Skip to content

Commit

Permalink
Move preview check onto storages
Browse files Browse the repository at this point in the history
  • Loading branch information
gthole committed Jan 22, 2018
1 parent 4f6d7a3 commit 5a655b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
18 changes: 18 additions & 0 deletions gedgo/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ def preview(self, name, size='w128h128'):
)[1].content)
return resize_thumb(file_, size)

def can_preview(self, name):
return (
'.' in name and
name.rsplit('.', 1)[1].lower() in (
'jpeg', 'jpg', 'gif', 'png', 'pdf', 'tif', 'tiff',
'mov', 'avi', 'doc', 'mpg', 'bmp', 'psd'
)
)



class FileSystemSearchableStorage(FileSystemStorage):
def search(self, query):
Expand All @@ -86,6 +96,14 @@ def search(self, query):
def preview(self, name, size='w128h128'):
return resize_thumb(self.open(name), size)

def can_preview(self, name):
return (
'.' in name and
name.rsplit('.', 1)[1].lower() in (
'jpeg', 'jpg'
)
)


def resize_thumb(file_, size='w128h128', crop=None):
im = Image.open(file_)
Expand Down
10 changes: 1 addition & 9 deletions gedgo/views/research.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,8 @@ def can_preview(storage, name):
"""
Check if the file in question can generate a preview
"""
# TODO: Move suffix check onto storage child classes, since filesystem
# won't support previewing lots of these other types
return (
hasattr(storage, 'preview') and
is_ascii(name) and
(
'.' in name and
name.rsplit('.', 1)[1].lower() in (
'jpeg', 'jpg', 'gif', 'png', 'pdf',
'mov', 'avi', 'doc', 'mpg', 'bmp'
)
)
storage.can_preview(name)
)

0 comments on commit 5a655b7

Please sign in to comment.