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">
|
<div class="control-group">
|
||||||
{% block extra_controls %}{% endblock %}
|
{% block extra_controls %}{% endblock %}
|
||||||
{% if 'add' in actions %}
|
{% if 'add' in actions %}
|
||||||
{% add_button model|validated_viewname:"add" %}
|
{% add_button model %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'import' in actions %}
|
{% if 'import' in actions %}
|
||||||
{% import_button model|validated_viewname:"import" %}
|
{% import_button model %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'export' in actions %}
|
{% if 'export' in actions %}
|
||||||
{% export_button model|content_type %}
|
{% export_button model %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
{% comment %} <div class="d-flex flex-shrink-1">
|
{% if url %}
|
||||||
<a href="{{ add_url }}" type="button" class="btn btn-sm btn-success">
|
<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
|
<i class="mdi mdi-plus-thick"></i> Add
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
<a href="{% url import_url %}" type="button" class="btn btn-sm btn-info">
|
{% if url %}
|
||||||
<i class="mdi mdi-upload"></i> Import
|
<a href="{{ url }}" type="button" class="btn btn-sm btn-info">
|
||||||
|
<i class="mdi mdi-upload"></i> Import
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from django import template
|
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 extras.models import ExportTemplate
|
||||||
from utilities.utils import get_viewname, prepare_cloned_fields
|
from utilities.utils import get_viewname, prepare_cloned_fields
|
||||||
@ -50,24 +51,32 @@ def delete_button(instance):
|
|||||||
#
|
#
|
||||||
|
|
||||||
@register.inclusion_tag('buttons/add.html')
|
@register.inclusion_tag('buttons/add.html')
|
||||||
def add_button(url):
|
def add_button(model, action='add'):
|
||||||
url = reverse(url)
|
try:
|
||||||
|
url = reverse(get_viewname(model, action))
|
||||||
|
except NoReverseMatch:
|
||||||
|
url = None
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'add_url': url,
|
'url': url,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('buttons/import.html')
|
@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 {
|
return {
|
||||||
'import_url': url,
|
'url': url,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('buttons/export.html', takes_context=True)
|
@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
|
user = context['request'].user
|
||||||
|
|
||||||
# Determine if the "all data" export returns CSV or YAML
|
# Determine if the "all data" export returns CSV or YAML
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
import re
|
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
|
Loading…
Reference in New Issue
Block a user