summaryrefslogtreecommitdiffstats
path: root/combo/apps/assets/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'combo/apps/assets/views.py')
-rw-r--r--combo/apps/assets/views.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/combo/apps/assets/views.py b/combo/apps/assets/views.py
index b261672..991a9e0 100644
--- a/combo/apps/assets/views.py
+++ b/combo/apps/assets/views.py
@@ -23,6 +23,7 @@ from django.core.exceptions import PermissionDenied
from django.core.files.storage import default_storage
from django.core.urlresolvers import reverse, reverse_lazy
from django.http import Http404, HttpResponse
+from django.shortcuts import get_object_or_404
from django.shortcuts import redirect
from django.utils.six import BytesIO
from django.utils.translation import ugettext_lazy as _
@@ -296,8 +297,25 @@ def assets_export(request, *args, **kwargs):
def serve_asset(request, key):
- try:
- asset = Asset.objects.get(key=key)
- return redirect(asset.asset.url)
- except (Asset.DoesNotExist, AttributeError):
+ asset = get_object_or_404(Asset, key=key)
+
+ if not os.path.exists(asset.asset.path):
raise Http404()
+
+ # get options for thumbnail
+ thumb_options = request.GET.dict()
+ width = thumb_options.pop('width', None)
+ height = thumb_options.pop('height', None)
+
+ geometry_string = ''
+ if width:
+ geometry_string += width
+ if height:
+ geometry_string += 'x%s' % height
+
+ # no thumbnail whithout geometry_string or for a svg file
+ if not geometry_string or asset.asset.name.endswith('svg'):
+ return redirect(asset.asset.url)
+
+ # get or create thumbnail and return url
+ return redirect(get_thumbnail(asset.asset, geometry_string, **thumb_options).url)