Skip to content

Commit

Permalink
add function to retrieve facility form classes for display
Browse files Browse the repository at this point in the history
  • Loading branch information
jchate6 committed Oct 11, 2024
1 parent 5b26c54 commit 532cb5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tom_observations/facility.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class BaseObservationFacility(ABC):
the other BaseObservationFacilities.
"""
name = 'BaseObservation'
observation_forms = {}

def __init__(self):
self.user = None
Expand Down Expand Up @@ -227,6 +228,16 @@ def get_form(self, observation_type):
This method takes in an observation type and returns the form type that matches it.
"""

def get_form_classes_for_display(self, **kwargs):
"""
This method returns a dictionary of the format:
{'OBSERVATION_TYPE': FacilityFormClass}
Typically this will be all or a subset of the forms in `self.observation_forms`
"""
return self.observation_forms

def get_facility_context_data(self, **kwargs):
"""
This method provides an opportunity for the Facility subclass to add additional
Expand Down
3 changes: 2 additions & 1 deletion tom_observations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ def get_context_data(self, **kwargs):
# reloaded due to form errors, only repopulate the form that was submitted.
observation_type_choices = []
initial = self.get_initial()
for observation_type, observation_form_class in self.get_facility_class().observation_forms.items():
observation_form_classes = self.get_facility_class()().get_form_classes_for_display(**kwargs)
for observation_type, observation_form_class in observation_form_classes.items():
form_data = {**initial, **{'observation_type': observation_type}}
# Repopulate the appropriate form with form data if the original submission was invalid
if observation_type == self.request.POST.get('observation_type'):
Expand Down

0 comments on commit 532cb5a

Please sign in to comment.