Add support to specifying the compressed documents download filename

This commit is contained in:
Roberto Rosario
2012-06-28 16:13:26 -04:00
parent 03f799e527
commit 4e93da6e80
3 changed files with 8 additions and 4 deletions

View File

@@ -15,7 +15,7 @@ from .models import (Document, DocumentType,
DocumentPage, DocumentPageTransformation, DocumentTypeFilename, DocumentPage, DocumentPageTransformation, DocumentTypeFilename,
DocumentVersion) DocumentVersion)
from .widgets import document_html_widget from .widgets import document_html_widget
from .literals import (RELEASE_LEVEL_FINAL, RELEASE_LEVEL_CHOICES) from .literals import (RELEASE_LEVEL_FINAL, RELEASE_LEVEL_CHOICES, DEFAULT_ZIP_FILENAME)
# Document page forms # Document page forms
@@ -316,6 +316,7 @@ class DocumentTypeFilenameForm_create(forms.ModelForm):
class DocumentDownloadForm(forms.Form): class DocumentDownloadForm(forms.Form):
compressed = forms.BooleanField(label=_(u'Compress'), required=False, help_text=_(u'Download the document in the original format or in a compressed manner. This option is selectable only when downloading one document, for multiple documents, the bundle will always be downloads as a compressed file.')) compressed = forms.BooleanField(label=_(u'Compress'), required=False, help_text=_(u'Download the document in the original format or in a compressed manner. This option is selectable only when downloading one document, for multiple documents, the bundle will always be downloads as a compressed file.'))
zip_filename = forms.CharField(initial=DEFAULT_ZIP_FILENAME, label=_(u'Compressed filename'), required=False, help_text=_(u'The filename of the compressed file that will contain the documents to be downloaded, if the previous option is selected.'))
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.document_versions = kwargs.pop('document_versions', None) self.document_versions = kwargs.pop('document_versions', None)

View File

@@ -22,3 +22,5 @@ RELEASE_LEVEL_CHOICES = (
VERSION_UPDATE_MAJOR = u'major' VERSION_UPDATE_MAJOR = u'major'
VERSION_UPDATE_MINOR = u'minor' VERSION_UPDATE_MINOR = u'minor'
VERSION_UPDATE_MICRO = u'micro' VERSION_UPDATE_MICRO = u'micro'
DEFAULT_ZIP_FILENAME = u'document_bundle.zip'

View File

@@ -370,8 +370,8 @@ def document_download(request, document_id=None, document_id_list=None, document
return serve_file( return serve_file(
request, request,
compressed_file.as_file('document_bundle.zip'), compressed_file.as_file(form.cleaned_data['zip_filename']),
save_as=u'"document_bundle.zip"', save_as=u'"%s"' % form.cleaned_data['zip_filename'],
content_type='application/zip' content_type='application/zip'
) )
# TODO: DO a redirection afterwards # TODO: DO a redirection afterwards
@@ -409,6 +409,7 @@ def document_download(request, document_id=None, document_id_list=None, document
'submit_label': _(u'Download'), 'submit_label': _(u'Download'),
'previous': previous, 'previous': previous,
'cancel_label': _(u'Return'), 'cancel_label': _(u'Return'),
'disable_auto_focus': True,
} }
if len(document_versions) == 1: if len(document_versions) == 1: