Skip to content

Commit

Permalink
Set pr.provider on creating a new object on /providers/{id}/edit
Browse files Browse the repository at this point in the history
  • Loading branch information
tortila committed Sep 27, 2023
1 parent 7e0e926 commit d3bed11
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions apps/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ def done(self, form_list, form_dict, **kwargs):
""" # noqa

def _process_formset(formset, request):
"""
Helper function to process the data from ModelFormSets used in this view
"""
instances = formset.save(commit=False)
for instance in instances:
instance.request = request
Expand Down Expand Up @@ -394,6 +397,16 @@ def _process_formset(formset, request):
pr.newsletter_opt_in = bool(newsletter_opt_in)
pr.save()

# if this view was used to edit an existing hosting provider,
# mark its ID in the new ProviderRequest object
provider_id = self.kwargs.get("provider_id")
if provider_id:
try:
pr.provider = Hostingprovider.objects.get(id=provider_id)
except Hostingprovider.DoesNotExist:
# fallback to creating a new provider
pr.provider = None

# set status
pr.status = ProviderRequestStatus.PENDING_REVIEW.value
pr.save()
Expand Down

0 comments on commit d3bed11

Please sign in to comment.