diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-03-23 11:52:54 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-03-23 11:52:54 +0100 |
commit | 492a1b9c0acee48cb6d9334d93ab55512a5981a6 (patch) | |
tree | 4d0441a7deb96b5fa0dd31416f3a2d8e9ebab4c4 | |
parent | a2d98fb25b40c7aca6e0683abb09a50700f325b5 (diff) | |
download | Ishtar-492a1b9c0acee48cb6d9334d93ab55512a5981a6.tar.bz2 Ishtar-492a1b9c0acee48cb6d9334d93ab55512a5981a6.zip |
Operation forms: filter some fields if "files" module is not activated (ref #3367)
-rw-r--r-- | archaeological_operations/forms.py | 28 | ||||
-rw-r--r-- | archaeological_operations/views.py | 67 |
2 files changed, 59 insertions, 36 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 27ab4670a..041458ecd 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -857,21 +857,29 @@ class OperationFormGeneral(ManageOldType, forms.Form): def __init__(self, *args, **kwargs): super(OperationFormGeneral, self).__init__(*args, **kwargs) - if not get_current_profile().warehouse: - self.fields.pop('documentation_deadline') - self.fields.pop('documentation_received') - self.fields.pop('finds_deadline') - self.fields.pop('finds_received') + profile = get_current_profile() + if not profile.files: + self.fields.pop('report_delivery_date') + self.fields.pop('report_processing') + self.fields.pop('cira_rapporteur') + self.fields.pop('cira_date') + self.fields.pop('negative_result') + if not profile.warehouse: + self.fields.pop('documentation_deadline') + self.fields.pop('documentation_received') + self.fields.pop('finds_deadline') + self.fields.pop('finds_received') self.fields['operation_type'].choices = \ models.OperationType.get_types( initial=self.init_data.get('operation_type')) self.fields['operation_type'].help_text = \ models.OperationType.get_help() - self.fields['report_processing'].choices = \ - models.ReportState.get_types( - initial=self.init_data.get('report_processing')) - self.fields['report_processing'].help_text = \ - models.ReportState.get_help() + if 'report_processing' in self.fields: + self.fields['report_processing'].choices = \ + models.ReportState.get_types( + initial=self.init_data.get('report_processing')) + self.fields['report_processing'].help_text = \ + models.ReportState.get_help() self.fields['record_quality'].choices = \ [('', '--')] + list(models.QUALITY) if 'operation_code' in self.fields: diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py index c4e4acb5e..c886d9095 100644 --- a/archaeological_operations/views.py +++ b/archaeological_operations/views.py @@ -185,20 +185,29 @@ wizard_steps = [ ('final-operation_creation', FinalForm)] -def check_files_for_operation(self): - if not check_rights_condition(['view_file'])(self): - return False - return get_current_profile().files +def get_check_files_for_operation(other_check=None): + def func(self): + if not get_current_profile().files or \ + not check_rights_condition(['view_file'])(self): + return False + if not other_check: + return True + return other_check(self) + return func + +check_files_for_operation = get_check_files_for_operation() + ope_crea_condition_dict = { - 'filechoice-operation_creation': - check_files_for_operation, + 'filechoice-operation_creation': check_files_for_operation, 'preventive-operation_creation': - is_preventive('general-operation_creation', models.OperationType, - 'operation_type', 'prev_excavation'), + get_check_files_for_operation( + is_preventive('general-operation_creation', models.OperationType, + 'operation_type', 'prev_excavation')), 'preventivediag-operation_creation': - is_preventive('general-operation_creation', models.OperationType, - 'operation_type', 'arch_diagnostic'), + get_check_files_for_operation( + is_preventive('general-operation_creation', models.OperationType, + 'operation_type', 'arch_diagnostic')), 'townsgeneral-operation_creation': has_associated_file( 'filechoice-operation_creation', negate=True), 'towns-operation_creation': has_associated_file( @@ -232,25 +241,31 @@ operation_modif_wizard_steps = [ ('final-operation_modification', FinalForm) ] + +ope_modif_condition_dict = { + 'preventive-operation_modification': + get_check_files_for_operation( + is_preventive('general-operation_modification', models.OperationType, + 'operation_type', 'prev_excavation')), + 'preventivediag-operation_modification': + get_check_files_for_operation( + is_preventive('general-operation_modification', models.OperationType, + 'operation_type', 'arch_diagnostic')), + 'townsgeneral-operation_modification': has_associated_file( + 'general-operation_modification', negate=True), + 'towns-operation_modification': has_associated_file( + 'general-operation_modification'), + 'parcelsgeneral-operation_modification': has_associated_file( + 'general-operation_modification', negate=True), + 'parcels-operation_modification': has_associated_file( + 'general-operation_modification'), + +} + operation_modification_wizard = OperationModificationWizard.as_view( operation_modif_wizard_steps, label=_(u"Operation modification"), - condition_dict={ - 'preventive-operation_modification': is_preventive( - 'general-operation_modification', models.OperationType, - 'operation_type', 'prev_excavation'), - 'preventivediag-operation_modification': is_preventive( - 'general-operation_modification', models.OperationType, - 'operation_type', 'arch_diagnostic'), - 'townsgeneral-operation_modification': has_associated_file( - 'general-operation_modification', negate=True), - 'towns-operation_modification': has_associated_file( - 'general-operation_modification'), - 'parcelsgeneral-operation_modification': has_associated_file( - 'general-operation_modification', negate=True), - 'parcels-operation_modification': has_associated_file( - 'general-operation_modification'), -}, + condition_dict=ope_modif_condition_dict, url_name='operation_modification',) |