Skip to content

20048 cleanup get_viewname URL resolution #20050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: feature
Choose a base branch
from
Open

Conversation

arthanson
Copy link
Collaborator

@arthanson arthanson commented Aug 7, 2025

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.

@arthanson arthanson changed the title DRAFT: 20048 cleanup get_viewname URL resolution 20048 cleanup get_viewname URL resolution Aug 8, 2025
@arthanson arthanson marked this pull request as ready for review August 8, 2025 17:17
@arthanson arthanson requested review from a team and jeremystretch and removed request for a team August 8, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants