diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-04-03 13:42:20 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-04-03 13:42:20 +0200 |
commit | f03c9a7f969d66d4b7ccb945e14f567022f59528 (patch) | |
tree | 4124a46812c68edb65c50679567e93213c6507e6 /archaeological_operations/forms.py | |
parent | 3bf841c2a36981417115fa4168e5565b53fa29ff (diff) | |
download | Ishtar-f03c9a7f969d66d4b7ccb945e14f567022f59528.tar.bz2 Ishtar-f03c9a7f969d66d4b7ccb945e14f567022f59528.zip |
Automatic copy of associated archaeological file on operation creation (refs #1745)
Diffstat (limited to 'archaeological_operations/forms.py')
-rw-r--r-- | archaeological_operations/forms.py | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index d10019aa8..af0dbb1ac 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -275,6 +275,15 @@ class OperationCodeInput(forms.HiddenInput): 'url':reverse_lazy('get_available_operation_code')} return mark_safe(rendered + js) +class OperationFormFileChoice(forms.Form): + form_label = _(u"Associated file") + associated_models = {'associated_file':File,} + currents = {'associated_file':File} + associated_file = forms.IntegerField(label=_(u"Archaelogical file"), + widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-file'), + associated_model=File), + validators=[valid_id(File)], required=False) + class OperationFormGeneral(forms.Form): form_label = _(u"General") base_model = 'archaeological_site' @@ -282,10 +291,8 @@ class OperationFormGeneral(forms.Form): 'in_charge':Person, 'cira_rapporteur':Person, 'operator':Organization, - 'associated_file':File, 'operation_type':models.OperationType, 'archaeological_site':models.ArchaeologicalSite} - currents = {'associated_file':File} pk = forms.IntegerField(required=False, widget=forms.HiddenInput) scientist = forms.IntegerField(label=_("Head scientist"), widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person', @@ -306,10 +313,6 @@ class OperationFormGeneral(forms.Form): [unicode(PersonType.objects.get(txt_idx='sra_agent').pk)])]), associated_model=Person, new=True), validators=[valid_id(Person)], required=False) - associated_file = forms.IntegerField(label=_(u"Archaelogical file"), - widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-file'), - associated_model=File), - validators=[valid_id(File)], required=False) operation_type = forms.ChoiceField(label=_(u"Operation type"), choices=[]) start_date = forms.DateField(label=_(u"Start date"), required=False, @@ -394,8 +397,24 @@ class OperationFormGeneral(forms.Form): return self.cleaned_data class OperationFormModifGeneral(OperationFormGeneral): - operation_code = forms.IntegerField(label=_(u"Operation code"), - initial=models.Operation.get_available_operation_code) + currents = {'associated_file':File} + operation_code = forms.IntegerField(label=_(u"Operation code")) + associated_file = forms.IntegerField(label=_(u"Archaelogical file"), + widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-file'), + associated_model=File), + validators=[valid_id(File)], required=False) + + def __init__(self, *args, **kwargs): + super(OperationFormModifGeneral, self).__init__(*args, **kwargs) + self.fields.keyOrder = list(self.fields.keyOrder) + self.fields.keyOrder.pop(self.fields.keyOrder.index('associated_file')) + self.fields.keyOrder.insert(self.fields.keyOrder.index('in_charge'), + 'associated_file') + +OperationFormModifGeneral.associated_models = \ + OperationFormGeneral.associated_models.copy() +OperationFormModifGeneral.associated_models['associated_file'] = File + class OperationFormPreventive(forms.Form): form_label = _(u"Preventive informations - excavation") |