Skip to content

Commit

Permalink
Merge pull request #1085 from bobeldering/bugfix/set-user-in-facility…
Browse files Browse the repository at this point in the history
…-before-calling-get_form_classes_for_display

Set user in facility before calling the get_form_classes_for_display.
  • Loading branch information
jchate6 authored Oct 22, 2024
2 parents 18b460b + 8a8e3e6 commit 61ab0d9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tom_observations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ 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()
observation_form_classes = self.get_facility_class()().get_form_classes_for_display(**kwargs)
facility = self.get_facility_class()()
facility.set_user(self.request.user)
observation_form_classes = facility.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
Expand All @@ -223,8 +225,6 @@ def get_context_data(self, **kwargs):
context['target'] = target

# allow the Facility class to add data to the context
facility = self.get_facility_class()()
facility.set_user(self.request.user)
facility_context = facility.get_facility_context_data(target=target)
context.update(facility_context)

Expand Down

0 comments on commit 61ab0d9

Please sign in to comment.