From 4952af24727fff9115e84cd9200c9da9af9eaffb Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Fri, 10 Nov 2023 08:36:55 +0100 Subject: [PATCH] fix: don't expect entities to have {start|end}_date_written fields Those are part of TempEntityClass which we don't require anymore to be used. Closes: #405 --- apis_core/apis_entities/forms.py | 58 +++++++++++++++++--------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/apis_core/apis_entities/forms.py b/apis_core/apis_entities/forms.py index 9ad31f49f..4a77e1abb 100644 --- a/apis_core/apis_entities/forms.py +++ b/apis_core/apis_entities/forms.py @@ -191,33 +191,37 @@ def sort_fields_list(field_names, entity_name): instance = getattr(self, "instance", None) if instance != None: - if instance.start_date_written: - self.fields[ - "start_date_written" - ].help_text = DateParser.get_date_help_text_from_dates( - single_date=instance.start_date, - single_start_date=instance.start_start_date, - single_end_date=instance.start_end_date, - single_date_written=instance.start_date_written, - ) - else: - self.fields[ - "start_date_written" - ].help_text = DateParser.get_date_help_text_default() - - if instance.end_date_written: - self.fields[ - "end_date_written" - ].help_text = DateParser.get_date_help_text_from_dates( - single_date=instance.end_date, - single_start_date=instance.end_start_date, - single_end_date=instance.end_end_date, - single_date_written=instance.end_date_written, - ) - else: - self.fields[ - "end_date_written" - ].help_text = DateParser.get_date_help_text_default() + # same as above, part of TempEntityClass + if "start_date_written" in self.fields: + if instance.start_date_written: + self.fields[ + "start_date_written" + ].help_text = DateParser.get_date_help_text_from_dates( + single_date=instance.start_date, + single_start_date=instance.start_start_date, + single_end_date=instance.start_end_date, + single_date_written=instance.start_date_written, + ) + else: + self.fields[ + "start_date_written" + ].help_text = DateParser.get_date_help_text_default() + + # same as above, part of TempEntityClass + if "end_date_written" in self.fields: + if instance.end_date_written: + self.fields[ + "end_date_written" + ].help_text = DateParser.get_date_help_text_from_dates( + single_date=instance.end_date, + single_start_date=instance.end_start_date, + single_end_date=instance.end_end_date, + single_date_written=instance.end_date_written, + ) + else: + self.fields[ + "end_date_written" + ].help_text = DateParser.get_date_help_text_default() def save(self, *args, **kwargs): obj = super(GenericEntitiesForm, self).save(*args, **kwargs)