mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-20 02:06:42 -06:00
Simplify add/import/export button invocation
This commit is contained in:
parent
ffc29d14a8
commit
5a3e99626d
@ -26,13 +26,13 @@ Context:
|
||||
<div class="control-group">
|
||||
{% block extra_controls %}{% endblock %}
|
||||
{% if 'add' in actions %}
|
||||
{% add_button model|validated_viewname:"add" %}
|
||||
{% add_button model %}
|
||||
{% endif %}
|
||||
{% if 'import' in actions %}
|
||||
{% import_button model|validated_viewname:"import" %}
|
||||
{% import_button model %}
|
||||
{% endif %}
|
||||
{% if 'export' in actions %}
|
||||
{% export_button model|content_type %}
|
||||
{% export_button model %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,9 +1,5 @@
|
||||
{% comment %} <div class="d-flex flex-shrink-1">
|
||||
<a href="{{ add_url }}" type="button" class="btn btn-sm btn-success">
|
||||
<i class="mdi mdi-plus-thick"></i>
|
||||
Add
|
||||
{% if url %}
|
||||
<a href="{{ url }}" type="button" class="btn btn-sm btn-success">
|
||||
<i class="mdi mdi-plus-thick"></i> Add
|
||||
</a>
|
||||
</div> {% endcomment %}
|
||||
<a href="{{ add_url }}" type="button" class="btn btn-sm btn-success">
|
||||
<i class="mdi mdi-plus-thick"></i> Add
|
||||
</a>
|
||||
{% endif %}
|
||||
|
@ -1,3 +1,5 @@
|
||||
<a href="{% url import_url %}" type="button" class="btn btn-sm btn-info">
|
||||
<i class="mdi mdi-upload"></i> Import
|
||||
</a>
|
||||
{% if url %}
|
||||
<a href="{{ url }}" type="button" class="btn btn-sm btn-info">
|
||||
<i class="mdi mdi-upload"></i> Import
|
||||
</a>
|
||||
{% endif %}
|
||||
|
@ -1,5 +1,6 @@
|
||||
from django import template
|
||||
from django.urls import reverse
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.urls import NoReverseMatch, reverse
|
||||
|
||||
from extras.models import ExportTemplate
|
||||
from utilities.utils import get_viewname, prepare_cloned_fields
|
||||
@ -50,24 +51,32 @@ def delete_button(instance):
|
||||
#
|
||||
|
||||
@register.inclusion_tag('buttons/add.html')
|
||||
def add_button(url):
|
||||
url = reverse(url)
|
||||
def add_button(model, action='add'):
|
||||
try:
|
||||
url = reverse(get_viewname(model, action))
|
||||
except NoReverseMatch:
|
||||
url = None
|
||||
|
||||
return {
|
||||
'add_url': url,
|
||||
'url': url,
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('buttons/import.html')
|
||||
def import_button(url):
|
||||
def import_button(model, action='import'):
|
||||
try:
|
||||
url = reverse(get_viewname(model, action))
|
||||
except NoReverseMatch:
|
||||
url = None
|
||||
|
||||
return {
|
||||
'import_url': url,
|
||||
'url': url,
|
||||
}
|
||||
|
||||
|
||||
@register.inclusion_tag('buttons/export.html', takes_context=True)
|
||||
def export_button(context, content_type):
|
||||
def export_button(context, model):
|
||||
content_type = ContentType.objects.get_for_model(model)
|
||||
user = context['request'].user
|
||||
|
||||
# Determine if the "all data" export returns CSV or YAML
|
||||
|
@ -1,6 +1,5 @@
|
||||
import datetime
|
||||
import decimal
|
||||
import re
|
||||
from typing import Dict, Any
|
||||
|
||||
from django import template
|
||||
|
Loading…
Reference in New Issue
Block a user