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 %}
</div>
<div>
{% add_button prerequisite_model %}
{% add_button prerequisite_model request.path %}
</div>
</div>
</div>

View File

@ -1,6 +1,10 @@
{% if url %}
{% load i18n %}
{% load i18n %}
{% if return_url %}
<a href="{{ url }}?return_url={{ return_url }}" type="button" class="btn btn-primary">
{% else %}
<a href="{{ url }}" type="button" class="btn btn-primary">
<i class="mdi mdi-plus-thick"></i> {% trans "Add" %}
</a>
{% 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')
def add_button(model, action='add'):
def add_button(model, return_url=None, action='add'):
try:
url = reverse(get_viewname(model, action))
except NoReverseMatch:
@ -154,6 +154,7 @@ def add_button(model, action='add'):
return {
'url': url,
'return_url': return_url,
}