[PR #20050] [MERGED] 20048 cleanup get_viewname URL resolution #15812

Closed
opened 2025-12-30 00:24:12 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20050
Author: @arthanson
Created: 8/7/2025
Status: Merged
Merged: 8/11/2025
Merged by: @jeremystretch

Base: featureHead: 20048-viewname


📝 Commits (10+)

📊 Changes

24 files changed (+220 additions, -115 deletions)

View changed files

📝 netbox/core/api/serializers_/object_types.py (+6 -7)
📝 netbox/extras/dashboard/widgets.py (+7 -9)
📝 netbox/extras/tests/test_dashboard.py (+1 -1)
📝 netbox/extras/views.py (+3 -5)
📝 netbox/netbox/object_actions.py (+2 -4)
📝 netbox/netbox/tables/columns.py (+2 -2)
📝 netbox/netbox/tables/tables.py (+2 -4)
📝 netbox/netbox/views/generic/bulk_views.py (+3 -4)
📝 netbox/netbox/views/generic/object_views.py (+2 -3)
📝 netbox/templates/core/job/base.html (+3 -5)
📝 netbox/templates/dcim/inc/cable_termination.html (+9 -15)
📝 netbox/templates/extras/dashboard/widgets/objectlist.html (+1 -1)
📝 netbox/templates/extras/journalentry.html (+1 -1)
📝 netbox/templates/extras/object_imageattachments.html (+3 -5)
📝 netbox/templates/extras/tag.html (+12 -13)
📝 netbox/templates/generic/object.html (+1 -1)
📝 netbox/templates/htmx/quick_add.html (+1 -1)
📝 netbox/templates/inc/panels/related_objects.html (+4 -5)
📝 netbox/templates/tenancy/object_contacts.html (+3 -5)
📝 netbox/utilities/forms/fields/dynamic.py (+3 -5)

...and 4 more files

📄 Description

Fixes: #20048

adds a get_action_url to replace the get_viewname / reverse sequence in the app, and allows it to be replaceable by models that need a different URL pattern then the standard.

get_viewname is used in two filters viewname and validated_viewname which gets the viewname and then passes this to the url template tag so added in an action_url template tag (in netbox/utilities/templatetags/helpers.py) to use the get_action_url and have cleaner syntax goes from {% url object|viewname:'list' %} to {% action_url object 'list' %}. As a template tag it also supports as syntax so allows the following replacement:

{% with viewname=qs.model|validated_viewname:"list" %}
<a href="{% url viewname %}

with cleaner:

{% action_url qs.model 'list' as list_url %}
<a href="{{ list_url }}

netbox/extras/dashboard/widgets.py needed the returned context changed as viewname isn't returned anymore but the template just uses it in an error message, so just updated the error message.

NetBoxFeatureSet still uses get_viewname in the get_absolute_url function, but that is fine as any model that is overriding _get_action_url would also override get_absoulte_url as well so it doesn't need to be changed there.

NetBoxAPIHyperlinkedIdentityField and NetBoxURLHyperlinkedIdentityField also use get_viewname and there isn't a good way around that, but if needed any plugin should be able to override those as needed.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20050 **Author:** [@arthanson](https://github.com/arthanson) **Created:** 8/7/2025 **Status:** ✅ Merged **Merged:** 8/11/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `20048-viewname` --- ### 📝 Commits (10+) - [`fa262ad`](https://github.com/netbox-community/netbox/commit/fa262adc6f59e748161ae0947f1d80da4180c6df) #20048 add get_action_url utility function - [`d7e92bd`](https://github.com/netbox-community/netbox/commit/d7e92bdfb71410af801f17c66c915a4c1d3edfcb) #20048 add get_action_url utility function - [`976d20f`](https://github.com/netbox-community/netbox/commit/976d20f48c7bec4b092aeb7e2d20ce8eadb2ee43) #20048 add get_action_url utility function - [`a497572`](https://github.com/netbox-community/netbox/commit/a4975720d42647b5a5d19d615f0b09bb69db6b93) #20048 add get_action_url utility function - [`a47746d`](https://github.com/netbox-community/netbox/commit/a47746d70820fe92495501c913674b05c80c6c56) #20048 add get_action_url utility function - [`d3ef9bd`](https://github.com/netbox-community/netbox/commit/d3ef9bdf8d852e3bdd60fd999022aa6fd13c202a) #20048 action_url template tag - [`581f7e8`](https://github.com/netbox-community/netbox/commit/581f7e88a32c6430f4ad94a027e52ecbd365e0d9) #20048 action_url template tag - [`025afb6`](https://github.com/netbox-community/netbox/commit/025afb6b1c74bf9a111fa0e58bbcae9ecf4ba4bf) #20048 fix test - [`0f53bfd`](https://github.com/netbox-community/netbox/commit/0f53bfdc19f3b1691c0e055aac6c4a347cc041f9) #20048 review feedback - [`6247b33`](https://github.com/netbox-community/netbox/commit/6247b339c91b78cb4468e655011675665417a1c6) #20048 fix tags ### 📊 Changes **24 files changed** (+220 additions, -115 deletions) <details> <summary>View changed files</summary> 📝 `netbox/core/api/serializers_/object_types.py` (+6 -7) 📝 `netbox/extras/dashboard/widgets.py` (+7 -9) 📝 `netbox/extras/tests/test_dashboard.py` (+1 -1) 📝 `netbox/extras/views.py` (+3 -5) 📝 `netbox/netbox/object_actions.py` (+2 -4) 📝 `netbox/netbox/tables/columns.py` (+2 -2) 📝 `netbox/netbox/tables/tables.py` (+2 -4) 📝 `netbox/netbox/views/generic/bulk_views.py` (+3 -4) 📝 `netbox/netbox/views/generic/object_views.py` (+2 -3) 📝 `netbox/templates/core/job/base.html` (+3 -5) 📝 `netbox/templates/dcim/inc/cable_termination.html` (+9 -15) 📝 `netbox/templates/extras/dashboard/widgets/objectlist.html` (+1 -1) 📝 `netbox/templates/extras/journalentry.html` (+1 -1) 📝 `netbox/templates/extras/object_imageattachments.html` (+3 -5) 📝 `netbox/templates/extras/tag.html` (+12 -13) 📝 `netbox/templates/generic/object.html` (+1 -1) 📝 `netbox/templates/htmx/quick_add.html` (+1 -1) 📝 `netbox/templates/inc/panels/related_objects.html` (+4 -5) 📝 `netbox/templates/tenancy/object_contacts.html` (+3 -5) 📝 `netbox/utilities/forms/fields/dynamic.py` (+3 -5) _...and 4 more files_ </details> ### 📄 Description ### Fixes: #20048 adds a `get_action_url` to replace the `get_viewname` / reverse sequence in the app, and allows it to be replaceable by models that need a different URL pattern then the standard. `get_viewname` is used in two filters `viewname` and `validated_viewname` which gets the viewname and then passes this to the url template tag so added in an `action_url` template tag (in netbox/utilities/templatetags/helpers.py) to use the get_action_url and have cleaner syntax goes from `{% url object|viewname:'list' %}` to `{% action_url object 'list' %}`. As a template tag it also supports `as` syntax so allows the following replacement: ``` {% with viewname=qs.model|validated_viewname:"list" %} <a href="{% url viewname %} ``` with cleaner: ``` {% action_url qs.model 'list' as list_url %} <a href="{{ list_url }} ``` `netbox/extras/dashboard/widgets.py` needed the returned context changed as viewname isn't returned anymore but the template just uses it in an error message, so just updated the error message. NetBoxFeatureSet still uses get_viewname in the get_absolute_url function, but that is fine as any model that is overriding _get_action_url would also override get_absoulte_url as well so it doesn't need to be changed there. NetBoxAPIHyperlinkedIdentityField and NetBoxURLHyperlinkedIdentityField also use get_viewname and there isn't a good way around that, but if needed any plugin should be able to override those as needed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:24:12 +01:00
adam closed this issue 2025-12-30 00:24:12 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15812