Skip to content

Commit

Permalink
fix: maintain parent GET param when saving pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jerivas committed Jul 20, 2021
1 parent 8030255 commit e88a334
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mezzanine/pages/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,20 @@ def save_model(self, request, obj, form, change):
parent = request.GET.get("parent")
if parent is not None and not change:
obj.parent_id = parent
obj.save()
super().save_model(request, obj, form, change)

def _maintain_parent(self, request, response):
"""
Maintain the parent ID in the querystring for response_add and
response_change.
"""
location = response._headers.get("location")
try:
location = response["Location"]
except KeyError:
location = None
parent = request.GET.get("parent")
if parent and location and "?" not in location[1]:
url = f"{location[1]}?parent={parent}"
if parent and location and "?" not in location:
url = f"{location}?parent={parent}"
return HttpResponseRedirect(url)
return response

Expand Down

0 comments on commit e88a334

Please sign in to comment.