Improved new document form 'quick rename' feature logic
This commit is contained in:
@@ -166,6 +166,8 @@ class DocumentForm(forms.ModelForm):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
document_type = kwargs.pop('document_type', None)
|
document_type = kwargs.pop('document_type', None)
|
||||||
|
instance = kwargs.pop('instance', None)
|
||||||
|
|
||||||
super(DocumentForm, self).__init__(*args, **kwargs)
|
super(DocumentForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
if 'document_type' in self.fields:
|
if 'document_type' in self.fields:
|
||||||
@@ -173,9 +175,10 @@ class DocumentForm(forms.ModelForm):
|
|||||||
self.fields['document_type'].widget = forms.HiddenInput()
|
self.fields['document_type'].widget = forms.HiddenInput()
|
||||||
|
|
||||||
# Instance's document_type overrides the passed document_type
|
# Instance's document_type overrides the passed document_type
|
||||||
if hasattr(self, 'instance'):
|
if instance:
|
||||||
if hasattr(self.instance, 'document_type'):
|
if hasattr(instance, 'document_type'):
|
||||||
document_type = self.instance.document_type
|
document_type = instance.document_type
|
||||||
|
|
||||||
if document_type:
|
if document_type:
|
||||||
filenames_qs = document_type.documenttypefilename_set.filter(enabled=True)
|
filenames_qs = document_type.documenttypefilename_set.filter(enabled=True)
|
||||||
if filenames_qs.count() > 0:
|
if filenames_qs.count() > 0:
|
||||||
@@ -187,7 +190,7 @@ class DocumentForm(forms.ModelForm):
|
|||||||
new_filename = forms.CharField(
|
new_filename = forms.CharField(
|
||||||
label=_('New document filename'), required=False
|
label=_('New document filename'), required=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DocumentForm_edit(DocumentForm):
|
class DocumentForm_edit(DocumentForm):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user