From b96e3af6c71981981c6959699c4ead707ac411bd Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 2 Feb 2018 16:12:57 -0500 Subject: [PATCH] Closes #1714: Standardized CSV export functionality for all object lists --- netbox/templates/circuits/circuit_list.html | 13 +++------- .../templates/circuits/circuittype_list.html | 12 +++------ netbox/templates/circuits/provider_list.html | 13 +++------- .../dcim/console_connections_list.html | 8 +++--- netbox/templates/dcim/device_list.html | 13 +++------- netbox/templates/dcim/devicerole_list.html | 12 +++------ netbox/templates/dcim/devicetype_list.html | 13 +++------- .../dcim/interface_connections_list.html | 8 +++--- netbox/templates/dcim/inventoryitem_list.html | 8 +++--- netbox/templates/dcim/manufacturer_list.html | 13 +++------- netbox/templates/dcim/platform_list.html | 12 +++------ .../dcim/power_connections_list.html | 8 +++--- netbox/templates/dcim/rack_list.html | 13 +++------- netbox/templates/dcim/rackgroup_list.html | 13 +++------- netbox/templates/dcim/region_list.html | 13 +++------- netbox/templates/dcim/site_list.html | 13 +++------- netbox/templates/inc/export_button.html | 20 -------------- netbox/templates/ipam/aggregate_list.html | 13 +++------- netbox/templates/ipam/ipaddress_list.html | 15 ++++------- netbox/templates/ipam/prefix_list.html | 15 ++++------- netbox/templates/ipam/rir_list.html | 12 +++------ netbox/templates/ipam/role_list.html | 12 +++------ netbox/templates/ipam/vlan_list.html | 15 ++++------- netbox/templates/ipam/vlangroup_list.html | 12 +++------ netbox/templates/ipam/vrf_list.html | 14 +++------- netbox/templates/secrets/secret_list.html | 6 ++--- netbox/templates/secrets/secretrole_list.html | 14 ++++------ netbox/templates/tenancy/tenant_list.html | 13 +++------- .../templates/tenancy/tenantgroup_list.html | 12 +++------ .../virtualization/cluster_list.html | 13 +++------- .../virtualization/clustergroup_list.html | 12 +++------ .../virtualization/clustertype_list.html | 12 +++------ .../virtualization/virtualmachine_list.html | 13 +++------- netbox/utilities/templates/buttons/add.html | 3 +++ .../utilities/templates/buttons/export.html | 19 ++++++++++++++ .../utilities/templates/buttons/import.html | 3 +++ netbox/utilities/templatetags/buttons.py | 26 +++++++++++++++++++ netbox/utilities/views.py | 6 ++--- 38 files changed, 180 insertions(+), 285 deletions(-) delete mode 100644 netbox/templates/inc/export_button.html create mode 100644 netbox/utilities/templates/buttons/add.html create mode 100644 netbox/utilities/templates/buttons/export.html create mode 100644 netbox/utilities/templates/buttons/import.html create mode 100644 netbox/utilities/templatetags/buttons.py diff --git a/netbox/templates/circuits/circuit_list.html b/netbox/templates/circuits/circuit_list.html index 418459a15db..de99223131e 100644 --- a/netbox/templates/circuits/circuit_list.html +++ b/netbox/templates/circuits/circuit_list.html @@ -1,19 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.circuits.add_circuit %} - - - Add a circuit - - - - Import circuits - + {% add_button 'circuits:circuit_add' %} + {% import_button 'circuits:circuit_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='circuits' %} + {% export_button content_type %}

{% block title %}Circuits{% endblock %}

diff --git a/netbox/templates/circuits/circuittype_list.html b/netbox/templates/circuits/circuittype_list.html index ce9cdf38577..af48ecd0c55 100644 --- a/netbox/templates/circuits/circuittype_list.html +++ b/netbox/templates/circuits/circuittype_list.html @@ -1,18 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.circuits.add_circuittype %} - - - Add a circuit type - - - - Import circuit types - + {% add_button 'circuits:circuittype_add' %} + {% import_button 'circuits:circuittype_import' %} {% endif %} + {% export_button content_type %}

{% block title %}Circuit Types{% endblock %}

diff --git a/netbox/templates/circuits/provider_list.html b/netbox/templates/circuits/provider_list.html index 9ba8bb83822..cb7aab40637 100644 --- a/netbox/templates/circuits/provider_list.html +++ b/netbox/templates/circuits/provider_list.html @@ -1,18 +1,13 @@ {% extends '_base.html' %} +{% load buttons %} {% block content %}
{% if perms.circuits.add_provider %} - - - Add a provider - - - - Import providers - + {% add_button 'circuits:provider_add' %} + {% import_button 'circuits:provider_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='providers' %} + {% export_button content_type %}

{% block title %}Providers{% endblock %}

diff --git a/netbox/templates/dcim/console_connections_list.html b/netbox/templates/dcim/console_connections_list.html index 57d3435e541..89eb0822dca 100644 --- a/netbox/templates/dcim/console_connections_list.html +++ b/netbox/templates/dcim/console_connections_list.html @@ -1,14 +1,12 @@ {% extends '_base.html' %} +{% load buttons %} {% block content %}
{% if perms.dcim.change_consoleport %} - - - Import connections - + {% import_button 'dcim:console_connections_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='connections' %} + {% export_button content_type %}

{% block title %}Console Connections{% endblock %}

diff --git a/netbox/templates/dcim/device_list.html b/netbox/templates/dcim/device_list.html index 34b143fc543..cccdfe4c09f 100644 --- a/netbox/templates/dcim/device_list.html +++ b/netbox/templates/dcim/device_list.html @@ -1,19 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.dcim.add_device %} - - - Add a device - - - - Import devices - + {% add_button 'dcim:device_add' %} + {% import_button 'dcim:device_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='devices' %} + {% export_button content_type %}

{% block title %}Devices{% endblock %}

diff --git a/netbox/templates/dcim/devicerole_list.html b/netbox/templates/dcim/devicerole_list.html index 871e6280670..cf58d2b1d28 100644 --- a/netbox/templates/dcim/devicerole_list.html +++ b/netbox/templates/dcim/devicerole_list.html @@ -1,18 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.dcim.add_devicerole %} - - - Add a device role - - - - Import device roles - + {% add_button 'dcim:devicerole_add' %} + {% import_button 'dcim:devicerole_import' %} {% endif %} + {% export_button content_type %}

{% block title %}Device Roles{% endblock %}

diff --git a/netbox/templates/dcim/devicetype_list.html b/netbox/templates/dcim/devicetype_list.html index 69807fcff4e..e0f365786d5 100644 --- a/netbox/templates/dcim/devicetype_list.html +++ b/netbox/templates/dcim/devicetype_list.html @@ -1,19 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.dcim.add_devicetype %} - - - Add a device type - - - - Import device types - + {% add_button 'dcim:devicetype_add' %} + {% import_button 'dcim:devicetype_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='device types' %} + {% export_button content_type %}

{% block title %}Device Types{% endblock %}

diff --git a/netbox/templates/dcim/interface_connections_list.html b/netbox/templates/dcim/interface_connections_list.html index a7355a449e2..950eb2f0b7c 100644 --- a/netbox/templates/dcim/interface_connections_list.html +++ b/netbox/templates/dcim/interface_connections_list.html @@ -1,14 +1,12 @@ {% extends '_base.html' %} +{% load buttons %} {% block content %}
{% if perms.dcim.add_interfaceconnection %} - - - Import connections - + {% import_button 'dcim:interface_connections_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='connections' %} + {% export_button content_type %}

{% block title %}Interface Connections{% endblock %}

diff --git a/netbox/templates/dcim/inventoryitem_list.html b/netbox/templates/dcim/inventoryitem_list.html index 612534d980c..5662b51d99b 100644 --- a/netbox/templates/dcim/inventoryitem_list.html +++ b/netbox/templates/dcim/inventoryitem_list.html @@ -1,15 +1,13 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.dcim.add_devicetype %} - - - Import inventory items - + {% import_button 'dcim:inventoryitem_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='inventory items' %} + {% export_button content_type %}

{% block title %}Inventory Items{% endblock %}

diff --git a/netbox/templates/dcim/manufacturer_list.html b/netbox/templates/dcim/manufacturer_list.html index ff6025af516..0ca9c40b3f5 100644 --- a/netbox/templates/dcim/manufacturer_list.html +++ b/netbox/templates/dcim/manufacturer_list.html @@ -1,19 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.dcim.add_manufacturer %} - - - Add a manufacturer - - - - Import manufacturers - + {% add_button 'dcim:manufacturer_add' %} + {% import_button 'dcim:manufacturer_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='manufacturers' %} + {% export_button content_type %}

{% block title %}Manufacturers{% endblock %}

diff --git a/netbox/templates/dcim/platform_list.html b/netbox/templates/dcim/platform_list.html index dc8d43660ed..66dce925229 100644 --- a/netbox/templates/dcim/platform_list.html +++ b/netbox/templates/dcim/platform_list.html @@ -1,18 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.dcim.add_platform %} - - - Add a platform - - - - Import platforms - + {% add_button 'dcim:platform_add' %} + {% import_button 'dcim:platform_import' %} {% endif %} + {% export_button content_type %}

{% block title %}Platforms{% endblock %}

diff --git a/netbox/templates/dcim/power_connections_list.html b/netbox/templates/dcim/power_connections_list.html index 50e983bece0..4e351eb6a90 100644 --- a/netbox/templates/dcim/power_connections_list.html +++ b/netbox/templates/dcim/power_connections_list.html @@ -1,14 +1,12 @@ {% extends '_base.html' %} +{% load buttons %} {% block content %}
{% if perms.dcim.change_powerport %} - - - Import connections - + {% import_button 'dcim:power_connections_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='connections' %} + {% export_button content_type %}

{% block title %}Power Connections{% endblock %}

diff --git a/netbox/templates/dcim/rack_list.html b/netbox/templates/dcim/rack_list.html index 88b5a2f9d0b..eb00800ec32 100644 --- a/netbox/templates/dcim/rack_list.html +++ b/netbox/templates/dcim/rack_list.html @@ -1,19 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.dcim.add_rack %} - - - Add a rack - - - - Import racks - + {% add_button 'dcim:rack_add' %} + {% import_button 'dcim:rack_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='racks' %} + {% export_button content_type %}

{% block title %}Racks{% endblock %}

diff --git a/netbox/templates/dcim/rackgroup_list.html b/netbox/templates/dcim/rackgroup_list.html index d5853f11cfa..51989db0f16 100644 --- a/netbox/templates/dcim/rackgroup_list.html +++ b/netbox/templates/dcim/rackgroup_list.html @@ -1,19 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.dcim.add_rackgroup %} - - - Add a rack group - - - - Import rack groups - + {% add_button 'dcim:rackgroup_add' %} + {% import_button 'dcim:rackgroup_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='rack groups' %} + {% export_button content_type %}

{% block title %}Rack Groups{% endblock %}

diff --git a/netbox/templates/dcim/region_list.html b/netbox/templates/dcim/region_list.html index 4d61b4acb58..d6b9f1c5a6d 100644 --- a/netbox/templates/dcim/region_list.html +++ b/netbox/templates/dcim/region_list.html @@ -1,19 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.dcim.add_region %} - - - Add a region - - - - Import regions - + {% add_button 'dcim:region_add' %} + {% import_button 'dcim:region_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='regions' %} + {% export_button content_type %}

{% block title %}Regions{% endblock %}

diff --git a/netbox/templates/dcim/site_list.html b/netbox/templates/dcim/site_list.html index 6d3e2f7f709..7baa76dad80 100644 --- a/netbox/templates/dcim/site_list.html +++ b/netbox/templates/dcim/site_list.html @@ -1,18 +1,13 @@ {% extends '_base.html' %} +{% load buttons %} {% block content %}
{% if perms.dcim.add_site %} - - - Add a site - - - - Import sites - + {% add_button 'dcim:site_add' %} + {% import_button 'dcim:site_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='sites' %} + {% export_button content_type %}

{% block title %}Sites{% endblock %}

diff --git a/netbox/templates/inc/export_button.html b/netbox/templates/inc/export_button.html deleted file mode 100644 index 8851fe1f7f8..00000000000 --- a/netbox/templates/inc/export_button.html +++ /dev/null @@ -1,20 +0,0 @@ -{% if export_templates %} -
- - -
-{% else %} - - - Export {{ obj_type }} - -{% endif %} diff --git a/netbox/templates/ipam/aggregate_list.html b/netbox/templates/ipam/aggregate_list.html index df8e4772e69..7b15479f622 100644 --- a/netbox/templates/ipam/aggregate_list.html +++ b/netbox/templates/ipam/aggregate_list.html @@ -1,20 +1,15 @@ {% extends '_base.html' %} +{% load buttons %} {% load humanize %} {% load helpers %} {% block content %}
{% if perms.ipam.add_aggregate %} - - - Add an aggregate - - - - Import aggregates - + {% add_button 'ipam:aggregate_add' %} + {% import_button 'ipam:aggregate_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='aggregates' %} + {% export_button content_type %}

{% block title %}Aggregates{% endblock %}

diff --git a/netbox/templates/ipam/ipaddress_list.html b/netbox/templates/ipam/ipaddress_list.html index 2d273145dce..9e378de54d4 100644 --- a/netbox/templates/ipam/ipaddress_list.html +++ b/netbox/templates/ipam/ipaddress_list.html @@ -1,19 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.ipam.add_ipaddress %} - - - Add an IP - - - - Import IPs - - {% endif %} - {% include 'inc/export_button.html' with obj_type='IPs' %} + {% add_button 'ipam:ipaddress_add' %} + {% import_button 'ipam:ipaddress_import' %} + {% endif %} + {% export_button content_type %}

{% block title %}IP Addresses{% endblock %}

diff --git a/netbox/templates/ipam/prefix_list.html b/netbox/templates/ipam/prefix_list.html index 4747731f8b1..8e6d28d4936 100644 --- a/netbox/templates/ipam/prefix_list.html +++ b/netbox/templates/ipam/prefix_list.html @@ -1,4 +1,5 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% load form_helpers %} @@ -9,16 +10,10 @@ Expand
{% if perms.ipam.add_prefix %} - - - Add a prefix - - - - Import prefixes - - {% endif %} - {% include 'inc/export_button.html' with obj_type='prefixes' %} + {% add_button 'ipam:prefix_add' %} + {% import_button 'ipam:prefix_import' %} + {% endif %} + {% export_button content_type %}

{% block title %}Prefixes{% endblock %}

diff --git a/netbox/templates/ipam/rir_list.html b/netbox/templates/ipam/rir_list.html index bd2a30c2a07..40a21fc2568 100644 --- a/netbox/templates/ipam/rir_list.html +++ b/netbox/templates/ipam/rir_list.html @@ -1,4 +1,5 @@ {% extends '_base.html' %} +{% load buttons %} {% load humanize %} {% load helpers %} @@ -16,15 +17,10 @@ {% endif %} {% if perms.ipam.add_rir %} - - - Add a RIR - - - - Import RIRs - + {% add_button 'ipam:rir_add' %} + {% import_button 'ipam:rir_import' %} {% endif %} + {% export_button content_type %}

{% block title %}RIRs{% endblock %}

diff --git a/netbox/templates/ipam/role_list.html b/netbox/templates/ipam/role_list.html index 54b0a892538..bc493e15b8f 100644 --- a/netbox/templates/ipam/role_list.html +++ b/netbox/templates/ipam/role_list.html @@ -1,18 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.ipam.add_role %} - - - Add a role - - - - Import roles - + {% add_button 'ipam:role_add' %} + {% import_button 'ipam:role_import' %} {% endif %} + {% export_button content_type %}

{% block title %}Prefix/VLAN Roles{% endblock %}

diff --git a/netbox/templates/ipam/vlan_list.html b/netbox/templates/ipam/vlan_list.html index b5db84e5266..29fc6a79d96 100644 --- a/netbox/templates/ipam/vlan_list.html +++ b/netbox/templates/ipam/vlan_list.html @@ -1,20 +1,15 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% load form_helpers %} {% block content %}
{% if perms.ipam.add_vlan %} - - - Add a VLAN - - - - Import VLANs - - {% endif %} - {% include 'inc/export_button.html' with obj_type='VLANs' %} + {% add_button 'ipam:vlan_add' %} + {% import_button 'ipam:vlan_import' %} + {% endif %} + {% export_button content_type %}

{% block title %}VLANs{% endblock %}

diff --git a/netbox/templates/ipam/vlangroup_list.html b/netbox/templates/ipam/vlangroup_list.html index 77d8e9b30b7..6eb63afdcd4 100644 --- a/netbox/templates/ipam/vlangroup_list.html +++ b/netbox/templates/ipam/vlangroup_list.html @@ -1,18 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.ipam.add_vlangroup %} - - - Add a VLAN group - - - - Import VLAN groups - + {% add_button 'ipam:vlangroup_add' %} + {% import_button 'ipam:vlangroup_import' %} {% endif %} + {% export_button content_type %}

{% block title %}VLAN Groups{% endblock %}

diff --git a/netbox/templates/ipam/vrf_list.html b/netbox/templates/ipam/vrf_list.html index 029426a1430..47994755425 100644 --- a/netbox/templates/ipam/vrf_list.html +++ b/netbox/templates/ipam/vrf_list.html @@ -5,16 +5,10 @@ {% block content %}
{% if perms.ipam.add_vrf %} - - - Add a VRF - - - - Import VRFs - - {% endif %} - {% include 'inc/export_button.html' with obj_type='VRFs' %} + {% add_button 'ipam:vrf_add' %} + {% import_button 'ipam:vrf_import' %} + {% endif %} + {% export_button content_type %}

{% block title %}VRFs{% endblock %}

diff --git a/netbox/templates/secrets/secret_list.html b/netbox/templates/secrets/secret_list.html index 5293b5a6d7e..4e2aa9cb97e 100644 --- a/netbox/templates/secrets/secret_list.html +++ b/netbox/templates/secrets/secret_list.html @@ -1,13 +1,11 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.secrets.add_secret %} - - - Import secrets - + {% import_button 'secrets:secret_import' %} {% endif %}

{% block title %}Secrets{% endblock %}

diff --git a/netbox/templates/secrets/secretrole_list.html b/netbox/templates/secrets/secretrole_list.html index ccaa20730d5..c76c8f748c4 100644 --- a/netbox/templates/secrets/secretrole_list.html +++ b/netbox/templates/secrets/secretrole_list.html @@ -1,18 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
- {% if perms.dcim.add_devicerole %} - - - Add a secret role - - - - Import secret roles - + {% if perms.secrets.add_secretrole %} + {% add_button 'secrets:secretrole_add' %} + {% import_button 'secrets:secretrole_import' %} {% endif %} + {% export_button content_type %}

{% block title %}Secret Roles{% endblock %}

diff --git a/netbox/templates/tenancy/tenant_list.html b/netbox/templates/tenancy/tenant_list.html index afc1a154fa0..c2181f1b8ec 100644 --- a/netbox/templates/tenancy/tenant_list.html +++ b/netbox/templates/tenancy/tenant_list.html @@ -1,19 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.tenancy.add_tenant %} - - - Add a tenant - - - - Import tenants - + {% add_button 'tenancy:tenant_add' %} + {% import_button 'tenancy:tenant_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='tenants' %} + {% export_button content_type %}

{% block title %}Tenants{% endblock %}

diff --git a/netbox/templates/tenancy/tenantgroup_list.html b/netbox/templates/tenancy/tenantgroup_list.html index 3bffb5c6b27..26bbb86bdfb 100644 --- a/netbox/templates/tenancy/tenantgroup_list.html +++ b/netbox/templates/tenancy/tenantgroup_list.html @@ -1,18 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.tenancy.add_tenantgroup %} - - - Add a tenant group - - - - Import tenant groups - + {% add_button 'tenancy:tenantgroup_add' %} + {% import_button 'tenancy:tenantgroup_import' %} {% endif %} + {% export_button content_type %}

{% block title %}Tenant Groups{% endblock %}

diff --git a/netbox/templates/virtualization/cluster_list.html b/netbox/templates/virtualization/cluster_list.html index dad7a9e4946..08f62e6ba1d 100644 --- a/netbox/templates/virtualization/cluster_list.html +++ b/netbox/templates/virtualization/cluster_list.html @@ -1,18 +1,13 @@ {% extends '_base.html' %} +{% load buttons %} {% block content %}
{% if perms.virtualization.add_cluster %} - - - Add a cluster - - - - Import clusters - + {% add_button 'virtualization:cluster_add' %} + {% import_button 'virtualization:cluster_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='clusters' %} + {% export_button content_type %}

{% block title %}Clusters{% endblock %}

diff --git a/netbox/templates/virtualization/clustergroup_list.html b/netbox/templates/virtualization/clustergroup_list.html index 6d28400c0a1..a5d042f65ff 100644 --- a/netbox/templates/virtualization/clustergroup_list.html +++ b/netbox/templates/virtualization/clustergroup_list.html @@ -1,18 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.virtualization.add_clustergroup %} - - - Add a cluster group - - - - Import cluster groups - + {% add_button 'virtualization:clustergroup_add' %} + {% import_button 'virtualization:clustergroup_import' %} {% endif %} + {% export_button content_type %}

{% block title %}Cluster Groups{% endblock %}

diff --git a/netbox/templates/virtualization/clustertype_list.html b/netbox/templates/virtualization/clustertype_list.html index 7d905ba0680..b05ae9afeeb 100644 --- a/netbox/templates/virtualization/clustertype_list.html +++ b/netbox/templates/virtualization/clustertype_list.html @@ -1,18 +1,14 @@ {% extends '_base.html' %} +{% load buttons %} {% load helpers %} {% block content %}
{% if perms.virtualization.add_clustertype %} - - - Add a cluster type - - - - Import cluster types - + {% add_button 'virtualization:clustertype_add' %} + {% import_button 'virtualization:clustertype_import' %} {% endif %} + {% export_button content_type %}

{% block title %}Cluster Types{% endblock %}

diff --git a/netbox/templates/virtualization/virtualmachine_list.html b/netbox/templates/virtualization/virtualmachine_list.html index a771dfbd937..30ed76dae0c 100644 --- a/netbox/templates/virtualization/virtualmachine_list.html +++ b/netbox/templates/virtualization/virtualmachine_list.html @@ -1,18 +1,13 @@ {% extends '_base.html' %} +{% load buttons %} {% block content %}
{% if perms.virtualization.add_virtualmachine %} - - - Add a virtual machine - - - - Import virtual machines - + {% add_button 'virtualization:virtualmachine_add' %} + {% import_button 'virtualization:virtualmachine_import' %} {% endif %} - {% include 'inc/export_button.html' with obj_type='virtual machines' %} + {% export_button content_type %}

{% block title %}Virtual Machines{% endblock %}

diff --git a/netbox/utilities/templates/buttons/add.html b/netbox/utilities/templates/buttons/add.html new file mode 100644 index 00000000000..a5278ae124f --- /dev/null +++ b/netbox/utilities/templates/buttons/add.html @@ -0,0 +1,3 @@ + + Add + diff --git a/netbox/utilities/templates/buttons/export.html b/netbox/utilities/templates/buttons/export.html new file mode 100644 index 00000000000..ee76dae6cff --- /dev/null +++ b/netbox/utilities/templates/buttons/export.html @@ -0,0 +1,19 @@ +{% if export_templates %} +
+ + +
+{% else %} + + Export + +{% endif %} \ No newline at end of file diff --git a/netbox/utilities/templates/buttons/import.html b/netbox/utilities/templates/buttons/import.html new file mode 100644 index 00000000000..67be7787100 --- /dev/null +++ b/netbox/utilities/templates/buttons/import.html @@ -0,0 +1,3 @@ + + Import + diff --git a/netbox/utilities/templatetags/buttons.py b/netbox/utilities/templatetags/buttons.py new file mode 100644 index 00000000000..3090f45384d --- /dev/null +++ b/netbox/utilities/templatetags/buttons.py @@ -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, + } diff --git a/netbox/utilities/views.py b/netbox/utilities/views.py index 917cf3002f8..7e1a34e191d 100644 --- a/netbox/utilities/views.py +++ b/netbox/utilities/views.py @@ -79,7 +79,7 @@ class ObjectListView(View): def get(self, request): model = self.queryset.model - object_ct = ContentType.objects.get_for_model(model) + content_type = ContentType.objects.get_for_model(model) if self.filter: self.queryset = self.filter(request.GET, self.queryset).qs @@ -92,7 +92,7 @@ def get(self, request): # Check for export template rendering 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 try: return et.render_to_response(queryset) @@ -125,10 +125,10 @@ def get(self, request): RequestConfig(request, paginate).configure(table) context = { + 'content_type': content_type, 'table': table, 'permissions': permissions, '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())