diff options
Diffstat (limited to 'archaeological_files/forms.py')
-rw-r--r-- | archaeological_files/forms.py | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index 6e52bcff1..9d2c14691 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -121,8 +121,8 @@ class FileSelect(DocumentItemSelect): def __init__(self, *args, **kwargs): super(FileSelect, self).__init__(*args, **kwargs) - if settings.ISHTAR_DPTS: - k = 'towns__numero_insee__startswith' + k = 'towns__numero_insee__startswith' + if settings.ISHTAR_DPTS and k in self.fields: self.fields[k].choices = [ ('', '--')] + list(settings.ISHTAR_DPTS) @@ -247,19 +247,20 @@ class FileFormGeneral(ManageOldType): label=_(u"Total surface (m2)"), validators=[validators.MinValueValidator(0), validators.MaxValueValidator(999999999)]) - address = forms.CharField(label=_(u"Main address"), widget=forms.Textarea) - address_complement = forms.CharField(label=_(u"Main address - complement"), + address = forms.CharField(label=_("Main address"), widget=forms.Textarea) + address_complement = forms.CharField(label=_("Main address - complement"), required=False) def __init__(self, *args, **kwargs): super(FileFormGeneral, self).__init__(*args, **kwargs) - self.fields['file_type'].choices = models.FileType.get_types( - initial=self.init_data.get('file_type')) - self.fields['file_type'].help_text = models.FileType.get_help() + if 'file_type' in self.fields: + self.fields['file_type'].choices = models.FileType.get_types( + initial=self.init_data.get('file_type')) + self.fields['file_type'].help_text = models.FileType.get_help() q = models.File.objects\ .filter(internal_reference__isnull=False)\ .exclude(internal_reference='').order_by('-pk') - if q.count(): + if q.count() and 'internal_reference' in self.fields: lbl = self.fields['internal_reference'].label lbl += _(u"<br/>(last recorded: %s)") % ( q.all()[0].internal_reference) @@ -347,9 +348,10 @@ class FileFormPreventive(ManageOldType, forms.Form): initial=self.init_data.get('saisine_type')) self.fields['saisine_type'].help_text = \ models.SaisineType.get_help() - self.fields['permit_type'].choices = models.PermitType.get_types( - initial=self.init_data.get('permit_type'), default='NP') - self.fields['permit_type'].help_text = models.PermitType.get_help() + if 'permit_type' in self.fields: + self.fields['permit_type'].choices = models.PermitType.get_types( + initial=self.init_data.get('permit_type'), default='NP') + self.fields['permit_type'].help_text = models.PermitType.get_help() class FileFormResearch(CustomForm, ManageOldType, forms.Form): @@ -407,12 +409,13 @@ class FileFormResearch(CustomForm, ManageOldType, forms.Form): def __init__(self, *args, **kwargs): super(FileFormResearch, self).__init__(*args, **kwargs) - self.fields['requested_operation_type'].choices = \ - OperationType.get_types( - dct={"preventive": False}, - initial=self.init_data.get('requested_operation_type')) - self.fields['requested_operation_type'].help_text = \ - OperationType.get_help() + if 'requested_operation_type' in self.fields: + self.fields['requested_operation_type'].choices = \ + OperationType.get_types( + dct={"preventive": False}, + initial=self.init_data.get('requested_operation_type')) + self.fields['requested_operation_type'].help_text = \ + OperationType.get_help() class FinalFileClosingForm(FinalForm): @@ -449,12 +452,13 @@ class AdministrativeActFileModifySelect(TableSelect): def __init__(self, *args, **kwargs): super(AdministrativeActFileModifySelect, self).__init__(*args, **kwargs) - self.fields['act_type'].choices = ActType.get_types( - dct={'intented_to': 'F'}) - self.fields['act_type'].help_text = ActType.get_help( - dct={'intented_to': 'F'}) - if settings.ISHTAR_DPTS: - k = 'operation__towns__numero_insee__startswith' + if 'act_type' in self.fields: + self.fields['act_type'].choices = ActType.get_types( + dct={'intented_to': 'F'}) + self.fields['act_type'].help_text = ActType.get_help( + dct={'intented_to': 'F'}) + k = 'operation__towns__numero_insee__startswith' + if settings.ISHTAR_DPTS and k in self.fields: self.fields[k].choices = [ ('', '--')] + list(settings.ISHTAR_DPTS) @@ -537,12 +541,13 @@ class AdministrativeActFileSelect(TableSelect): def __init__(self, *args, **kwargs): super(AdministrativeActFileSelect, self).__init__(*args, **kwargs) - self.fields['act_type'].choices = ActType.get_types( - dct={'intented_to': 'F'}) - self.fields['act_type'].help_text = ActType.get_help( - dct={'intented_to': 'F'}) - if settings.ISHTAR_DPTS: - k = 'associated_file__towns__numero_insee__startswith' + if 'act_type' in self.fields: + self.fields['act_type'].choices = ActType.get_types( + dct={'intented_to': 'F'}) + self.fields['act_type'].help_text = ActType.get_help( + dct={'intented_to': 'F'}) + k = 'associated_file__towns__numero_insee__startswith' + if k in self.fields and settings.ISHTAR_DPTS: self.fields[k].choices = [ ('', '--')] + list(settings.ISHTAR_DPTS) |