-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closes: #19793 - Nav menu link customization #19794
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
Conversation
|
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 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 |
| 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 | ||
|
|
There was a problem hiding this comment.
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.
Closes: #19793
Changes the
PluginMenuItemandPluginMenuButtonclasses to handle an alternate pre-rendered literalurlinit parameter, rather than just supportinglinkwhich 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 alink_kwargsdict which could then be plugged into the template directly like{% url item.link **item.link_kwargs %}.