Update documents app to support multiple versions
This commit is contained in:
@@ -11,9 +11,11 @@ from common.conf.settings import DEFAULT_PAPER_SIZE
|
|||||||
from common.conf.settings import DEFAULT_PAGE_ORIENTATION
|
from common.conf.settings import DEFAULT_PAGE_ORIENTATION
|
||||||
from common.widgets import TextAreaDiv
|
from common.widgets import TextAreaDiv
|
||||||
|
|
||||||
from documents.models import Document, DocumentType, \
|
from documents.models import (Document, DocumentType,
|
||||||
DocumentPage, DocumentPageTransformation, DocumentTypeFilename
|
DocumentPage, DocumentPageTransformation, DocumentTypeFilename,
|
||||||
|
DocumentVersion)
|
||||||
from documents.widgets import document_html_widget
|
from documents.widgets import document_html_widget
|
||||||
|
from documents.literals import (RELEASE_LEVEL_FINAL, RELEASE_LEVEL_CHOICES)
|
||||||
|
|
||||||
# Document page forms
|
# Document page forms
|
||||||
class DocumentPageTransformationForm(forms.ModelForm):
|
class DocumentPageTransformationForm(forms.ModelForm):
|
||||||
@@ -147,6 +149,8 @@ class DocumentForm(forms.ModelForm):
|
|||||||
instance = kwargs.pop('instance', None)
|
instance = kwargs.pop('instance', None)
|
||||||
|
|
||||||
super(DocumentForm, self).__init__(*args, **kwargs)
|
super(DocumentForm, self).__init__(*args, **kwargs)
|
||||||
|
if instance:
|
||||||
|
self.version_fields(instance)
|
||||||
|
|
||||||
if 'document_type' in self.fields:
|
if 'document_type' in self.fields:
|
||||||
# To allow merging with DocumentForm_edit
|
# To allow merging with DocumentForm_edit
|
||||||
@@ -164,11 +168,51 @@ class DocumentForm(forms.ModelForm):
|
|||||||
queryset=filenames_qs,
|
queryset=filenames_qs,
|
||||||
required=False,
|
required=False,
|
||||||
label=_(u'Quick document rename'))
|
label=_(u'Quick document rename'))
|
||||||
|
|
||||||
|
def version_fields(self, document):
|
||||||
|
self.fields['comment'] = forms.CharField(
|
||||||
|
label=_(u'Comment'),
|
||||||
|
required=False,
|
||||||
|
widget=forms.widgets.Textarea(attrs={'rows': 4}),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.fields['version_update'] = forms.ChoiceField(
|
||||||
|
label=_(u'Version update'),
|
||||||
|
#widget=forms.widgets.RadioSelect(),
|
||||||
|
choices=DocumentVersion.get_version_update_choices(document.latest_version)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.fields['release_level'] = forms.ChoiceField(
|
||||||
|
label=_(u'Release level'),
|
||||||
|
choices=RELEASE_LEVEL_CHOICES,
|
||||||
|
initial=RELEASE_LEVEL_FINAL,
|
||||||
|
#required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.fields['serial'] = forms.IntegerField(
|
||||||
|
label=_(u'Release level serial'),
|
||||||
|
initial=0,
|
||||||
|
widget=forms.widgets.TextInput(
|
||||||
|
attrs = {'style': 'width: auto;'}
|
||||||
|
),
|
||||||
|
#required=False
|
||||||
|
)
|
||||||
|
|
||||||
new_filename = forms.CharField(
|
new_filename = forms.CharField(
|
||||||
label=_('New document filename'), required=False
|
label=_('New document filename'), required=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = self.cleaned_data
|
||||||
|
cleaned_data['new_version_data'] = {
|
||||||
|
'comment': self.cleaned_data.get('comment'),
|
||||||
|
'version_update': self.cleaned_data.get('version_update'),
|
||||||
|
'release_level': self.cleaned_data.get('release_level'),
|
||||||
|
'serial': self.cleaned_data.get('serial'),
|
||||||
|
}
|
||||||
|
|
||||||
|
# Always return the full collection of cleaned data.
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
class DocumentForm_edit(DocumentForm):
|
class DocumentForm_edit(DocumentForm):
|
||||||
"""
|
"""
|
||||||
@@ -177,6 +221,13 @@ class DocumentForm_edit(DocumentForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Document
|
model = Document
|
||||||
exclude = ('file', 'document_type', 'tags')
|
exclude = ('file', 'document_type', 'tags')
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(DocumentForm_edit, self).__init__(*args, **kwargs)
|
||||||
|
self.fields.pop('serial')
|
||||||
|
self.fields.pop('release_level')
|
||||||
|
self.fields.pop('version_update')
|
||||||
|
self.fields.pop('comment')
|
||||||
|
|
||||||
|
|
||||||
class DocumentPropertiesForm(DetailForm):
|
class DocumentPropertiesForm(DetailForm):
|
||||||
|
|||||||
@@ -44,3 +44,21 @@ HISTORY_DOCUMENT_DELETED = {
|
|||||||
'details': _(u'Document "%(document)s" deleted on %(datetime)s by %(fullname)s.'),
|
'details': _(u'Document "%(document)s" deleted on %(datetime)s by %(fullname)s.'),
|
||||||
'expressions': {'fullname': 'user.get_full_name() if user.get_full_name() else user.username'}
|
'expressions': {'fullname': 'user.get_full_name() if user.get_full_name() else user.username'}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RELEASE_LEVEL_FINAL = 1
|
||||||
|
RELEASE_LEVEL_ALPHA = 2
|
||||||
|
RELEASE_LEVEL_BETA = 3
|
||||||
|
RELEASE_LEVEL_RC = 4
|
||||||
|
RELEASE_LEVEL_HF = 5
|
||||||
|
|
||||||
|
RELEASE_LEVEL_CHOICES = (
|
||||||
|
(RELEASE_LEVEL_FINAL, _(u'final')),
|
||||||
|
(RELEASE_LEVEL_ALPHA, _(u'alpha')),
|
||||||
|
(RELEASE_LEVEL_BETA, _(u'beta')),
|
||||||
|
(RELEASE_LEVEL_RC, _(u'release candidate')),
|
||||||
|
(RELEASE_LEVEL_HF, _(u'hotfix')),
|
||||||
|
)
|
||||||
|
|
||||||
|
VERSION_UPDATE_MAJOR = u'major'
|
||||||
|
VERSION_UPDATE_MINOR = u'minor'
|
||||||
|
VERSION_UPDATE_MICRO = u'micro'
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -35,7 +35,7 @@ urlpatterns = patterns('documents.views',
|
|||||||
url(r'^(?P<document_id>\d+)/clear_transformations/$', 'document_clear_transformations', (), 'document_clear_transformations'),
|
url(r'^(?P<document_id>\d+)/clear_transformations/$', 'document_clear_transformations', (), 'document_clear_transformations'),
|
||||||
|
|
||||||
url(r'^(?P<document_pk>\d+)/version/all/$', 'document_version_list', (), 'document_version_list'),
|
url(r'^(?P<document_pk>\d+)/version/all/$', 'document_version_list', (), 'document_version_list'),
|
||||||
url(r'^document/version/(?P<document_version_pk>\d+)/download/$', 'document_version_download', (), 'document_version_download'),
|
url(r'^document/version/(?P<document_version_pk>\d+)/download/$', 'document_download', (), 'document_version_download'),
|
||||||
|
|
||||||
url(r'^multiple/clear_transformations/$', 'document_multiple_clear_transformations', (), 'document_multiple_clear_transformations'),
|
url(r'^multiple/clear_transformations/$', 'document_multiple_clear_transformations', (), 'document_multiple_clear_transformations'),
|
||||||
url(r'^duplicates/list/$', 'document_find_all_duplicates', (), 'document_find_all_duplicates'),
|
url(r'^duplicates/list/$', 'document_find_all_duplicates', (), 'document_find_all_duplicates'),
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ from documents.literals import PERMISSION_DOCUMENT_CREATE, \
|
|||||||
from documents.literals import HISTORY_DOCUMENT_CREATED, \
|
from documents.literals import HISTORY_DOCUMENT_CREATED, \
|
||||||
HISTORY_DOCUMENT_EDITED, HISTORY_DOCUMENT_DELETED
|
HISTORY_DOCUMENT_EDITED, HISTORY_DOCUMENT_DELETED
|
||||||
|
|
||||||
from documents.forms import DocumentTypeSelectForm, \
|
from documents.forms import (DocumentTypeSelectForm,
|
||||||
DocumentForm_edit, DocumentPropertiesForm, \
|
DocumentForm_edit, DocumentPropertiesForm,
|
||||||
DocumentPreviewForm, \
|
DocumentPreviewForm, DocumentPageForm,
|
||||||
DocumentPageForm, DocumentPageTransformationForm, \
|
DocumentPageTransformationForm, DocumentContentForm,
|
||||||
DocumentContentForm, DocumentPageForm_edit, \
|
DocumentPageForm_edit, DocumentPageForm_text, PrintForm,
|
||||||
DocumentPageForm_text, PrintForm, DocumentTypeForm, \
|
DocumentTypeForm, DocumentTypeFilenameForm,
|
||||||
DocumentTypeFilenameForm, DocumentTypeFilenameForm_create
|
DocumentTypeFilenameForm_create)
|
||||||
from documents.wizards import DocumentCreateWizard
|
from documents.wizards import DocumentCreateWizard
|
||||||
from documents.models import (Document, DocumentType, DocumentPage,
|
from documents.models import (Document, DocumentType, DocumentPage,
|
||||||
DocumentPageTransformation, RecentDocument, DocumentTypeFilename,
|
DocumentPageTransformation, RecentDocument, DocumentTypeFilename,
|
||||||
@@ -242,12 +242,12 @@ def document_edit(request, document_id):
|
|||||||
for warning in warnings:
|
for warning in warnings:
|
||||||
messages.warning(request, warning)
|
messages.warning(request, warning)
|
||||||
|
|
||||||
document.file_filename = form.cleaned_data['new_filename']
|
document.filename = form.cleaned_data['new_filename']
|
||||||
document.description = form.cleaned_data['description']
|
document.description = form.cleaned_data['description']
|
||||||
|
|
||||||
if 'document_type_available_filenames' in form.cleaned_data:
|
if 'document_type_available_filenames' in form.cleaned_data:
|
||||||
if form.cleaned_data['document_type_available_filenames']:
|
if form.cleaned_data['document_type_available_filenames']:
|
||||||
document.file_filename = form.cleaned_data['document_type_available_filenames'].filename
|
document.filename = form.cleaned_data['document_type_available_filenames'].filename
|
||||||
|
|
||||||
document.save()
|
document.save()
|
||||||
create_history(HISTORY_DOCUMENT_EDITED, document, {'user': request.user, 'diff': return_diff(old_document, document, ['file_filename', 'description'])})
|
create_history(HISTORY_DOCUMENT_EDITED, document, {'user': request.user, 'diff': return_diff(old_document, document, ['file_filename', 'description'])})
|
||||||
@@ -291,27 +291,27 @@ def get_document_image(request, document_id, size=PREVIEW_SIZE, base64_version=F
|
|||||||
if base64_version:
|
if base64_version:
|
||||||
return HttpResponse(u'<html><body><img src="%s" /></body></html>' % document.get_image(size=size, page=page, zoom=zoom, rotation=rotation, as_base64=True))
|
return HttpResponse(u'<html><body><img src="%s" /></body></html>' % document.get_image(size=size, page=page, zoom=zoom, rotation=rotation, as_base64=True))
|
||||||
else:
|
else:
|
||||||
# TODO: hardcoded MIMETYPE
|
# TODO: fix hardcoded MIMETYPE
|
||||||
return sendfile.sendfile(request, document.get_image(size=size, page=page, zoom=zoom, rotation=rotation), mimetype=DEFAULT_FILE_FORMAT_MIMETYPE)
|
return sendfile.sendfile(request, document.get_image(size=size, page=page, zoom=zoom, rotation=rotation), mimetype=DEFAULT_FILE_FORMAT_MIMETYPE)
|
||||||
|
|
||||||
|
|
||||||
def document_version_download(request, document_version_pk):
|
def document_download(request, document_id=None, document_version_pk=None):
|
||||||
document_version = get_object_or_404(DocumentVersion, pk=document_version_pk)
|
|
||||||
return document_download(request, document_version.document.pk)
|
|
||||||
|
|
||||||
|
|
||||||
def document_download(request, document_id):
|
|
||||||
check_permissions(request.user, [PERMISSION_DOCUMENT_DOWNLOAD])
|
check_permissions(request.user, [PERMISSION_DOCUMENT_DOWNLOAD])
|
||||||
|
|
||||||
document = get_object_or_404(Document, pk=document_id)
|
if document_version_pk:
|
||||||
|
document_version = get_object_or_404(DocumentVersion, pk=document_version_pk)
|
||||||
|
else:
|
||||||
|
document_version = get_object_or_404(Document, pk=document_id).latest_version
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#Test permissions and trigger exception
|
# Test permissions and trigger exception
|
||||||
document.open()
|
fd = document_version.open()
|
||||||
|
fd.close()
|
||||||
return serve_file(
|
return serve_file(
|
||||||
request,
|
request,
|
||||||
document.file,
|
document_version.file,
|
||||||
save_as=u'"%s"' % document.get_fullname(),
|
save_as=u'"%s"' % document_version.filename,
|
||||||
content_type=document.file_mimetype if document.file_mimetype else 'application/octet-stream'
|
content_type=document_version.mimetype if document_version.mimetype else 'application/octet-stream'
|
||||||
)
|
)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
messages.error(request, e)
|
messages.error(request, e)
|
||||||
@@ -1154,14 +1154,14 @@ def document_version_list(request, document_pk):
|
|||||||
document = get_object_or_404(Document, pk=document_pk)
|
document = get_object_or_404(Document, pk=document_pk)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'object_list': document.versions.all(),
|
'object_list': document.versions.order_by('-timestamp'),
|
||||||
'title': _(u'versions for document: %s') % document,
|
'title': _(u'versions for document: %s') % document,
|
||||||
'hide_object': True,
|
'hide_object': True,
|
||||||
'object': document,
|
'object': document,
|
||||||
'extra_columns': [
|
'extra_columns': [
|
||||||
{
|
{
|
||||||
'name': _(u'version'),
|
'name': _(u'version'),
|
||||||
'attribute': 'get_version',
|
'attribute': 'get_formated_version',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': _(u'time and date'),
|
'name': _(u'time and date'),
|
||||||
|
|||||||
Reference in New Issue
Block a user