generate thumbnails for preview
This commit is contained in:
parent
12fde8b36d
commit
f63ee3b99c
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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>";
|
||||
|
|
Loading…
Reference in New Issue
Block a user