Improved new document form 'quick rename' feature logic

This commit is contained in:
Roberto Rosario
2011-06-27 22:00:12 -04:00
parent ffd86d4bc1
commit 06d3dc35e3

View File

@@ -166,6 +166,8 @@ class DocumentForm(forms.ModelForm):
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' in self.fields:
@@ -173,9 +175,10 @@ class DocumentForm(forms.ModelForm):
self.fields['document_type'].widget = forms.HiddenInput()
# Instance's document_type overrides the passed document_type
if hasattr(self, 'instance'):
if hasattr(self.instance, 'document_type'):
document_type = self.instance.document_type
if instance:
if hasattr(instance, 'document_type'):
document_type = instance.document_type
if document_type:
filenames_qs = document_type.documenttypefilename_set.filter(enabled=True)
if filenames_qs.count() > 0:
@@ -187,7 +190,7 @@ class DocumentForm(forms.ModelForm):
new_filename = forms.CharField(
label=_('New document filename'), required=False
)
class DocumentForm_edit(DocumentForm):
"""