Skip to content

Commit

Permalink
- Generating documents thumbnails for video and audio mime types
Browse files Browse the repository at this point in the history
(cherry picked from commit d1f4251)
  • Loading branch information
afabiani committed Nov 5, 2020
1 parent bd28e30 commit 5c89762
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
22 changes: 11 additions & 11 deletions geonode/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@ def name_long(self):

def find_placeholder(self):
placeholder = 'documents/{0}-placeholder.png'
return finders.find(placeholder.format(self.extension), False) or \
finders.find(placeholder.format('generic'), False)
if finders.find(placeholder.format(self.extension), False):
return finders.find(placeholder.format(self.extension), False)
elif self.is_audio:
return finders.find(placeholder.format('audio'), False)
elif self.is_image:
return finders.find(placeholder.format('image'), False)
elif self.is_video:
return finders.find(placeholder.format('video'), False)
return finders.find(placeholder.format('generic'), False)

@property
def is_file(self):
Expand Down Expand Up @@ -207,6 +214,7 @@ def pre_save_document(instance, sender, **kwargs):


def post_save_document(instance, *args, **kwargs):
from .tasks import create_document_thumbnail

name = None
ext = instance.extension
Expand All @@ -221,6 +229,7 @@ def post_save_document(instance, *args, **kwargs):
url = '%s%s' % (
site_url,
reverse('document_download', args=(instance.id,)))
create_document_thumbnail.apply_async((instance.id,))
elif instance.doc_url:
name = "External Document"
url = instance.doc_url
Expand All @@ -237,14 +246,6 @@ def post_save_document(instance, *args, **kwargs):
link_type='data',))


def create_thumbnail(sender, instance, created, **kwargs):
from .tasks import create_document_thumbnail

result = create_document_thumbnail.delay(object_id=instance.id)
# Attempt to run task synchronously
result.get()


def update_documents_extent(sender, **kwargs):
documents = get_related_documents(sender)
if documents:
Expand All @@ -257,7 +258,6 @@ def pre_delete_document(instance, sender, **kwargs):


signals.pre_save.connect(pre_save_document, sender=Document)
signals.post_save.connect(create_thumbnail, sender=Document)
signals.post_save.connect(post_save_document, sender=Document)
signals.post_save.connect(resourcebase_post_save, sender=Document)
signals.pre_delete.connect(pre_delete_document, sender=Document)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions geonode/documents/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def create_document_thumbnail(self, object_id):

if document.is_image:
image_file = storage.open(document.doc_file.name, 'rb')
elif document.is_video or document.is_audio:
image_file = open(document.find_placeholder(), 'rb')
elif document.is_file:
try:
document_location = storage.path(document.doc_file.name)
Expand Down

0 comments on commit 5c89762

Please sign in to comment.