-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue #6414] File system operations do not adhere to Django file sto…
…rage API (#6425) * [Issue #6414] Use Django storage API in delete_orphaned_* functions * [Issue #6414] Use Django storage API in geonode.qgis_server.tests.test_views * [Issue #6414] Use Django storage API when generating document thumbnails * [Issue #6414] Thumbnail generation fix for local storage * Add thumbnail convenience functions * Cleanup Django storage API changes
- Loading branch information
Matthew Northcott
authored
Sep 23, 2020
1 parent
6b62716
commit 771e154
Showing
11 changed files
with
194 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
|
||
from django.conf import settings | ||
from django.core.files.storage import default_storage as storage | ||
|
||
|
||
def thumb_path(filename): | ||
"""Return the complete path of the provided thumbnail file accessible | ||
via Django storage API""" | ||
return os.path.join(settings.THUMBNAIL_LOCATION, filename) | ||
|
||
|
||
def thumb_exists(filename): | ||
"""Determine if a thumbnail file exists in storage""" | ||
return storage.exists(thumb_path(filename)) | ||
|
||
|
||
def get_thumbs(): | ||
"""Fetches a list of all stored thumbnails""" | ||
if not storage.exists(settings.THUMBNAIL_LOCATION): | ||
return [] | ||
|
||
subdirs, thumbs = storage.listdir(settings.THUMBNAIL_LOCATION) | ||
|
||
return thumbs | ||
|
||
|
||
def remove_thumb(filename): | ||
"""Delete a thumbnail from storage""" | ||
storage.delete(thumb_path(filename)) | ||
|
||
|
||
def remove_thumbs(name): | ||
"""Removes all stored thumbnails that start with the same name as the | ||
file specified""" | ||
for thumb in get_thumbs(): | ||
if thumb.startswith(name): | ||
remove_thumb(thumb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.