generate thumbnails for preview

This commit is contained in:
Sanj 2011-06-30 00:38:11 +05:30
parent 12fde8b36d
commit f63ee3b99c
3 changed files with 10 additions and 1 deletions

View File

@ -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

View File

@ -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())

View File

@ -44,7 +44,7 @@ function getJQ(f) {
var d = $this.data("data");
switch (d.type) {
case "image":
var html = "<img width='400' src='" + d.url + "' />";
var html = "<img width='400' src='" + d.thumbnail + "' />";
break;
default:
var html = "<a href='" + d.url + "' target='_blank'>Click to view</a>";