Organized the file document/forms.py a little better, class renamed, added document content form to advanced document view
This commit is contained in:
@@ -14,7 +14,7 @@ from common.conf.settings import DEFAULT_PAGE_ORIENTATION
|
|||||||
from documents.models import Document, DocumentType, \
|
from documents.models import Document, DocumentType, \
|
||||||
DocumentPage, DocumentPageTransformation
|
DocumentPage, DocumentPageTransformation
|
||||||
|
|
||||||
|
# Document page forms
|
||||||
class DocumentPageTransformationForm(forms.ModelForm):
|
class DocumentPageTransformationForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DocumentPageTransformation
|
model = DocumentPageTransformation
|
||||||
@@ -102,7 +102,11 @@ class DocumentPageForm_edit(forms.ModelForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ImageWidget(forms.widgets.Widget):
|
# Document forms
|
||||||
|
class DocumentPagesCarouselWidget(forms.widgets.Widget):
|
||||||
|
"""
|
||||||
|
Display many small representations of a document pages
|
||||||
|
"""
|
||||||
def render(self, name, value, attrs=None):
|
def render(self, name, value, attrs=None):
|
||||||
output = []
|
output = []
|
||||||
output.append(u'<div style="white-space:nowrap; overflow: auto;">')
|
output.append(u'<div style="white-space:nowrap; overflow: auto;">')
|
||||||
@@ -141,6 +145,16 @@ class ImageWidget(forms.widgets.Widget):
|
|||||||
return mark_safe(u''.join(output))
|
return mark_safe(u''.join(output))
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentPreviewForm(forms.Form):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
document = kwargs.pop('document', None)
|
||||||
|
super(DocumentPreviewForm, self).__init__(*args, **kwargs)
|
||||||
|
self.fields['preview'].initial = document
|
||||||
|
self.fields['preview'].label = _(u'Document pages (%s)') % document.documentpage_set.count()
|
||||||
|
|
||||||
|
preview = forms.CharField(widget=DocumentPagesCarouselWidget())
|
||||||
|
|
||||||
|
|
||||||
#TODO: Turn this into a base form and let others inherit
|
#TODO: Turn this into a base form and let others inherit
|
||||||
class DocumentForm(forms.ModelForm):
|
class DocumentForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@@ -167,17 +181,26 @@ class DocumentForm(forms.ModelForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DocumentPreviewForm(forms.Form):
|
class DocumentForm_edit(DocumentForm):
|
||||||
def __init__(self, *args, **kwargs):
|
class Meta:
|
||||||
document = kwargs.pop('document', None)
|
model = Document
|
||||||
super(DocumentPreviewForm, self).__init__(*args, **kwargs)
|
exclude = ('file', 'document_type', 'tags')
|
||||||
self.fields['preview'].initial = document
|
|
||||||
self.fields['preview'].label = _(u'Document pages (%s)') % document.documentpage_set.count()
|
|
||||||
|
|
||||||
preview = forms.CharField(widget=ImageWidget())
|
|
||||||
|
class DocumentPropertiesForm(DetailForm):
|
||||||
|
"""
|
||||||
|
Detail class form to display a document file based properties
|
||||||
|
"""
|
||||||
|
class Meta:
|
||||||
|
model = Document
|
||||||
|
exclude = ('file', 'tags')
|
||||||
|
|
||||||
|
|
||||||
class DocumentContentForm(forms.Form):
|
class DocumentContentForm(forms.Form):
|
||||||
|
"""
|
||||||
|
Form that contatenates all of a document pages' text content into a
|
||||||
|
single textarea widget
|
||||||
|
"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.document = kwargs.pop('document', None)
|
self.document = kwargs.pop('document', None)
|
||||||
super(DocumentContentForm, self).__init__(*args, **kwargs)
|
super(DocumentContentForm, self).__init__(*args, **kwargs)
|
||||||
@@ -198,16 +221,16 @@ class DocumentContentForm(forms.Form):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DocumentForm_view(DetailForm):
|
class DocumentTypeSelectForm(forms.Form):
|
||||||
class Meta:
|
document_type = forms.ModelChoiceField(queryset=DocumentType.objects.all(), label=(u'Document type'), required=False)
|
||||||
model = Document
|
|
||||||
exclude = ('file', 'tags')
|
|
||||||
|
|
||||||
|
|
||||||
class DocumentForm_edit(DocumentForm):
|
class PrintForm(forms.Form):
|
||||||
class Meta:
|
page_size = forms.ChoiceField(choices=PAGE_SIZE_CHOICES, initial=DEFAULT_PAPER_SIZE, label=_(u'Page size'), required=False)
|
||||||
model = Document
|
custom_page_width = forms.CharField(label=_(u'Custom page width'), required=False)
|
||||||
exclude = ('file', 'document_type', 'tags')
|
custom_page_height = forms.CharField(label=_(u'Custom page height'), required=False)
|
||||||
|
page_orientation = forms.ChoiceField(choices=PAGE_ORIENTATION_CHOICES, initial=DEFAULT_PAGE_ORIENTATION, label=_(u'Page orientation'), required=True)
|
||||||
|
page_range = forms.CharField(label=_(u'Page range'), required=False)
|
||||||
|
|
||||||
|
|
||||||
class StagingDocumentForm(forms.Form):
|
class StagingDocumentForm(forms.Form):
|
||||||
@@ -235,16 +258,3 @@ class StagingDocumentForm(forms.Form):
|
|||||||
new_filename = forms.CharField(
|
new_filename = forms.CharField(
|
||||||
label=_('New document filename'), required=False
|
label=_('New document filename'), required=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DocumentTypeSelectForm(forms.Form):
|
|
||||||
document_type = forms.ModelChoiceField(queryset=DocumentType.objects.all(), label=(u'Document type'), required=False)
|
|
||||||
|
|
||||||
|
|
||||||
class PrintForm(forms.Form):
|
|
||||||
page_size = forms.ChoiceField(choices=PAGE_SIZE_CHOICES, initial=DEFAULT_PAPER_SIZE, label=_(u'Page size'), required=False)
|
|
||||||
custom_page_width = forms.CharField(label=_(u'Custom page width'), required=False)
|
|
||||||
custom_page_height = forms.CharField(label=_(u'Custom page height'), required=False)
|
|
||||||
page_orientation = forms.ChoiceField(choices=PAGE_ORIENTATION_CHOICES, initial=DEFAULT_PAGE_ORIENTATION, label=_(u'Page orientation'), required=True)
|
|
||||||
page_range = forms.CharField(label=_(u'Page range'), required=False)
|
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ from documents.literals import PERMISSION_DOCUMENT_CREATE, \
|
|||||||
PERMISSION_DOCUMENT_EDIT
|
PERMISSION_DOCUMENT_EDIT
|
||||||
|
|
||||||
from documents.forms import DocumentTypeSelectForm, \
|
from documents.forms import DocumentTypeSelectForm, \
|
||||||
DocumentForm, DocumentForm_edit, DocumentForm_view, \
|
DocumentForm, DocumentForm_edit, DocumentPropertiesForm, \
|
||||||
StagingDocumentForm, DocumentPreviewForm, \
|
StagingDocumentForm, DocumentPreviewForm, \
|
||||||
DocumentPageForm, DocumentPageTransformationForm, \
|
DocumentPageForm, DocumentPageTransformationForm, \
|
||||||
DocumentContentForm, DocumentPageForm_edit, \
|
DocumentContentForm, DocumentPageForm_edit, \
|
||||||
@@ -295,7 +295,7 @@ def document_view_simple(request, document_id):
|
|||||||
{
|
{
|
||||||
'name': 'generic_form_subtemplate.html',
|
'name': 'generic_form_subtemplate.html',
|
||||||
'context': {
|
'context': {
|
||||||
'title': _(u'document properties'),
|
'title': _(u'document data'),
|
||||||
'form': content_form,
|
'form': content_form,
|
||||||
'object': document,
|
'object': document,
|
||||||
},
|
},
|
||||||
@@ -347,7 +347,7 @@ def document_view_advanced(request, document_id):
|
|||||||
|
|
||||||
subtemplates_list = []
|
subtemplates_list = []
|
||||||
|
|
||||||
form = DocumentForm_view(instance=document, extra_fields=[
|
document_properties_form = DocumentPropertiesForm(instance=document, extra_fields=[
|
||||||
{'label': _(u'Filename'), 'field': 'file_filename'},
|
{'label': _(u'Filename'), 'field': 'file_filename'},
|
||||||
{'label': _(u'File extension'), 'field': 'file_extension'},
|
{'label': _(u'File extension'), 'field': 'file_extension'},
|
||||||
{'label': _(u'File mimetype'), 'field': 'file_mimetype'},
|
{'label': _(u'File mimetype'), 'field': 'file_mimetype'},
|
||||||
@@ -364,6 +364,8 @@ def document_view_advanced(request, document_id):
|
|||||||
|
|
||||||
preview_form = DocumentPreviewForm(document=document)
|
preview_form = DocumentPreviewForm(document=document)
|
||||||
|
|
||||||
|
content_form = DocumentContentForm(document=document)
|
||||||
|
|
||||||
subtemplates_list.append(
|
subtemplates_list.append(
|
||||||
{
|
{
|
||||||
'name': 'generic_form_subtemplate.html',
|
'name': 'generic_form_subtemplate.html',
|
||||||
@@ -373,11 +375,23 @@ def document_view_advanced(request, document_id):
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
subtemplates_list.append(
|
subtemplates_list.append(
|
||||||
{
|
{
|
||||||
'name': 'generic_form_subtemplate.html',
|
'name': 'generic_form_subtemplate.html',
|
||||||
'context': {
|
'context': {
|
||||||
'form': form,
|
'title': _(u'document data'),
|
||||||
|
'form': content_form,
|
||||||
|
'object': document,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
subtemplates_list.append(
|
||||||
|
{
|
||||||
|
'name': 'generic_form_subtemplate.html',
|
||||||
|
'context': {
|
||||||
|
'form': document_properties_form,
|
||||||
'title': _(u'document properties'),
|
'title': _(u'document properties'),
|
||||||
'object': document,
|
'object': document,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user