Skip to content

Conversation

@bctiemann
Copy link
Contributor

@bctiemann bctiemann commented Jun 30, 2025

Closes: #19793

Changes the PluginMenuItem and PluginMenuButton classes to handle an alternate pre-rendered literal url init parameter, rather than just supporting link which must be a view name suitable for {% url %}.

This allows plugin authors to supply link target URLs that might require additional (arbitrary) kwargs for resolution, rather than relying on built-in NetBox view names.

Note that Django does not provide a supported way of passing arbitrary kwargs to {% url %}; the params must be known in advance and specified explicitly (i.e. {% url 'view_name' arg1='foo' arg2='bar' %}). This prevents us from implementing this functionality in a more elegant way, i.e. being able to pass a link_kwargs dict which could then be plugged into the template directly like {% url item.link **item.link_kwargs %}.

@bctiemann bctiemann changed the base branch from main to feature June 30, 2025 18:35
@bctiemann bctiemann requested review from a team and arthanson and removed request for a team June 30, 2025 18:41
@jeremystretch
Copy link
Member

I'm not convinced we need to (or should) support arbitrary executables in place of menu items. Where dynamic iteration is needed, a plugin author can pass an arbitrary object as items within a MenuGroup, and define its __iter__() method to return whatever MenuItems are prudent.

I tested this approach with the custom objects plugin and it works well. The only blocker I ran into there was the rigid requirement for passing a static view name as a MenuItem's link. Rather than introducing a separate, conflicting url parameter maybe it would make sense to introduce a link_kwargs argument that can be passed along with link for URL resolution in the menu item.

@bctiemann bctiemann changed the base branch from feature to main July 8, 2025 19:38
@bctiemann bctiemann requested a review from jeremystretch July 8, 2025 19:46
@bctiemann bctiemann changed the title Closes: #19793 - Nav menu callables Closes: #19793 - Nav menu link customization Jul 8, 2025
jeremystretch
jeremystretch previously approved these changes Jul 14, 2025
Comment on lines 31 to 42
def __post_init__(self):
if self.link:
self._url = reverse(self.link)

@property
def url(self):
return self._url

@url.setter
def url(self, value):
self._url = value

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to move these to a base class to avoid the redundancy? It could be reused for both core and plugin nav objects.

@jeremystretch jeremystretch merged commit f5d32b1 into main Jul 14, 2025
10 checks passed
@jeremystretch jeremystretch deleted the nav-menu-callables branch July 14, 2025 14:39
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom link URLs for nav menu

3 participants