diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-05-29 11:19:14 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-05-29 11:19:14 +0200 |
commit | 84de894f83cb9eaaae81bb5514f8cacef4c1d986 (patch) | |
tree | 87d0f32604e7b960870a72713094dabfd3e3553e /archaeological_operations | |
parent | da8744afc3ca6d0fbc9c35825e84dcb9a52566ad (diff) | |
download | Ishtar-84de894f83cb9eaaae81bb5514f8cacef4c1d986.tar.bz2 Ishtar-84de894f83cb9eaaae81bb5514f8cacef4c1d986.zip |
Fix operation_code display when old_code is hidden (refs #4104)
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/forms.py | 24 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 25 |
2 files changed, 35 insertions, 14 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index e28fb2421..2309a4f4a 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -905,14 +905,6 @@ class OperationFormGeneral(CustomForm, ManageOldType): if 'record_quality' in self.fields: self.fields['record_quality'].choices = \ [('', '--')] + list(models.QUALITY) - if 'operation_code' in self.fields: - fields = OrderedDict() - ope_code = self.fields.pop('operation_code') - for key, value in self.fields.items(): - if key == 'old_code': - fields['operation_code'] = ope_code - fields[key] = value - self.fields = fields def clean(self): cleaned_data = self.cleaned_data @@ -955,7 +947,6 @@ class OperationFormGeneral(CustomForm, ManageOldType): if ops.count(): max_val = models.Operation.objects.filter(year=year).aggregate( Max('operation_code'))["operation_code__max"] - msg = '' if year and max_val: msg = _( u"Operation code already exists for year: %(year)d - use a " @@ -980,14 +971,19 @@ class OperationFormModifGeneral(OperationFormGeneral): def __init__(self, *args, **kwargs): super(OperationFormModifGeneral, self).__init__(*args, **kwargs) - asso_file = self.fields.pop('associated_file') if not get_current_profile().files: - return + self.fields.pop('associated_file') + fields = OrderedDict() - for key, value in self.fields.items(): - if key == 'in_charge': - fields['associated_file'] = asso_file + for idx, field in enumerate(self.fields.items()): + key, value = field + if 'associated_file' in self.fields and ( + key == 'in_charge' or idx > 6): + fields['associated_file'] = self.fields.pop('associated_file') fields[key] = value + if 'operation_code' in self.fields and ( + key == 'year' or idx > 5): + fields['operation_code'] = self.fields.pop('operation_code') self.fields = fields diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 657a3aa4c..e95010d36 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1809,6 +1809,20 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): }, ignored=base_ignored_steps ), + FormData( + "Set an operation to an exiting operation code for this year", + form_datas={ + 'selec': {}, + 'general': { + 'operation_type': 2, + 'operation_code': 42, + 'year': 2017}, + 'townsgeneral': [], + 'parcelsgeneral': [], + }, + ignored=base_ignored_steps, + error_expected='general' + ), ] def pre_wizard(self): @@ -1819,6 +1833,12 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): init_parcel = self.create_parcel()[0] operation.parcels.add(init_parcel) + self.create_operation() + operation2 = self.operations[1] + operation2.year = 2017 + operation2.operation_code = 42 + operation2.save() + from archaeological_context_records.models import ContextRecord cr_data = {'label': "Context record", "operation": operation, 'parcel': init_parcel, @@ -1831,14 +1851,17 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): self.form_datas[0].set('general', 'operation_type', self.ope_type.pk) self.form_datas[1].set('general', 'operation_type', self.ope_type.pk) self.form_datas[2].set('general', 'operation_type', self.ope_type.pk) + self.form_datas[3].set('general', 'operation_type', self.ope_type.pk) data = self.form_datas[0].form_datas data2 = self.form_datas[1].form_datas data3 = self.form_datas[2].form_datas + data4 = self.form_datas[3].form_datas data['selec']['pk'] = operation.pk data2['selec']['pk'] = operation.pk data3['selec']['pk'] = operation.pk + data4['selec']['pk'] = operation.pk town = self.create_towns( datas={'numero_insee': '67890', 'name': 'Twin Peaks'})[-1] @@ -1846,6 +1869,7 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): data['townsgeneral'] = towns data2['townsgeneral'] = towns data3['townsgeneral'] = towns + data4['townsgeneral'] = towns parcel_data = { 'town': town.pk, 'year': 2017, 'section': 'S', @@ -1853,6 +1877,7 @@ class OperationWizardModifTest(WizardTest, OperationInitTest, TestCase): data['parcelsgeneral'].append(parcel_data) data2['parcelsgeneral'].append(parcel_data) data3['parcelsgeneral'].append(parcel_data) + data4['parcelsgeneral'].append(parcel_data) parcel_data_2 = { 'town': init_parcel.town.pk, 'year': init_parcel.year or '', |