Closes #1714: Standardized CSV export functionality for all object lists

This commit is contained in:
Jeremy Stretch 2018-02-02 16:12:57 -05:00
parent 12e6fe1d50
commit b96e3af6c7
38 changed files with 180 additions and 285 deletions

View File

@ -1,19 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.circuits.add_circuit %} {% if perms.circuits.add_circuit %}
<a href="{% url 'circuits:circuit_add' %}" class="btn btn-primary"> {% add_button 'circuits:circuit_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'circuits:circuit_import' %}
Add a circuit
</a>
<a href="{% url 'circuits:circuit_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import circuits
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='circuits' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Circuits{% endblock %}</h1> <h1>{% block title %}Circuits{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.circuits.add_circuittype %} {% if perms.circuits.add_circuittype %}
<a href="{% url 'circuits:circuittype_add' %}" class="btn btn-primary"> {% add_button 'circuits:circuittype_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'circuits:circuittype_import' %}
Add a circuit type
</a>
<a href="{% url 'circuits:circuittype_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import circuit types
</a>
{% endif %} {% endif %}
{% export_button content_type %}
</div> </div>
<h1>{% block title %}Circuit Types{% endblock %}</h1> <h1>{% block title %}Circuit Types{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,13 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.circuits.add_provider %} {% if perms.circuits.add_provider %}
<a href="{% url 'circuits:provider_add' %}" class="btn btn-primary"> {% add_button 'circuits:provider_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'circuits:provider_import' %}
Add a provider
</a>
<a href="{% url 'circuits:provider_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import providers
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='providers' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Providers{% endblock %}</h1> <h1>{% block title %}Providers{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,14 +1,12 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.change_consoleport %} {% if perms.dcim.change_consoleport %}
<a href="{% url 'dcim:console_connections_import' %}" class="btn btn-info"> {% import_button 'dcim:console_connections_import' %}
<span class="fa fa-download" aria-hidden="true"></span>
Import connections
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='connections' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Console Connections{% endblock %}</h1> <h1>{% block title %}Console Connections{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,19 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_device %} {% if perms.dcim.add_device %}
<a href="{% url 'dcim:device_add' %}" class="btn btn-primary"> {% add_button 'dcim:device_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'dcim:device_import' %}
Add a device
</a>
<a href="{% url 'dcim:device_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import devices
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='devices' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Devices{% endblock %}</h1> <h1>{% block title %}Devices{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_devicerole %} {% if perms.dcim.add_devicerole %}
<a href="{% url 'dcim:devicerole_add' %}" class="btn btn-primary"> {% add_button 'dcim:devicerole_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'dcim:devicerole_import' %}
Add a device role
</a>
<a href="{% url 'dcim:devicerole_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import device roles
</a>
{% endif %} {% endif %}
{% export_button content_type %}
</div> </div>
<h1>{% block title %}Device Roles{% endblock %}</h1> <h1>{% block title %}Device Roles{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,19 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_devicetype %} {% if perms.dcim.add_devicetype %}
<a href="{% url 'dcim:devicetype_add' %}" class="btn btn-primary"> {% add_button 'dcim:devicetype_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'dcim:devicetype_import' %}
Add a device type
</a>
<a href="{% url 'dcim:devicetype_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import device types
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='device types' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Device Types{% endblock %}</h1> <h1>{% block title %}Device Types{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,14 +1,12 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_interfaceconnection %} {% if perms.dcim.add_interfaceconnection %}
<a href="{% url 'dcim:interface_connections_import' %}" class="btn btn-info"> {% import_button 'dcim:interface_connections_import' %}
<span class="fa fa-download" aria-hidden="true"></span>
Import connections
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='connections' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Interface Connections{% endblock %}</h1> <h1>{% block title %}Interface Connections{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,15 +1,13 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_devicetype %} {% if perms.dcim.add_devicetype %}
<a href="{% url 'dcim:inventoryitem_import' %}" class="btn btn-info"> {% import_button 'dcim:inventoryitem_import' %}
<span class="fa fa-download" aria-hidden="true"></span>
Import inventory items
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='inventory items' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Inventory Items{% endblock %}</h1> <h1>{% block title %}Inventory Items{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,19 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_manufacturer %} {% if perms.dcim.add_manufacturer %}
<a href="{% url 'dcim:manufacturer_add' %}" class="btn btn-primary"> {% add_button 'dcim:manufacturer_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'dcim:manufacturer_import' %}
Add a manufacturer
</a>
<a href="{% url 'dcim:manufacturer_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import manufacturers
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='manufacturers' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Manufacturers{% endblock %}</h1> <h1>{% block title %}Manufacturers{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_platform %} {% if perms.dcim.add_platform %}
<a href="{% url 'dcim:platform_add' %}" class="btn btn-primary"> {% add_button 'dcim:platform_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'dcim:platform_import' %}
Add a platform
</a>
<a href="{% url 'dcim:platform_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import platforms
</a>
{% endif %} {% endif %}
{% export_button content_type %}
</div> </div>
<h1>{% block title %}Platforms{% endblock %}</h1> <h1>{% block title %}Platforms{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,14 +1,12 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.change_powerport %} {% if perms.dcim.change_powerport %}
<a href="{% url 'dcim:power_connections_import' %}" class="btn btn-info"> {% import_button 'dcim:power_connections_import' %}
<span class="fa fa-download" aria-hidden="true"></span>
Import connections
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='connections' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Power Connections{% endblock %}</h1> <h1>{% block title %}Power Connections{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,19 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_rack %} {% if perms.dcim.add_rack %}
<a href="{% url 'dcim:rack_add' %}" class="btn btn-primary"> {% add_button 'dcim:rack_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'dcim:rack_import' %}
Add a rack
</a>
<a href="{% url 'dcim:rack_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import racks
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='racks' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Racks{% endblock %}</h1> <h1>{% block title %}Racks{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,19 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_rackgroup %} {% if perms.dcim.add_rackgroup %}
<a href="{% url 'dcim:rackgroup_add' %}" class="btn btn-primary"> {% add_button 'dcim:rackgroup_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'dcim:rackgroup_import' %}
Add a rack group
</a>
<a href="{% url 'dcim:rackgroup_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import rack groups
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='rack groups' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Rack Groups{% endblock %}</h1> <h1>{% block title %}Rack Groups{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,19 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_region %} {% if perms.dcim.add_region %}
<a href="{% url 'dcim:region_add' %}" class="btn btn-primary"> {% add_button 'dcim:region_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'dcim:region_import' %}
Add a region
</a>
<a href="{% url 'dcim:region_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import regions
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='regions' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Regions{% endblock %}</h1> <h1>{% block title %}Regions{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,13 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_site %} {% if perms.dcim.add_site %}
<a href="{% url 'dcim:site_add' %}" class="btn btn-primary"> {% add_button 'dcim:site_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'dcim:site_import' %}
Add a site
</a>
<a href="{% url 'dcim:site_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import sites
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='sites' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Sites{% endblock %}</h1> <h1>{% block title %}Sites{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,20 +0,0 @@
{% if export_templates %}
<div class="btn-group">
<button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="fa fa-upload" aria-hidden="true"></span>
Export {{ obj_type }} <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="?{% if request.GET %}{{ request.GET.urlencode }}&{% endif %}export">CSV (default)</a></li>
<li class="divider"></li>
{% for et in export_templates %}
<li><a href="?{% if request.GET %}{{ request.GET.urlencode }}&{% endif %}export={{ et.name }}"{% if et.description %} title="{{ et.description }}"{% endif %}>{{ et.name }}</a></li>
{% endfor %}
</ul>
</div>
{% else %}
<a href="?{% if request.GET %}{{ request.GET.urlencode }}&{% endif %}export" class="btn btn-success">
<span class="fa fa-upload" aria-hidden="true"></span>
Export {{ obj_type }}
</a>
{% endif %}

View File

@ -1,20 +1,15 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load humanize %} {% load humanize %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.ipam.add_aggregate %} {% if perms.ipam.add_aggregate %}
<a href="{% url 'ipam:aggregate_add' %}" class="btn btn-primary"> {% add_button 'ipam:aggregate_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'ipam:aggregate_import' %}
Add an aggregate
</a>
<a href="{% url 'ipam:aggregate_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import aggregates
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='aggregates' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Aggregates{% endblock %}</h1> <h1>{% block title %}Aggregates{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,19 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.ipam.add_ipaddress %} {% if perms.ipam.add_ipaddress %}
<a href="{% url 'ipam:ipaddress_add' %}" class="btn btn-primary"> {% add_button 'ipam:ipaddress_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'ipam:ipaddress_import' %}
Add an IP {% endif %}
</a> {% export_button content_type %}
<a href="{% url 'ipam:ipaddress_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import IPs
</a>
{% endif %}
{% include 'inc/export_button.html' with obj_type='IPs' %}
</div> </div>
<h1>{% block title %}IP Addresses{% endblock %}</h1> <h1>{% block title %}IP Addresses{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,4 +1,5 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% load form_helpers %} {% load form_helpers %}
@ -9,16 +10,10 @@
<a href="{% url 'ipam:prefix_list' %}{% querystring request expand='on' page=1 %}" class="btn btn-default{% if request.GET.expand %} active{% endif %}">Expand</a> <a href="{% url 'ipam:prefix_list' %}{% querystring request expand='on' page=1 %}" class="btn btn-default{% if request.GET.expand %} active{% endif %}">Expand</a>
</div> </div>
{% if perms.ipam.add_prefix %} {% if perms.ipam.add_prefix %}
<a href="{% url 'ipam:prefix_add' %}" class="btn btn-primary"> {% add_button 'ipam:prefix_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'ipam:prefix_import' %}
Add a prefix {% endif %}
</a> {% export_button content_type %}
<a href="{% url 'ipam:prefix_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import prefixes
</a>
{% endif %}
{% include 'inc/export_button.html' with obj_type='prefixes' %}
</div> </div>
<h1>{% block title %}Prefixes{% endblock %}</h1> <h1>{% block title %}Prefixes{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,4 +1,5 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load humanize %} {% load humanize %}
{% load helpers %} {% load helpers %}
@ -16,15 +17,10 @@
</a> </a>
{% endif %} {% endif %}
{% if perms.ipam.add_rir %} {% if perms.ipam.add_rir %}
<a href="{% url 'ipam:rir_add' %}" class="btn btn-primary"> {% add_button 'ipam:rir_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'ipam:rir_import' %}
Add a RIR
</a>
<a href="{% url 'ipam:rir_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import RIRs
</a>
{% endif %} {% endif %}
{% export_button content_type %}
</div> </div>
<h1>{% block title %}RIRs{% endblock %}</h1> <h1>{% block title %}RIRs{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.ipam.add_role %} {% if perms.ipam.add_role %}
<a href="{% url 'ipam:role_add' %}" class="btn btn-primary"> {% add_button 'ipam:role_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'ipam:role_import' %}
Add a role
</a>
<a href="{% url 'ipam:role_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import roles
</a>
{% endif %} {% endif %}
{% export_button content_type %}
</div> </div>
<h1>{% block title %}Prefix/VLAN Roles{% endblock %}</h1> <h1>{% block title %}Prefix/VLAN Roles{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,20 +1,15 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% load form_helpers %} {% load form_helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.ipam.add_vlan %} {% if perms.ipam.add_vlan %}
<a href="{% url 'ipam:vlan_add' %}" class="btn btn-primary"> {% add_button 'ipam:vlan_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'ipam:vlan_import' %}
Add a VLAN {% endif %}
</a> {% export_button content_type %}
<a href="{% url 'ipam:vlan_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import VLANs
</a>
{% endif %}
{% include 'inc/export_button.html' with obj_type='VLANs' %}
</div> </div>
<h1>{% block title %}VLANs{% endblock %}</h1> <h1>{% block title %}VLANs{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.ipam.add_vlangroup %} {% if perms.ipam.add_vlangroup %}
<a href="{% url 'ipam:vlangroup_add' %}" class="btn btn-primary"> {% add_button 'ipam:vlangroup_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'ipam:vlangroup_import' %}
Add a VLAN group
</a>
<a href="{% url 'ipam:vlangroup_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import VLAN groups
</a>
{% endif %} {% endif %}
{% export_button content_type %}
</div> </div>
<h1>{% block title %}VLAN Groups{% endblock %}</h1> <h1>{% block title %}VLAN Groups{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -5,16 +5,10 @@
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.ipam.add_vrf %} {% if perms.ipam.add_vrf %}
<a href="{% url 'ipam:vrf_add' %}" class="btn btn-primary"> {% add_button 'ipam:vrf_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'ipam:vrf_import' %}
Add a VRF {% endif %}
</a> {% export_button content_type %}
<a href="{% url 'ipam:vrf_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import VRFs
</a>
{% endif %}
{% include 'inc/export_button.html' with obj_type='VRFs' %}
</div> </div>
<h1>{% block title %}VRFs{% endblock %}</h1> <h1>{% block title %}VRFs{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,13 +1,11 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.secrets.add_secret %} {% if perms.secrets.add_secret %}
<a href="{% url 'secrets:secret_import' %}" class="btn btn-info"> {% import_button 'secrets:secret_import' %}
<span class="fa fa-download" aria-hidden="true"></span>
Import secrets
</a>
{% endif %} {% endif %}
</div> </div>
<h1>{% block title %}Secrets{% endblock %}</h1> <h1>{% block title %}Secrets{% endblock %}</h1>

View File

@ -1,18 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.dcim.add_devicerole %} {% if perms.secrets.add_secretrole %}
<a href="{% url 'secrets:secretrole_add' %}" class="btn btn-primary"> {% add_button 'secrets:secretrole_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'secrets:secretrole_import' %}
Add a secret role
</a>
<a href="{% url 'secrets:secretrole_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import secret roles
</a>
{% endif %} {% endif %}
{% export_button content_type %}
</div> </div>
<h1>{% block title %}Secret Roles{% endblock %}</h1> <h1>{% block title %}Secret Roles{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,19 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.tenancy.add_tenant %} {% if perms.tenancy.add_tenant %}
<a href="{% url 'tenancy:tenant_add' %}" class="btn btn-primary"> {% add_button 'tenancy:tenant_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'tenancy:tenant_import' %}
Add a tenant
</a>
<a href="{% url 'tenancy:tenant_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import tenants
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='tenants' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Tenants{% endblock %}</h1> <h1>{% block title %}Tenants{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.tenancy.add_tenantgroup %} {% if perms.tenancy.add_tenantgroup %}
<a href="{% url 'tenancy:tenantgroup_add' %}" class="btn btn-primary"> {% add_button 'tenancy:tenantgroup_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'tenancy:tenantgroup_import' %}
Add a tenant group
</a>
<a href="{% url 'tenancy:tenantgroup_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import tenant groups
</a>
{% endif %} {% endif %}
{% export_button content_type %}
</div> </div>
<h1>{% block title %}Tenant Groups{% endblock %}</h1> <h1>{% block title %}Tenant Groups{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,13 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.virtualization.add_cluster %} {% if perms.virtualization.add_cluster %}
<a href="{% url 'virtualization:cluster_add' %}" class="btn btn-primary"> {% add_button 'virtualization:cluster_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'virtualization:cluster_import' %}
Add a cluster
</a>
<a href="{% url 'virtualization:cluster_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import clusters
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='clusters' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Clusters{% endblock %}</h1> <h1>{% block title %}Clusters{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.virtualization.add_clustergroup %} {% if perms.virtualization.add_clustergroup %}
<a href="{% url 'virtualization:clustergroup_add' %}" class="btn btn-primary"> {% add_button 'virtualization:clustergroup_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'virtualization:clustergroup_import' %}
Add a cluster group
</a>
<a href="{% url 'virtualization:clustergroup_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import cluster groups
</a>
{% endif %} {% endif %}
{% export_button content_type %}
</div> </div>
<h1>{% block title %}Cluster Groups{% endblock %}</h1> <h1>{% block title %}Cluster Groups{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,14 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% load helpers %} {% load helpers %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.virtualization.add_clustertype %} {% if perms.virtualization.add_clustertype %}
<a href="{% url 'virtualization:clustertype_add' %}" class="btn btn-primary"> {% add_button 'virtualization:clustertype_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'virtualization:clustertype_import' %}
Add a cluster type
</a>
<a href="{% url 'virtualization:clustertype_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import cluster types
</a>
{% endif %} {% endif %}
{% export_button content_type %}
</div> </div>
<h1>{% block title %}Cluster Types{% endblock %}</h1> <h1>{% block title %}Cluster Types{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -1,18 +1,13 @@
{% extends '_base.html' %} {% extends '_base.html' %}
{% load buttons %}
{% block content %} {% block content %}
<div class="pull-right"> <div class="pull-right">
{% if perms.virtualization.add_virtualmachine %} {% if perms.virtualization.add_virtualmachine %}
<a href="{% url 'virtualization:virtualmachine_add' %}" class="btn btn-primary"> {% add_button 'virtualization:virtualmachine_add' %}
<span class="fa fa-plus" aria-hidden="true"></span> {% import_button 'virtualization:virtualmachine_import' %}
Add a virtual machine
</a>
<a href="{% url 'virtualization:virtualmachine_import' %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span>
Import virtual machines
</a>
{% endif %} {% endif %}
{% include 'inc/export_button.html' with obj_type='virtual machines' %} {% export_button content_type %}
</div> </div>
<h1>{% block title %}Virtual Machines{% endblock %}</h1> <h1>{% block title %}Virtual Machines{% endblock %}</h1>
<div class="row"> <div class="row">

View File

@ -0,0 +1,3 @@
<a href="{% url add_url %}" class="btn btn-primary">
<span class="fa fa-plus" aria-hidden="true"></span> Add
</a>

View File

@ -0,0 +1,19 @@
{% if export_templates %}
<div class="btn-group">
<button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="fa fa-upload" aria-hidden="true"></span>
Export <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="?{% if url_params %}{{ url_params.urlencode }}&{% endif %}export">CSV (default)</a></li>
<li class="divider"></li>
{% for et in export_templates %}
<li><a href="?{% if url_params %}{{ url_params.urlencode }}&{% endif %}export={{ et.name }}"{% if et.description %} title="{{ et.description }}"{% endif %}>{{ et.name }}</a></li>
{% endfor %}
</ul>
</div>
{% else %}
<a href="?{% if url_params %}{{ url_params.urlencode }}&{% endif %}export" class="btn btn-success">
<span class="fa fa-upload" aria-hidden="true"></span> Export
</a>
{% endif %}

View File

@ -0,0 +1,3 @@
<a href="{% url import_url %}" class="btn btn-info">
<span class="fa fa-download" aria-hidden="true"></span> Import
</a>

View File

@ -0,0 +1,26 @@
from __future__ import unicode_literals
from django import template
from extras.models import ExportTemplate
register = template.Library()
@register.inclusion_tag('buttons/add.html')
def add_button(url):
return {'add_url': url}
@register.inclusion_tag('buttons/import.html')
def import_button(url):
return {'import_url': url}
@register.inclusion_tag('buttons/export.html', takes_context=True)
def export_button(context, content_type=None):
export_templates = ExportTemplate.objects.filter(content_type=content_type)
return {
'url_params': context['request'].GET,
'export_templates': export_templates,
}

View File

@ -79,7 +79,7 @@ class ObjectListView(View):
def get(self, request): def get(self, request):
model = self.queryset.model model = self.queryset.model
object_ct = ContentType.objects.get_for_model(model) content_type = ContentType.objects.get_for_model(model)
if self.filter: if self.filter:
self.queryset = self.filter(request.GET, self.queryset).qs self.queryset = self.filter(request.GET, self.queryset).qs
@ -92,7 +92,7 @@ class ObjectListView(View):
# Check for export template rendering # Check for export template rendering
if request.GET.get('export'): if request.GET.get('export'):
et = get_object_or_404(ExportTemplate, content_type=object_ct, name=request.GET.get('export')) et = get_object_or_404(ExportTemplate, content_type=content_type, name=request.GET.get('export'))
queryset = CustomFieldQueryset(self.queryset, custom_fields) if custom_fields else self.queryset queryset = CustomFieldQueryset(self.queryset, custom_fields) if custom_fields else self.queryset
try: try:
return et.render_to_response(queryset) return et.render_to_response(queryset)
@ -125,10 +125,10 @@ class ObjectListView(View):
RequestConfig(request, paginate).configure(table) RequestConfig(request, paginate).configure(table)
context = { context = {
'content_type': content_type,
'table': table, 'table': table,
'permissions': permissions, 'permissions': permissions,
'filter_form': self.filter_form(request.GET, label_suffix='') if self.filter_form else None, 'filter_form': self.filter_form(request.GET, label_suffix='') if self.filter_form else None,
'export_templates': ExportTemplate.objects.filter(content_type=object_ct),
} }
context.update(self.extra_context()) context.update(self.extra_context())