add optional return_url parameter to "Add" button, used by missing_prerequisites.html to return user back to initial page

This commit is contained in:
TomasNeuner 2025-08-19 18:29:17 +02:00
parent ab0a1f0bbc
commit 639c5e8052
3 changed files with 12 additions and 7 deletions

View File

@ -10,7 +10,7 @@
{% endblocktrans %} {% endblocktrans %}
</div> </div>
<div> <div>
{% add_button prerequisite_model %} {% add_button prerequisite_model request.path %}
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,6 +1,10 @@
{% if url %} {% if url %}
{% load i18n %} {% load i18n %}
<a href="{{ url }}" type="button" class="btn btn-primary"> {% if return_url %}
<i class="mdi mdi-plus-thick"></i> {% trans "Add" %} <a href="{{ url }}?return_url={{ return_url }}" type="button" class="btn btn-primary">
</a> {% else %}
{% endif %} <a href="{{ url }}" type="button" class="btn btn-primary">
{% endif %}
<i class="mdi mdi-plus-thick"></i> {% trans "Add" %}
</a>
{% endif %}

View File

@ -146,7 +146,7 @@ def sync_button(instance):
# #
@register.inclusion_tag('buttons/add.html') @register.inclusion_tag('buttons/add.html')
def add_button(model, action='add'): def add_button(model, return_url=None, action='add'):
try: try:
url = reverse(get_viewname(model, action)) url = reverse(get_viewname(model, action))
except NoReverseMatch: except NoReverseMatch:
@ -154,6 +154,7 @@ def add_button(model, action='add'):
return { return {
'url': url, 'url': url,
'return_url': return_url,
} }