implement image thumbnails for upload and in list: site may behave slow for sometime.
This commit is contained in:
parent
768a6eb5f2
commit
48159d3428
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ function getListElement(f) {
|
|||
// console.log(f);
|
||||
var $item = $('<div />').addClass("fileItem").data("data", f);
|
||||
var $checkbox = $('<input />').attr("type", "checkbox").addClass("fileCheckbox").appendTo($item);
|
||||
var $icon = $('<img />').addClass("fileIcon").attr("src", "/static/images/icons2/" + f.type.toLowerCase() + ".jpg").appendTo($item);
|
||||
var $icon = $('<img />').addClass("fileIcon").attr("src", f.thumb).appendTo($item);
|
||||
var study_txt = joinStudies(f.studies);
|
||||
var $study = $('<span />').addClass("fileStudy").text(study_txt + ": ").appendTo($item);
|
||||
var $title = $('<span />').addClass("fileTitle").text(f.title).appendTo($item);
|
||||
|
|
|
@ -118,6 +118,9 @@ function fileUploadedCallback(jq, data) {
|
|||
// console.log($titleInput);
|
||||
$titleInput.appendTo($formContainer);
|
||||
var $descInput = $('<textarea />').attr("placeholder", "Add Description").addClass("fileDesc").appendTo($formContainer);
|
||||
if (d.type == 'image') {
|
||||
var $thumbnail = $('<img />').addClass("thumbnail").attr("src", d.thumbnail).appendTo($formContainer);
|
||||
}
|
||||
var $submitBtn = $('<button />').text("Submit").click(function() {
|
||||
var $this = $(this);
|
||||
$this.attr("disabled", "disabled");
|
||||
|
|
Loading…
Reference in New Issue
Block a user