From f63ee3b99cdfa3defdc474ce08a298d794ada62e Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 30 Jun 2011 00:38:11 +0530 Subject: [PATCH] generate thumbnails for preview --- edgware/files/models.py | 7 +++++++ edgware/files/views.py | 2 ++ edgware/static/js/files/browse.js | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/edgware/files/models.py b/edgware/files/models.py index a970b75..85c44b7 100755 --- a/edgware/files/models.py +++ b/edgware/files/models.py @@ -13,6 +13,7 @@ from django.core.files.base import ContentFile import operator from django.db.models import Q from ox.text import smartSplit +from sorl.thumbnail import get_thumbnail #FIXME: The following two functions are ridiculous. please remove and clean up all references to them. def baseFileName(filename): @@ -124,11 +125,17 @@ class File(models.Model): #FIXME try: url = self.file.url + if self.type.lower() == 'image': + thumbnail = get_thumbnail(open(self.file.path), "300x", quality=60).url + else: + thumbnail = '' except: url = '' + thumbnail = '' return { 'id': self.id, 'url': url, + 'thumbnail': thumbnail, 'title': self.title, 'description': self.description, 'type': self.type diff --git a/edgware/files/views.py b/edgware/files/views.py index c1adc94..55bceb4 100644 --- a/edgware/files/views.py +++ b/edgware/files/views.py @@ -252,6 +252,8 @@ def fileList(request): results = paginator.page(paginator.num_pages) files = results.object_list d = {} + d['noOfResults'] = qset.count() + d['noOfPages'] = 2 d['files'] = [] for f in files: d['files'].append(f.get_dict()) diff --git a/edgware/static/js/files/browse.js b/edgware/static/js/files/browse.js index d52e408..e54f0a7 100644 --- a/edgware/static/js/files/browse.js +++ b/edgware/static/js/files/browse.js @@ -44,7 +44,7 @@ function getJQ(f) { var d = $this.data("data"); switch (d.type) { case "image": - var html = ""; + var html = ""; break; default: var html = "Click to view";