Added document thumbnail previews in document list view

This commit is contained in:
Roberto Rosario
2011-02-08 20:35:29 -04:00
parent 0c5b03b715
commit 52bee20025
7 changed files with 26 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ Requirements
* Django - A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
* django-pagination
* ImageMagick - Convert, Edit, Or Compose Bitmap Images
Or execute pip install -r requirements/production.txt to install the dependencies automatically.

View File

@@ -32,6 +32,7 @@ STORAGE_BACKEND = getattr(settings, 'DOCUMENTS_STORAGE_BACKEND', DocumentStorage
STORAGE_DIRECTORY_NAME = getattr(settings, 'DOCUMENTS_STORAGE_DIRECTORY_NAME', 'documents')
# Usage
PREVIEW_SIZE = getattr(settings, 'DOCUMENTS_PREVIEW_SIZE', '640x480')
THUMBNAIL_SIZE = getattr(settings, 'DOCUMENTS_THUMBNAIL_SIZE', '50x50')
# Serving
FILESYSTEM_FILESERVING_ENABLE = getattr(settings, 'DOCUMENTS_FILESYSTEM_FILESERVING_ENABLE', True)
FILESYSTEM_FILESERVING_PATH = getattr(settings, 'DOCUMENTS_FILESERVING_PATH', u'/tmp/mayan/documents')

View File

@@ -13,6 +13,7 @@ urlpatterns = patterns('documents.views',
url(r'^document/(?P<document_id>\d+)/delete/$', 'document_delete', (), 'document_delete'),
url(r'^document/(?P<document_id>\d+)/edit/$', 'document_edit', (), 'document_edit'),
url(r'^document/(?P<document_id>\d+)/preview/$', 'document_preview', (), 'document_preview'),
url(r'^document/(?P<document_id>\d+)/thumbnail/$', 'document_thumbnail', (), 'document_thumbnail'),
url(r'^document/(?P<document_id>\d+)/download/$', 'document_download', (), 'document_download'),
url(r'^staging_file/(?P<staging_file_id>\w+)/preview/$', 'staging_file_preview', (), 'staging_file_preview'),

View File

@@ -10,6 +10,8 @@ from django.core.urlresolvers import reverse
from django.views.generic.create_update import create_object, delete_object, update_object
from django.forms.formsets import formset_factory
from django.core.files.base import File
from django.conf import settings
from filetransfers.api import serve_file
from converter.api import convert, in_cache
@@ -29,6 +31,7 @@ from documents.conf.settings import USE_STAGING_DIRECTORY
from documents.conf.settings import FILESYSTEM_FILESERVING_ENABLE
from documents.conf.settings import STAGING_FILES_PREVIEW_SIZE
from documents.conf.settings import PREVIEW_SIZE
from documents.conf.settings import THUMBNAIL_SIZE
def document_list(request):
return object_list(
@@ -41,6 +44,8 @@ def document_list(request):
{'name':_(u'mimetype'), 'attribute':'file_mimetype'},
{'name':_(u'added'), 'attribute':lambda x: x.date_added.date()},
{'name':_(u'file size'), 'attribute':lambda x: pretty_size(x.file.storage.size(x.file.path)) if x.exists() else '-'},
{'name':_(u'thumbnail'), 'attribute':
lambda x: '<img src="%s" />' % reverse('document_thumbnail', args=[x.id])},
],
},
)
@@ -274,10 +279,10 @@ def document_edit(request, document_id):
}, context_instance=RequestContext(request))
def document_preview(request, document_id):
def get_document_image(request, document_id, size=PREVIEW_SIZE):
document = get_object_or_404(Document, pk=document_id)
filepath = in_cache(document.uuid, PREVIEW_SIZE)
filepath = in_cache(document.uuid, size)
if filepath:
return serve_file(request, File(file=open(filepath, 'r')))
@@ -286,12 +291,24 @@ def document_preview(request, document_id):
document.file.open()
desc = document.file.storage.open(document.file.path)
filepath = from_descriptor_to_tempfile(desc, document.uuid)
output_file = convert(filepath, PREVIEW_SIZE)
output_file = convert(filepath, size)
print document_id, output_file
return serve_file(request, File(file=open(output_file, 'r')))
except Exception, e:
if size == THUMBNAIL_SIZE:
return serve_file(request, File(file=open('%simages/picture_error.png' % settings.MEDIA_ROOT, 'r')))
else:
return serve_file(request, File(file=open('%simages/1297211435_error.png' % settings.MEDIA_ROOT, 'r')))
#messages.error(request, e)
return HttpResponse(e)
#return HttpResponse(e)
def document_thumbnail(request, document_id):
return get_document_image(request, document_id, THUMBNAIL_SIZE)
def document_preview(request, document_id):
return get_document_image(request, document_id, PREVIEW_SIZE)
def document_download(request, document_id):

View File

@@ -183,6 +183,7 @@ LOGIN_EXEMPT_URLS = (
#DOCUMENTS_STORAGE_DIRECTORY_NAME = 'documents'
# Usage
#DOCUMENTS_PREVIEW_SIZE = '640x480'
#DOCUMENTS_THUMBNAIL_SIZE = '50x50'
# Serving
#DOCUMENTS_FILESYSTEM_FILESERVING_ENABLE = True
#DOCUMENTS_FILESYSTEM_FILESERVING_PATH = u'/tmp/mayan/documents'

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB