-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Include request object in custom link renderer on tables #13415
Comments
It seems we're missing several context variables when rendering the column. For reference, the template tag used to render custom links passes the following: # Pass select context data when rendering the CustomLink
link_context = {
'object': obj,
'debug': context.get('debug', False), # django.template.context_processors.debug
'request': context['request'], # django.template.context_processors.request
'user': context['user'], # django.contrib.auth.context_processors.auth
'perms': context['perms'], # django.contrib.auth.context_processors.auth
} Whereas the column passes only rendered = self.customlink.render({
'object': record,
}) Unfortunately, I'm not sure it's feasible to access the current request from within the column. |
We do it here: netbox/netbox/netbox/tables/columns.py Lines 231 to 241 in 16e2283
Did a quick test and seems to work fine for the CustomLinkColumn, not sure if there's any downsides though. |
Thank you! I wanted to say there was a way to do it but obviously dig far enough into it. |
NetBox version
v3.5.7
Feature type
Change to existing functionality
Proposed functionality
The custom field renderer should have access to the request object.
Use case
I'd like to record a console server 'node reference' against a console port and create a custom link that deep links me to an SSH session on that console server.
The deep link needs to look something like ssh://{{ request.user }}:{{ object.cf['node_id'] }}@consoleserver.my.domain
If I create a custom link for console ports and then view the detail page for the console port, the custom link shows up and works fine, but if I add the custom link as a column to the console ports table view, the custom link returns 'Error' as the request object is not exposed to the custom link table column renderer.
Database changes
None
External dependencies
None
The text was updated successfully, but these errors were encountered: