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)
|
qobjects.append(qobject)
|
||||||
return qset.filter(reduce(operator.or_, qobjects))
|
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):
|
def get_dict(self):
|
||||||
#FIXME
|
#FIXME
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django.shortcuts import render_to_response
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django import forms
|
from django import forms
|
||||||
from models import Category, File
|
from models import Category, File, extFileName
|
||||||
from settings import FTP_ROOT, UPLOAD_ROOT
|
from settings import FTP_ROOT, UPLOAD_ROOT
|
||||||
import os
|
import os
|
||||||
from os.path import join, isdir, getmtime, basename
|
from os.path import join, isdir, getmtime, basename
|
||||||
|
@ -179,6 +179,7 @@ class ChunkForm(forms.Form):
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def chunk(request, id):
|
def chunk(request, id):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
response = {}
|
||||||
item = get_object_or_404(File, id=id)
|
item = get_object_or_404(File, id=id)
|
||||||
form = ChunkForm(request.POST, request.FILES)
|
form = ChunkForm(request.POST, request.FILES)
|
||||||
canEdit = True
|
canEdit = True
|
||||||
|
@ -188,16 +189,21 @@ def chunk(request, id):
|
||||||
name = item.title
|
name = item.title
|
||||||
else:
|
else:
|
||||||
name = f.name
|
name = f.name
|
||||||
response = {
|
# if extFileName(name).lower() in ['jpg', 'jpeg', 'png']:
|
||||||
'resultUrl': '/files/' + str(item.id),
|
# thumbnail = get_thumbnail(
|
||||||
'fileId': item.id,
|
|
||||||
'title': name
|
|
||||||
}
|
|
||||||
if not item.save_chunk(f.read(), name):
|
if not item.save_chunk(f.read(), name):
|
||||||
response['result'] = 'failed'
|
response['result'] = 'failed'
|
||||||
elif form.cleaned_data['done']:
|
elif form.cleaned_data['done']:
|
||||||
item.done = True
|
item.done = True
|
||||||
item.save()
|
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['done'] = 1
|
||||||
response['result'] = 1
|
response['result'] = 1
|
||||||
else:
|
else:
|
||||||
|
@ -369,6 +375,10 @@ def fileList(request):
|
||||||
for f in files:
|
for f in files:
|
||||||
fileData = f.get_dict()
|
fileData = f.get_dict()
|
||||||
fileData['can_edit'] = f.can_edit(user)
|
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)
|
d['files'].append(fileData)
|
||||||
return render_to_json_response(d)
|
return render_to_json_response(d)
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@ function getListElement(f) {
|
||||||
// console.log(f);
|
// console.log(f);
|
||||||
var $item = $('<div />').addClass("fileItem").data("data", f);
|
var $item = $('<div />').addClass("fileItem").data("data", f);
|
||||||
var $checkbox = $('<input />').attr("type", "checkbox").addClass("fileCheckbox").appendTo($item);
|
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_txt = joinStudies(f.studies);
|
||||||
var $study = $('<span />').addClass("fileStudy").text(study_txt + ": ").appendTo($item);
|
var $study = $('<span />').addClass("fileStudy").text(study_txt + ": ").appendTo($item);
|
||||||
var $title = $('<span />').addClass("fileTitle").text(f.title).appendTo($item);
|
var $title = $('<span />').addClass("fileTitle").text(f.title).appendTo($item);
|
||||||
|
|
|
@ -118,6 +118,9 @@ function fileUploadedCallback(jq, data) {
|
||||||
// console.log($titleInput);
|
// console.log($titleInput);
|
||||||
$titleInput.appendTo($formContainer);
|
$titleInput.appendTo($formContainer);
|
||||||
var $descInput = $('<textarea />').attr("placeholder", "Add Description").addClass("fileDesc").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 $submitBtn = $('<button />').text("Submit").click(function() {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
$this.attr("disabled", "disabled");
|
$this.attr("disabled", "disabled");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user