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 import operator
from django.db.models import Q from django.db.models import Q
from ox.text import smartSplit 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. #FIXME: The following two functions are ridiculous. please remove and clean up all references to them.
def baseFileName(filename): def baseFileName(filename):
@ -124,11 +125,17 @@ class File(models.Model):
#FIXME #FIXME
try: try:
url = self.file.url url = self.file.url
if self.type.lower() == 'image':
thumbnail = get_thumbnail(open(self.file.path), "300x", quality=60).url
else:
thumbnail = ''
except: except:
url = '' url = ''
thumbnail = ''
return { return {
'id': self.id, 'id': self.id,
'url': url, 'url': url,
'thumbnail': thumbnail,
'title': self.title, 'title': self.title,
'description': self.description, 'description': self.description,
'type': self.type 'type': self.type

View File

@ -252,6 +252,8 @@ def fileList(request):
results = paginator.page(paginator.num_pages) results = paginator.page(paginator.num_pages)
files = results.object_list files = results.object_list
d = {} d = {}
d['noOfResults'] = qset.count()
d['noOfPages'] = 2
d['files'] = [] d['files'] = []
for f in files: for f in files:
d['files'].append(f.get_dict()) d['files'].append(f.get_dict())

View File

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