From 48159d34286173a5eab493801ecce1015515f0d4 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 6 Jul 2011 03:34:07 +0530 Subject: [PATCH] implement image thumbnails for upload and in list: site may behave slow for sometime. --- edgware/files/models.py | 6 ++++++ edgware/files/views.py | 22 ++++++++++++++++------ edgware/static/js/files/browse.js | 2 +- edgware/static/js/upload/edgeUpload.js | 3 +++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/edgware/files/models.py b/edgware/files/models.py index e560186..5acf031 100755 --- a/edgware/files/models.py +++ b/edgware/files/models.py @@ -126,6 +126,12 @@ class File(models.Model): qobjects.append(qobject) return qset.filter(reduce(operator.or_, qobjects)) + def get_thumb(self, size): + if self.ext.lower() in ['jpg', 'jpeg', 'png']: + return get_thumbnail(open(self.file.path), size, crop="center", quality=60).url + else: + return self.ext + def get_dict(self): #FIXME try: diff --git a/edgware/files/views.py b/edgware/files/views.py index 744c13a..e00f6f7 100644 --- a/edgware/files/views.py +++ b/edgware/files/views.py @@ -3,7 +3,7 @@ from django.shortcuts import render_to_response from django.http import HttpResponseRedirect from django.contrib.auth.decorators import login_required from django import forms -from models import Category, File +from models import Category, File, extFileName from settings import FTP_ROOT, UPLOAD_ROOT import os from os.path import join, isdir, getmtime, basename @@ -179,6 +179,7 @@ class ChunkForm(forms.Form): @csrf_exempt def chunk(request, id): if request.method == 'POST': + response = {} item = get_object_or_404(File, id=id) form = ChunkForm(request.POST, request.FILES) canEdit = True @@ -188,16 +189,21 @@ def chunk(request, id): name = item.title else: name = f.name - response = { - 'resultUrl': '/files/' + str(item.id), - 'fileId': item.id, - 'title': name - } +# if extFileName(name).lower() in ['jpg', 'jpeg', 'png']: +# thumbnail = get_thumbnail( if not item.save_chunk(f.read(), name): response['result'] = 'failed' elif form.cleaned_data['done']: item.done = True item.save() + response = { + 'resultUrl': '/files/' + str(item.id), + 'fileId': item.id, + 'title': name, + 'type': item.type, + 'thumbnail': item.get_thumb("100x100") + } + response['done'] = 1 response['result'] = 1 else: @@ -369,6 +375,10 @@ def fileList(request): for f in files: fileData = f.get_dict() fileData['can_edit'] = f.can_edit(user) + if f.type == 'image': + fileData['thumb'] = f.get_thumb("10x10") + else: + fileData['thumb'] = "/static/images/icons2/" + f.type + ".jpg" d['files'].append(fileData) return render_to_json_response(d) diff --git a/edgware/static/js/files/browse.js b/edgware/static/js/files/browse.js index 9f50de3..8b9e77b 100644 --- a/edgware/static/js/files/browse.js +++ b/edgware/static/js/files/browse.js @@ -233,7 +233,7 @@ function getListElement(f) { // console.log(f); var $item = $('
').addClass("fileItem").data("data", f); var $checkbox = $('').attr("type", "checkbox").addClass("fileCheckbox").appendTo($item); - var $icon = $('').addClass("fileIcon").attr("src", "/static/images/icons2/" + f.type.toLowerCase() + ".jpg").appendTo($item); + var $icon = $('').addClass("fileIcon").attr("src", f.thumb).appendTo($item); var study_txt = joinStudies(f.studies); var $study = $('').addClass("fileStudy").text(study_txt + ": ").appendTo($item); var $title = $('').addClass("fileTitle").text(f.title).appendTo($item); diff --git a/edgware/static/js/upload/edgeUpload.js b/edgware/static/js/upload/edgeUpload.js index 13dcdd0..360d96f 100644 --- a/edgware/static/js/upload/edgeUpload.js +++ b/edgware/static/js/upload/edgeUpload.js @@ -118,6 +118,9 @@ function fileUploadedCallback(jq, data) { // console.log($titleInput); $titleInput.appendTo($formContainer); var $descInput = $('