From 22246353e21eb37aaf398414c90a159443e576f5 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 9 Mar 2020 10:22:30 -0400 Subject: [PATCH 1/6] Remove oneline filter --- netbox/templates/dcim/site.html | 2 +- netbox/utilities/templatetags/helpers.py | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/netbox/templates/dcim/site.html b/netbox/templates/dcim/site.html index 5e26b9a22..ae452bde9 100644 --- a/netbox/templates/dcim/site.html +++ b/netbox/templates/dcim/site.html @@ -143,7 +143,7 @@ {% if site.physical_address %}
- + Map it
diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 5cede8a7e..eda80f294 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -20,15 +20,6 @@ register = template.Library() # Filters # -@register.filter() -def oneline(value): - """ - Replace each line break with a single space - """ - value = value.replace('\r', '') - return value.replace('\n', ' ') - - @register.filter() def placeholder(value): """ From 0439be287093a8423d1e142dc5f87f962a6b794a Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 9 Mar 2020 10:24:37 -0400 Subject: [PATCH 2/6] Remove unused getlist and getkey filters --- netbox/utilities/templatetags/helpers.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index eda80f294..51768b56d 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -31,22 +31,6 @@ def placeholder(value): return mark_safe(placeholder) -@register.filter() -def getlist(value, arg): - """ - Return all values of a QueryDict key - """ - return value.getlist(arg) - - -@register.filter -def getkey(value, key): - """ - Return a dictionary item specified by key - """ - return value[key] - - # TODO: Rename this filter as py-gfm is no longer in use @register.filter(is_safe=True) def gfm(value): From 1423fd902435cb4c9edffec20bd04fd817ce0158 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 9 Mar 2020 10:31:29 -0400 Subject: [PATCH 3/6] Rename gfm filter to render_markdown --- netbox/templates/circuits/circuit.html | 2 +- netbox/templates/circuits/provider.html | 6 +++--- netbox/templates/dcim/device.html | 2 +- netbox/templates/dcim/devicetype.html | 2 +- netbox/templates/dcim/powerfeed.html | 2 +- netbox/templates/dcim/rack.html | 2 +- netbox/templates/dcim/site.html | 2 +- netbox/templates/extras/script.html | 2 +- netbox/templates/extras/tag.html | 2 +- netbox/templates/tenancy/tenant.html | 2 +- netbox/templates/virtualization/cluster.html | 2 +- netbox/templates/virtualization/virtualmachine.html | 2 +- netbox/utilities/templatetags/helpers.py | 3 +-- 13 files changed, 15 insertions(+), 16 deletions(-) diff --git a/netbox/templates/circuits/circuit.html b/netbox/templates/circuits/circuit.html index 07d3c360d..51f80cca5 100644 --- a/netbox/templates/circuits/circuit.html +++ b/netbox/templates/circuits/circuit.html @@ -119,7 +119,7 @@
{% if circuit.comments %} - {{ circuit.comments|gfm }} + {{ circuit.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/circuits/provider.html b/netbox/templates/circuits/provider.html index 7472366c5..dad07bc7c 100644 --- a/netbox/templates/circuits/provider.html +++ b/netbox/templates/circuits/provider.html @@ -88,11 +88,11 @@ NOC Contact - {{ provider.noc_contact|gfm|placeholder }} + {{ provider.noc_contact|markdown|placeholder }} Admin Contact - {{ provider.admin_contact|gfm|placeholder }} + {{ provider.admin_contact|markdown|placeholder }} Circuits @@ -110,7 +110,7 @@
{% if provider.comments %} - {{ provider.comments|gfm }} + {{ provider.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 5ab28b409..9e16f6e6c 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -325,7 +325,7 @@
{% if device.comments %} - {{ device.comments|gfm }} + {{ device.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/dcim/devicetype.html b/netbox/templates/dcim/devicetype.html index 292a31c89..27c61de76 100644 --- a/netbox/templates/dcim/devicetype.html +++ b/netbox/templates/dcim/devicetype.html @@ -149,7 +149,7 @@
{% if devicetype.comments %} - {{ devicetype.comments|gfm }} + {{ devicetype.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/dcim/powerfeed.html b/netbox/templates/dcim/powerfeed.html index 316e0e5f0..350d9bd52 100644 --- a/netbox/templates/dcim/powerfeed.html +++ b/netbox/templates/dcim/powerfeed.html @@ -158,7 +158,7 @@
{% if powerfeed.comments %} - {{ powerfeed.comments|gfm }} + {{ powerfeed.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index b43a4bfdf..a824f44de 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -198,7 +198,7 @@
{% if rack.comments %} - {{ rack.comments|gfm }} + {{ rack.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/dcim/site.html b/netbox/templates/dcim/site.html index ae452bde9..ac7e1d07f 100644 --- a/netbox/templates/dcim/site.html +++ b/netbox/templates/dcim/site.html @@ -206,7 +206,7 @@
{% if site.comments %} - {{ site.comments|gfm }} + {{ site.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/extras/script.html b/netbox/templates/extras/script.html index fc10db80f..bf83e7fd9 100644 --- a/netbox/templates/extras/script.html +++ b/netbox/templates/extras/script.html @@ -47,7 +47,7 @@ {{ forloop.counter }} {% log_level level %} - {{ message|gfm }} + {{ message|markdown }} {% empty %} diff --git a/netbox/templates/extras/tag.html b/netbox/templates/extras/tag.html index 2857d6188..f127d365a 100644 --- a/netbox/templates/extras/tag.html +++ b/netbox/templates/extras/tag.html @@ -90,7 +90,7 @@
{% if tag.comments %} - {{ tag.comments|gfm }} + {{ tag.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/tenancy/tenant.html b/netbox/templates/tenancy/tenant.html index 9a1ed1be8..e5cea5705 100644 --- a/netbox/templates/tenancy/tenant.html +++ b/netbox/templates/tenancy/tenant.html @@ -87,7 +87,7 @@
{% if tenant.comments %} - {{ tenant.comments|gfm }} + {{ tenant.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/virtualization/cluster.html b/netbox/templates/virtualization/cluster.html index 92540fd70..0d2b1a968 100644 --- a/netbox/templates/virtualization/cluster.html +++ b/netbox/templates/virtualization/cluster.html @@ -115,7 +115,7 @@
{% if cluster.comments %} - {{ cluster.comments|gfm }} + {{ cluster.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index 8f3bb61d4..b5339f508 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -152,7 +152,7 @@
{% if virtualmachine.comments %} - {{ virtualmachine.comments|gfm }} + {{ virtualmachine.comments|markdown }} {% else %} None {% endif %} diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 51768b56d..5086265db 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -31,9 +31,8 @@ def placeholder(value): return mark_safe(placeholder) -# TODO: Rename this filter as py-gfm is no longer in use @register.filter(is_safe=True) -def gfm(value): +def render_markdown(value): """ Render text as Markdown """ From 1069ad21d8c154b25c657e281934be1a466f92fd Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 9 Mar 2020 10:38:29 -0400 Subject: [PATCH 4/6] Remove unused contains filter --- netbox/utilities/templatetags/helpers.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 5086265db..db4d59114 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -92,14 +92,6 @@ def url_name(model, action): return None -@register.filter() -def contains(value, arg): - """ - Test whether a value contains any of a given set of strings. `arg` should be a comma-separated list of strings. - """ - return any(s in value for s in arg.split(',')) - - @register.filter() def bettertitle(value): """ From 16d3cebf3e6e2e38b88a6a5cae8da6d66079f593 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 9 Mar 2020 10:42:32 -0400 Subject: [PATCH 5/6] Update markdown filter name --- netbox/templates/circuits/circuit.html | 2 +- netbox/templates/circuits/provider.html | 6 +++--- netbox/templates/dcim/device.html | 2 +- netbox/templates/dcim/devicetype.html | 2 +- netbox/templates/dcim/powerfeed.html | 2 +- netbox/templates/dcim/rack.html | 2 +- netbox/templates/dcim/site.html | 2 +- netbox/templates/extras/script.html | 2 +- netbox/templates/extras/tag.html | 2 +- netbox/templates/tenancy/tenant.html | 2 +- netbox/templates/virtualization/cluster.html | 2 +- netbox/templates/virtualization/virtualmachine.html | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/netbox/templates/circuits/circuit.html b/netbox/templates/circuits/circuit.html index 51f80cca5..4d7fe9fe2 100644 --- a/netbox/templates/circuits/circuit.html +++ b/netbox/templates/circuits/circuit.html @@ -119,7 +119,7 @@
{% if circuit.comments %} - {{ circuit.comments|markdown }} + {{ circuit.comments|render_markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/circuits/provider.html b/netbox/templates/circuits/provider.html index dad07bc7c..faeb516ee 100644 --- a/netbox/templates/circuits/provider.html +++ b/netbox/templates/circuits/provider.html @@ -88,11 +88,11 @@ NOC Contact - {{ provider.noc_contact|markdown|placeholder }} + {{ provider.noc_contact|render_markdown|placeholder }} Admin Contact - {{ provider.admin_contact|markdown|placeholder }} + {{ provider.admin_contact|render_markdown|placeholder }} Circuits @@ -110,7 +110,7 @@
{% if provider.comments %} - {{ provider.comments|markdown }} + {{ provider.comments|render_markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 9e16f6e6c..c657e9fc5 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -325,7 +325,7 @@
{% if device.comments %} - {{ device.comments|markdown }} + {{ device.comments|render_markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/dcim/devicetype.html b/netbox/templates/dcim/devicetype.html index 27c61de76..352141a9a 100644 --- a/netbox/templates/dcim/devicetype.html +++ b/netbox/templates/dcim/devicetype.html @@ -149,7 +149,7 @@
{% if devicetype.comments %} - {{ devicetype.comments|markdown }} + {{ devicetype.comments|render_markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/dcim/powerfeed.html b/netbox/templates/dcim/powerfeed.html index 350d9bd52..ca717b5e1 100644 --- a/netbox/templates/dcim/powerfeed.html +++ b/netbox/templates/dcim/powerfeed.html @@ -158,7 +158,7 @@
{% if powerfeed.comments %} - {{ powerfeed.comments|markdown }} + {{ powerfeed.comments|render_markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index a824f44de..99d9e4697 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -198,7 +198,7 @@
{% if rack.comments %} - {{ rack.comments|markdown }} + {{ rack.comments|render_markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/dcim/site.html b/netbox/templates/dcim/site.html index ac7e1d07f..9f842bf10 100644 --- a/netbox/templates/dcim/site.html +++ b/netbox/templates/dcim/site.html @@ -206,7 +206,7 @@
{% if site.comments %} - {{ site.comments|markdown }} + {{ site.comments|render_markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/extras/script.html b/netbox/templates/extras/script.html index bf83e7fd9..6d7aca126 100644 --- a/netbox/templates/extras/script.html +++ b/netbox/templates/extras/script.html @@ -47,7 +47,7 @@ {{ forloop.counter }} {% log_level level %} - {{ message|markdown }} + {{ message|render_markdown }} {% empty %} diff --git a/netbox/templates/extras/tag.html b/netbox/templates/extras/tag.html index f127d365a..64e5bbebd 100644 --- a/netbox/templates/extras/tag.html +++ b/netbox/templates/extras/tag.html @@ -90,7 +90,7 @@
{% if tag.comments %} - {{ tag.comments|markdown }} + {{ tag.comments|render_markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/tenancy/tenant.html b/netbox/templates/tenancy/tenant.html index e5cea5705..4ef26c451 100644 --- a/netbox/templates/tenancy/tenant.html +++ b/netbox/templates/tenancy/tenant.html @@ -87,7 +87,7 @@
{% if tenant.comments %} - {{ tenant.comments|markdown }} + {{ tenant.comments|render_markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/virtualization/cluster.html b/netbox/templates/virtualization/cluster.html index 0d2b1a968..4070977bc 100644 --- a/netbox/templates/virtualization/cluster.html +++ b/netbox/templates/virtualization/cluster.html @@ -115,7 +115,7 @@
{% if cluster.comments %} - {{ cluster.comments|markdown }} + {{ cluster.comments|render_markdown }} {% else %} None {% endif %} diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index b5339f508..33dd8130a 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -152,7 +152,7 @@
{% if virtualmachine.comments %} - {{ virtualmachine.comments|markdown }} + {{ virtualmachine.comments|render_markdown }} {% else %} None {% endif %} From 15ab30d0c6bde14162b8b276c2b74035e027f5cf Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 9 Mar 2020 10:50:46 -0400 Subject: [PATCH 6/6] Replace model_name and model_name_verbose filters with meta --- netbox/templates/dcim/cable_connect.html | 2 +- netbox/templates/dcim/inc/cable_termination.html | 2 +- netbox/templates/dcim/inc/cable_trace_end.html | 2 +- netbox/templates/ipam/ipaddress_edit.html | 2 +- netbox/templates/utilities/obj_list.html | 2 +- netbox/utilities/templatetags/helpers.py | 15 ++++----------- 6 files changed, 9 insertions(+), 16 deletions(-) diff --git a/netbox/templates/dcim/cable_connect.html b/netbox/templates/dcim/cable_connect.html index aa4c4bf8c..3d9d06a1f 100644 --- a/netbox/templates/dcim/cable_connect.html +++ b/netbox/templates/dcim/cable_connect.html @@ -53,7 +53,7 @@
-

{{ termination_a|model_name|capfirst }}

+

{{ termination_a|meta:"verbose_name"|capfirst }}

diff --git a/netbox/templates/dcim/inc/cable_termination.html b/netbox/templates/dcim/inc/cable_termination.html index 48af97a0b..0711ff121 100644 --- a/netbox/templates/dcim/inc/cable_termination.html +++ b/netbox/templates/dcim/inc/cable_termination.html @@ -11,7 +11,7 @@ Type - {{ termination|model_name|capfirst }} + {{ termination|meta:"verbose_name"|capfirst }} diff --git a/netbox/templates/dcim/inc/cable_trace_end.html b/netbox/templates/dcim/inc/cable_trace_end.html index 4eab4d1d7..6073c06ee 100644 --- a/netbox/templates/dcim/inc/cable_trace_end.html +++ b/netbox/templates/dcim/inc/cable_trace_end.html @@ -17,7 +17,7 @@
{% if end.device %} {# Device component #} - {% with model=end|model_name %} + {% with model=end|meta:"verbose_name" %} {{ model|bettertitle }} {{ end }}
{% if model == 'interface' %} {{ end.get_type_display }} diff --git a/netbox/templates/ipam/ipaddress_edit.html b/netbox/templates/ipam/ipaddress_edit.html index e3f694fe3..d8902595a 100644 --- a/netbox/templates/ipam/ipaddress_edit.html +++ b/netbox/templates/ipam/ipaddress_edit.html @@ -35,7 +35,7 @@
- +

{{ obj.interface.parent }} diff --git a/netbox/templates/utilities/obj_list.html b/netbox/templates/utilities/obj_list.html index e917819c6..8f9a0563c 100644 --- a/netbox/templates/utilities/obj_list.html +++ b/netbox/templates/utilities/obj_list.html @@ -15,7 +15,7 @@ {% export_button content_type %} {% endif %}

-

{% block title %}{{ content_type.model_class|model_name_plural|bettertitle }}{% endblock %}

+

{% block title %}{{ content_type.model_class|meta:"verbose_name_plural"|bettertitle }}{% endblock %}

{% with bulk_edit_url=content_type.model_class|url_name:"bulk_edit" bulk_delete_url=content_type.model_class|url_name:"bulk_delete" %} diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index db4d59114..618641a07 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -62,19 +62,12 @@ def render_yaml(value): @register.filter() -def model_name(obj): +def meta(obj, attr): """ - Return the name of the model of the given object + Return the specified Meta attribute of a model. This is needed because Django does not permit templates + to access attributes which begin with an underscore (e.g. _meta). """ - return obj._meta.verbose_name - - -@register.filter() -def model_name_plural(obj): - """ - Return the plural name of the model of the given object - """ - return obj._meta.verbose_name_plural + return getattr(obj._meta, attr, '') @register.filter()