Skip to content

Commit

Permalink
fix(apis_entities): only set field attributes for existing fields
Browse files Browse the repository at this point in the history
There is some legacy code that expects specific model fields (the ones
that were part of TempEntityClass). This commit checks if those even
exist, before setting their attributes.

Closes: #298
  • Loading branch information
b1rger committed Sep 27, 2023
1 parent 71f85e6 commit 100de8c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions apis_core/apis_entities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,19 @@ def sort_fields_list(field_names, entity_name):
crispy_main_fields, crispy_meta_fields
)
)
self.fields["status"].required = False
self.fields["collection"].required = False
self.fields["start_date_written"].required = False
self.fields["end_date_written"].required = False
# backwards compatibility:
# those fields are part of TempEntityClass - this
# block can probably be removed when TempEntityClass
# is gone from apis_entities
# for now we at least check if they exist
if "status" in self.fields:
self.fields["status"].required = False
if "collection" in self.fields:
self.fields["collection"].required = False
if "start_date_written" in self.fields:
self.fields["start_date_written"].required = False
if "end_date_written" in self.fields:
self.fields["end_date_written"].required = False

instance = getattr(self, "instance", None)
if instance != None:
Expand Down

0 comments on commit 100de8c

Please sign in to comment.