Fix redirect

This commit is contained in:
zandercymatics 2024-04-11 15:50:34 -06:00
parent 3d21e4912c
commit 1d6c06208d
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 9 additions and 9 deletions

View file

@ -805,15 +805,13 @@ class WebsiteAdmin(ListHeaderAdmin):
""" """
superuser_perm = request.user.has_perm("registrar.full_access_permission") superuser_perm = request.user.has_perm("registrar.full_access_permission")
analyst_perm = request.user.has_perm("registrar.analyst_access_permission") analyst_perm = request.user.has_perm("registrar.analyst_access_permission")
return_path = request.GET.get('return_path')
# Don't redirect to the website page on save if the user is an analyst. # Don't redirect to the website page on save if the user is an analyst.
# Rather, just redirect back to the same change page. # Rather, just redirect back to the originating page.
if analyst_perm and not superuser_perm: if (analyst_perm and not superuser_perm) and return_path:
opts = obj._meta # Redirect to the return path if it exists
pk_value = obj._get_pk_val() return HttpResponseRedirect(return_path)
return HttpResponseRedirect(
reverse("admin:%s_%s_change" % (opts.app_label, opts.model_name), args=(pk_value,))
)
return super().response_change(request, obj) return super().response_change(request, obj)

View file

@ -49,9 +49,11 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
</div> </div>
{% elif field.field.name == "alternative_domains" %} {% elif field.field.name == "alternative_domains" %}
<div class="readonly"> <div class="readonly">
{% with current_path=request.get_full_path %}
{% for alt_domain in original.alternative_domains.all %} {% for alt_domain in original.alternative_domains.all %}
<a href="{% url 'admin:registrar_website_change' alt_domain.id %}">{{ alt_domain }}</a>{% if not forloop.last %}, {% endif %} <a href="{% url 'admin:registrar_website_change' alt_domain.id %}?{{ 'return_path='|add:current_path }}">{{ alt_domain }}</a>{% if not forloop.last %}, {% endif %}
{% endfor %} {% endfor %}
{% endwith %}
</div> </div>
{% else %} {% else %}
<div class="readonly">{{ field.contents }}</div> <div class="readonly">{{ field.contents }}</div>