Unify DocumentForm and DocumentForm_edit
This commit is contained in:
@@ -94,40 +94,24 @@ class DocumentPreviewForm(forms.Form):
|
||||
|
||||
|
||||
class DocumentForm(forms.ModelForm):
|
||||
"""
|
||||
Form sub classes from DocumentForm used only when editing a document
|
||||
"""
|
||||
class Meta:
|
||||
model = Document
|
||||
fields = ('label', 'description', 'language')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
document_type = kwargs.pop('document_type', None)
|
||||
instance = kwargs.pop('instance', None)
|
||||
|
||||
super(DocumentForm, self).__init__(*args, **kwargs)
|
||||
|
||||
if document_type:
|
||||
filenames_qs = document_type.documenttypefilename_set.filter(enabled=True)
|
||||
if filenames_qs.count() > 0:
|
||||
self.fields['document_type_available_filenames'] = forms.ModelChoiceField(
|
||||
queryset=filenames_qs,
|
||||
required=False,
|
||||
label=_(u'Quick document rename'))
|
||||
# Is a document (documents app edit) and has been saved (sources app upload)?
|
||||
if self.instance and self.instance.pk:
|
||||
document_type = self.instance.document_type
|
||||
|
||||
|
||||
# TODO: merge DocumentForm and DocumentForm_edit
|
||||
class DocumentForm_edit(forms.ModelForm):
|
||||
"""
|
||||
Form sub classes from DocumentForm used only when editing a document
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Document
|
||||
fields = ('label', 'description', 'language')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DocumentForm_edit, self).__init__(*args, **kwargs)
|
||||
|
||||
filenames_qs = self.instance.document_type.documenttypefilename_set.filter(enabled=True)
|
||||
if filenames_qs.count() > 0:
|
||||
filenames_qs = document_type.filenames.filter(enabled=True)
|
||||
if filenames_qs.count():
|
||||
self.fields['document_type_available_filenames'] = forms.ModelChoiceField(
|
||||
queryset=filenames_qs,
|
||||
required=False,
|
||||
|
||||
@@ -31,7 +31,7 @@ from navigation.utils import resolve_to_name
|
||||
from permissions.models import Permission
|
||||
|
||||
from .events import HISTORY_DOCUMENT_EDITED
|
||||
from .forms import (DocumentForm_edit, DocumentPropertiesForm,
|
||||
from .forms import (DocumentForm, DocumentPropertiesForm,
|
||||
DocumentPreviewForm, DocumentPageForm,
|
||||
DocumentPageTransformationForm, DocumentContentForm,
|
||||
DocumentPageForm_edit, DocumentPageForm_text, PrintForm,
|
||||
@@ -229,7 +229,7 @@ def document_edit(request, document_id):
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_PROPERTIES_EDIT, request.user, document)
|
||||
|
||||
if request.method == 'POST':
|
||||
form = DocumentForm_edit(request.POST, instance=document)
|
||||
form = DocumentForm(request.POST, instance=document)
|
||||
if form.is_valid():
|
||||
document.label = form.cleaned_data['label']
|
||||
document.description = form.cleaned_data['description']
|
||||
@@ -247,7 +247,7 @@ def document_edit(request, document_id):
|
||||
|
||||
return HttpResponseRedirect(document.get_absolute_url())
|
||||
else:
|
||||
form = DocumentForm_edit(instance=document)
|
||||
form = DocumentForm(instance=document)
|
||||
|
||||
return render_to_response('main/generic_form.html', {
|
||||
'form': form,
|
||||
|
||||
Reference in New Issue
Block a user