Added means to expand or not a compressed file during document creation, removed configuration options UNCOMPRESS_COMPRESSED_LOCAL_FILES and UNCOMPRESS_COMPRESSED_STAGING_FILES
This commit is contained in:
@@ -34,8 +34,6 @@ register_settings(
|
||||
{'name': u'USER_STAGING_DIRECTORY_EXPRESSION', 'global_name': u'DOCUMENTS_USER_STAGING_DIRECTORY_EXPRESSION', 'default': u'user.username'},
|
||||
{'name': u'DELETE_STAGING_FILE_AFTER_UPLOAD', 'global_name': u'DOCUMENTS_DELETE_STAGING_FILE_AFTER_UPLOAD', 'default': False},
|
||||
{'name': u'STAGING_FILES_PREVIEW_SIZE', 'global_name': u'DOCUMENTS_STAGING_FILES_PREVIEW_SIZE', 'default': u'640x480'},
|
||||
{'name': u'UNCOMPRESS_COMPRESSED_LOCAL_FILES', 'global_name': u'DOCUMENTS_UNCOMPRESS_COMPRESSED_LOCAL_FILES', 'default': True},
|
||||
{'name': u'UNCOMPRESS_COMPRESSED_STAGING_FILES', 'global_name': u'DOCUMENTS_UNCOMPRESS_COMPRESSED_STAGING_FILES', 'default': True},
|
||||
# Saving
|
||||
{'name': u'CHECKSUM_FUNCTION', 'global_name': u'DOCUMENTS_CHECKSUM_FUNCTION', 'default': default_checksum},
|
||||
{'name': u'UUID_FUNCTION', 'global_name': u'DOCUMENTS_UUID_FUNCTION', 'default': default_uuid},
|
||||
|
||||
@@ -186,10 +186,20 @@ class DocumentForm(forms.ModelForm):
|
||||
queryset=filenames_qs,
|
||||
required=False,
|
||||
label=_(u'Quick document rename'))
|
||||
|
||||
# Put the expand field last in the field order list
|
||||
expand_field_index = self.fields.keyOrder.index('expand')
|
||||
expand_field = self.fields.keyOrder.pop(expand_field_index)
|
||||
self.fields.keyOrder.append(expand_field)
|
||||
|
||||
new_filename = forms.CharField(
|
||||
label=_('New document filename'), required=False
|
||||
)
|
||||
|
||||
expand = forms.BooleanField(
|
||||
label=_(u'Expand compressed files'), required=False,
|
||||
help_text=ugettext(u'Upload a compressed file\'s contained files as individual documents')
|
||||
)
|
||||
|
||||
|
||||
class DocumentForm_edit(DocumentForm):
|
||||
@@ -198,8 +208,13 @@ class DocumentForm_edit(DocumentForm):
|
||||
"""
|
||||
class Meta:
|
||||
model = Document
|
||||
exclude = ('file', 'document_type', 'tags')
|
||||
exclude = ('file', 'document_type', 'tags', 'expand')
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DocumentForm_edit, self).__init__(*args, **kwargs)
|
||||
self.fields.pop('expand')
|
||||
|
||||
|
||||
class DocumentPropertiesForm(DetailForm):
|
||||
"""
|
||||
@@ -267,7 +282,8 @@ class StagingDocumentForm(DocumentForm):
|
||||
pass
|
||||
|
||||
# Put staging_list field first in the field order list
|
||||
staging_list = self.fields.keyOrder.pop(1)
|
||||
staging_list_index = self.fields.keyOrder.index('staging_file_id')
|
||||
staging_list = self.fields.keyOrder.pop(staging_list_index)
|
||||
self.fields.keyOrder.insert(0, staging_list)
|
||||
|
||||
staging_file_id = forms.ChoiceField(label=_(u'Staging file'))
|
||||
|
||||
@@ -45,8 +45,6 @@ from documents.conf.settings import PER_USER_STAGING_DIRECTORY
|
||||
|
||||
from documents.conf.settings import PREVIEW_SIZE
|
||||
from documents.conf.settings import THUMBNAIL_SIZE
|
||||
from documents.conf.settings import UNCOMPRESS_COMPRESSED_LOCAL_FILES
|
||||
from documents.conf.settings import UNCOMPRESS_COMPRESSED_STAGING_FILES
|
||||
from documents.conf.settings import STORAGE_BACKEND
|
||||
from documents.conf.settings import ZOOM_PERCENT_STEP
|
||||
from documents.conf.settings import ZOOM_MAX_LEVEL
|
||||
@@ -182,7 +180,8 @@ def upload_document_with_type(request, source):
|
||||
form = DocumentForm(request.POST, request.FILES, document_type=document_type)
|
||||
if form.is_valid():
|
||||
try:
|
||||
if (not UNCOMPRESS_COMPRESSED_LOCAL_FILES) or (UNCOMPRESS_COMPRESSED_LOCAL_FILES and not _handle_zip_file(request, request.FILES['file'], document_type)):
|
||||
expand = form.cleaned_data['expand']
|
||||
if (not expand) or (expand and not _handle_zip_file(request, request.FILES['file'], document_type)):
|
||||
instance = form.save()
|
||||
instance.save()
|
||||
if document_type:
|
||||
@@ -201,7 +200,8 @@ def upload_document_with_type(request, source):
|
||||
if form.is_valid():
|
||||
try:
|
||||
staging_file = StagingFile.get(form.cleaned_data['staging_file_id'])
|
||||
if (not UNCOMPRESS_COMPRESSED_STAGING_FILES) or (UNCOMPRESS_COMPRESSED_STAGING_FILES and not _handle_zip_file(request, staging_file.upload(), document_type)):
|
||||
expand = form.cleaned_data['expand']
|
||||
if (not expand) or (expand and not _handle_zip_file(request, staging_file.upload(), document_type)):
|
||||
document = Document(file=staging_file.upload())
|
||||
if document_type:
|
||||
document.document_type = document_type
|
||||
|
||||
Reference in New Issue
Block a user