Commit eb7d6c65 by Chris Dodge

use better encapsulation for the naming convention behind thumbnails. Put it all…

use better encapsulation for the naming convention behind thumbnails. Put it all in content.py rather than view.py.
parent 84bc81f7
......@@ -500,8 +500,8 @@ def upload_asset(request, org, course, coursename):
thumbnail_file.seek(0)
# use a naming convention to associate originals with the thumbnail
# <name_without_extention>.thumbnail.jpg
thumbnail_name = os.path.splitext(name)[0] + '.thumbnail.jpg'
thumbnail_name = content.generate_thumbnail_name()
# then just store this thumbnail as any other piece of content
thumbnail_file_location = StaticContent.compute_location(org, course,
thumbnail_name)
......@@ -515,6 +515,7 @@ def upload_asset(request, org, course, coursename):
except:
# catch, log, and continue as thumbnails are not a hard requirement
logging.error('Failed to generate thumbnail for {0}. Continuing...'.format(name))
raise
return HttpResponse('Upload completed')
......
XASSET_LOCATION_TAG = 'c4x'
XASSET_SRCREF_PREFIX = 'xasset:'
XASSET_THUMBNAIL_TAIL_NAME = '.thumbnail.jpg'
import os
import logging
from xmodule.modulestore import Location
......@@ -12,6 +15,12 @@ class StaticContent(object):
self.data = data
self.last_modified_at = last_modified_at
@property
def is_thumbnail(self):
return self.name.endswith(XASSET_THUMBNAIL_TAIL_NAME)
def generate_thumbnail_name(self):
return ('{0}'+XASSET_THUMBNAIL_TAIL_NAME).format(os.path.splitext(self.name)[0])
@staticmethod
def compute_location(org, course, name, revision=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment