Added staging file previews support
This commit is contained in:
@@ -12,10 +12,14 @@ document_view = {'text':_('details'), 'view':'document_view', 'args':'object.id'
|
||||
document_delete = {'text':_('delete'), 'view':'document_delete', 'args':'object.id', 'famfam':'page_delete'}
|
||||
document_edit = {'text':_('edit'), 'view':'document_edit', 'args':'object.id', 'famfam':'page_edit'}
|
||||
|
||||
staging_file_preview = {'class':'fancybox', 'text':_('preview'), 'view':'staging_file_preview', 'args':'object.id', 'famfam':'drive_magnify'}
|
||||
|
||||
register_links(Document, [document_view, document_edit, document_delete])
|
||||
register_links(Document, [document_list, document_create, document_create_multiple], menu_name='sidebar')
|
||||
register_links(['document_list', 'document_create', 'document_create_multiple', 'upload_document_with_type', 'upload_multiple_documents_with_type'], [document_list, document_create, document_create_multiple], menu_name='sidebar')
|
||||
|
||||
register_links(StagingFile, [staging_file_preview])
|
||||
|
||||
|
||||
register_menu([
|
||||
{'text':_('documents'), 'view':'document_list', 'links':[
|
||||
|
||||
@@ -22,6 +22,8 @@ AVAILABLE_MODELS = getattr(settings, 'DOCUMENTS_METADATA_AVAILABLE_MODELS', defa
|
||||
USE_STAGING_DIRECTORY = getattr(settings, 'DOCUMENTS_USE_STAGING_DIRECTORY', False)
|
||||
STAGING_DIRECTORY = getattr(settings, 'DOCUMENTS_STAGING_DIRECTORY', u'/tmp/mayan/staging')
|
||||
DELETE_STAGING_FILE_AFTER_UPLOAD = getattr(settings, 'DOCUMENTS_DELETE_STAGING_FILE_AFTER_UPLOAD', False)
|
||||
STAGING_FILES_PREVIEW_SIZE = getattr(settings, 'DOCUMENTS_STAGING_FILES_PREVIEW_SIZE', '640x480')
|
||||
|
||||
DELETE_LOCAL_ORIGINAL = getattr(settings, 'DOCUMENTS_DELETE_LOCAL_ORIGINAL', False)
|
||||
# Saving
|
||||
CHECKSUM_FUNCTION = getattr(settings, 'DOCUMENTS_CHECKSUM_FUNCTION', lambda x: hashlib.sha256(x).hexdigest())
|
||||
@@ -34,3 +36,5 @@ FILESYSTEM_FILESERVING_ENABLE = getattr(settings, 'DOCUMENTS_FILESYSTEM_FILESERV
|
||||
FILESYSTEM_FILESERVING_PATH = getattr(settings, 'DOCUMENTS_FILESERVING_PATH', u'/tmp/mayan/documents')
|
||||
FILESYSTEM_SLUGIFY_PATHS = getattr(settings, 'DOCUMENTS_SLUGIFY_PATHS', False)
|
||||
FILESYSTEM_MAX_RENAME_COUNT = getattr(settings, 'DOCUMENTS_FILESYSTEM_MAX_RENAME_COUNT', 200)
|
||||
#misc
|
||||
TEMPORARY_DIRECTORY = getattr(settings, 'DOCUMENTS_TEMPORARY_DIRECTORY', u'/tmp')
|
||||
|
||||
29
apps/documents/convert.py
Normal file
29
apps/documents/convert.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
#from django.core.files.base import File
|
||||
from documents.conf.settings import TEMPORARY_DIRECTORY
|
||||
|
||||
def convert(input_filepath, size, cache=True, page=0, format='jpg'):
|
||||
temp_directory = TEMPORARY_DIRECTORY if TEMPORARY_DIRECTORY else tempfile.mkdtemp()
|
||||
#TODO: generate output file using lightweight hash function on
|
||||
#file name or file content
|
||||
#descriptor, temp_filepath = tempfile.mkstemp()
|
||||
|
||||
temp_filename, separator = os.path.splitext(os.path.basename(input_filepath))
|
||||
temp_path = os.path.join(temp_directory, temp_filename)
|
||||
output_arg = '%s_%s%s%s' % (temp_path, size, os.extsep, format)
|
||||
input_arg = '%s[%s]' % (input_filepath, page)
|
||||
if os.path.exists(output_arg):
|
||||
return output_arg
|
||||
|
||||
#TODO: Check mimetype and use corresponding utility
|
||||
convert = subprocess.Popen(['convert', input_arg, '-resize', size, output_arg])
|
||||
return_code = convert.wait()
|
||||
if return_code:
|
||||
raise Exception
|
||||
#TODO: check return code & messages
|
||||
#TODO: Timeout & kill child
|
||||
return output_arg
|
||||
15
apps/documents/templates/fancybox.html
Normal file
15
apps/documents/templates/fancybox.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<link rel="stylesheet" href="{{ MEDIA_URL }}packages/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
|
||||
<script type="text/javascript" src="{{ MEDIA_URL }}packages/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
|
||||
<script type="text/javascript" src="{{ MEDIA_URL }}packages/jquery.fancybox-1.3.4/fancybox/jquery.easing-1.3.pack.js"></script>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function() {
|
||||
$("a.fancybox").fancybox({
|
||||
'titleShow' : false,
|
||||
'transitionIn' : 'elastic',
|
||||
'transitionOut' : 'elastic',
|
||||
'easingIn' : 'easeOutBack',
|
||||
'easingOut' : 'easeInBack',
|
||||
'type' : 'image'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -12,4 +12,8 @@ urlpatterns = patterns('documents.views',
|
||||
url(r'^document/(?P<document_id>\d+)/$', 'document_view', (), 'document_view'),
|
||||
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'^staging_file/(?P<staging_file_id>\w+)/preview/$', 'staging_file_preview', (), 'staging_file_preview'),
|
||||
|
||||
|
||||
)
|
||||
|
||||
@@ -10,6 +10,11 @@ from django.views.generic.list_detail import object_detail, object_list
|
||||
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 filetransfers.api import serve_file
|
||||
|
||||
from convert import convert
|
||||
|
||||
from models import Document, DocumentMetadata, DocumentType, MetadataType
|
||||
from forms import DocumentTypeSelectForm, DocumentCreateWizard, \
|
||||
@@ -21,7 +26,7 @@ from staging import StagingFile
|
||||
from documents.conf.settings import DELETE_STAGING_FILE_AFTER_UPLOAD
|
||||
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
|
||||
|
||||
def document_list(request):
|
||||
return object_list(
|
||||
@@ -158,10 +163,13 @@ def upload_document_with_type(request, document_type_id, multiple=True):
|
||||
context.update({
|
||||
'subtemplates_dict':[
|
||||
{
|
||||
'name':'generic_list_subtemplate.html',
|
||||
'title':_(u'files in staging'),
|
||||
'object_list':filelist,
|
||||
'hide_link':True,
|
||||
'name':'fancybox.html',
|
||||
},
|
||||
{
|
||||
'name':'generic_list_subtemplate.html',
|
||||
'title':_(u'files in staging'),
|
||||
'object_list':filelist,
|
||||
'hide_link':True,
|
||||
},
|
||||
],
|
||||
})
|
||||
@@ -264,3 +272,13 @@ def document_edit(request, document_id):
|
||||
'object':document,
|
||||
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def staging_file_preview(request, staging_file_id):
|
||||
try:
|
||||
filepath = StagingFile.get(staging_file_id).filepath
|
||||
output_file = convert(filepath, STAGING_FILES_PREVIEW_SIZE)
|
||||
return serve_file(request, File(file=open(output_file, 'r')))
|
||||
except Exception, e:
|
||||
#messages.error(request, e)
|
||||
return HttpResponse('')
|
||||
|
||||
Reference in New Issue
Block a user