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,
DocumentVersion)
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
@@ -316,7 +316,8 @@ class DocumentTypeFilenameForm_create(forms.ModelForm):
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.'))
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):
self.document_versions = kwargs.pop('document_versions', None)
super(DocumentDownloadForm, self).__init__(*args, **kwargs)

View File

@@ -22,3 +22,5 @@ RELEASE_LEVEL_CHOICES = (
VERSION_UPDATE_MAJOR = u'major'
VERSION_UPDATE_MINOR = u'minor'
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(
request,
compressed_file.as_file('document_bundle.zip'),
save_as=u'"document_bundle.zip"',
compressed_file.as_file(form.cleaned_data['zip_filename']),
save_as=u'"%s"' % form.cleaned_data['zip_filename'],
content_type='application/zip'
)
# 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'),
'previous': previous,
'cancel_label': _(u'Return'),
'disable_auto_focus': True,
}
if len(document_versions) == 1: