From cbaa2b8400dc5f034338e34531a0ef4a5066d1d7 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 19 Jun 2011 14:12:12 +0530 Subject: [PATCH] updated code for updated sorl + fixed PNG support --- edgware/editor/models.py | 14 +++++++++++--- edgware/editor/views.py | 11 +++++++---- edgware/files/convert.py | 4 +++- edgware/templates/thumbnailTmp.txt | 10 ++++++++-- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/edgware/editor/models.py b/edgware/editor/models.py index d649c10..3717076 100644 --- a/edgware/editor/models.py +++ b/edgware/editor/models.py @@ -14,6 +14,7 @@ from django.contrib.auth.models import User, Group from tagging.fields import TagField from tagging.models import Tag from copy import deepcopy +from sorl.thumbnail import get_thumbnail def addPx(val): ''' @@ -719,17 +720,24 @@ class ImageBox(models.Model): else: return self.original_print() + def get_path(self, *args): if len(args) > 0: m = args[0] else: m = 1 - path = self.actual_unresized() + path = join(MEDIA_ROOT, self.actual_unresized()) + f = open(path) + size = str(self.width * m) + "x" + str(self.height * m) + im = get_thumbnail(f, size, crop='center', quality=99) + ''' context = { 'path': path, - 'size': (self.width * m, self.height * m,) + # 'size': (self.width * m, self.height * m,) + 'size': str(self.width * m) + "x" + str(self.height * m) } - return get_template("thumbnailTmp.txt").render(Context(context)) + ''' + return im.url diff --git a/edgware/editor/views.py b/edgware/editor/views.py index a97ab41..120c0d8 100644 --- a/edgware/editor/views.py +++ b/edgware/editor/views.py @@ -407,10 +407,13 @@ def category_json(request): aspect_ratio = orig_size[1] / (orig_size[0] + .0) height = TARGET_WIDTH * aspect_ratio output_size = (TARGET_WIDTH, int(height),) - context = {'path': filePath, 'size': (100,100,)} - context2 = {'path': filePath, 'size': output_size} - iconPath = get_template("thumbnailTmp.txt").render(Context(context)) - resizedPath = get_template("thumbnailTmp.txt").render(Context(context2)) + f = open(join(MEDIA_ROOT, filePath)) + iconSize = "100x100" + resizedSize = str(TARGET_WIDTH) + "x" + str(int(height)) +# context = {'path': filePath, 'size': (100,100,)} +# context2 = {'path': filePath, 'size': output_size} + iconPath = get_thumbnail(f, iconSize, crop="center", quality=99).url + resizedPath = get_thumbnail(f, resizedSize, quality=99).url except: iconPath = "/static/images/binimages/jpg.jpg" resizedPath = filePath diff --git a/edgware/files/convert.py b/edgware/files/convert.py index 8f8a481..38ddd2e 100644 --- a/edgware/files/convert.py +++ b/edgware/files/convert.py @@ -55,12 +55,14 @@ def convertFile(**kwargs): fname = str(f.file) ext = e.models.extFileName(fname) f.ext = ext - if f.ext in ['jpg', 'JPG']: + if f.ext in ['jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG']: f.type = 'image' elif f.ext in ['ogg', 'oga']: f.type = 'audio' elif f.ext in ['ogv']: f.type = 'video' + elif f.ext in ['doc', 'pdf', 'rtf', 'txt']: + f.type = 'text' else: f.type = 'other' f.save() diff --git a/edgware/templates/thumbnailTmp.txt b/edgware/templates/thumbnailTmp.txt index c1cffaa..2956c1b 100644 --- a/edgware/templates/thumbnailTmp.txt +++ b/edgware/templates/thumbnailTmp.txt @@ -1,3 +1,9 @@ -{% load thumbnail %} -{% thumbnail path size crop %} +{% load thumbnail %} +{% thumbnail path size crop="center" as im %} + {{ im.url }} + {% empty %} + no image +{% endthumbnail %} + +path:{{ path }} size:{{ size }}