Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion netbox/templates/inc/missing_prerequisites.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% endblocktrans %}
</div>
<div>
{% add_button prerequisite_model %}
{% add_button prerequisite_model request.path %}
</div>
</div>
</div>
14 changes: 9 additions & 5 deletions netbox/utilities/templates/buttons/add.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% if url %}
{% load i18n %}
<a href="{{ url }}" type="button" class="btn btn-primary">
<i class="mdi mdi-plus-thick"></i> {% trans "Add" %}
</a>
{% endif %}
{% 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">
{% endif %}
<i class="mdi mdi-plus-thick"></i> {% trans "Add" %}
</a>
{% endif %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to avoid repeating ourselves:

Suggested change
{% if url %}
{% load i18n %}
<a href="{{ url }}" type="button" class="btn btn-primary">
<i class="mdi mdi-plus-thick"></i> {% trans "Add" %}
</a>
{% endif %}
{% 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">
{% endif %}
<i class="mdi mdi-plus-thick"></i> {% trans "Add" %}
</a>
{% endif %}
{% if url %}
{% load i18n %}
<a href="{{ url }}{% if return_url %}?return_url={{ return_url }}{% endif %}" type="button" class="btn btn-primary">
<i class="mdi mdi-plus-thick"></i> {% trans "Add" %}
</a>
{% endif %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah of course, makes sense. django templates still feel a bit strange to me.
i commited the fix

3 changes: 2 additions & 1 deletion netbox/utilities/templatetags/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,15 @@ 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:
url = None

return {
'url': url,
'return_url': return_url,
}


Expand Down