Include request object in custom link renderer on tables #8435

Closed
opened 2025-12-29 20:36:39 +01:00 by adam · 3 comments
Owner

Originally created by @cpmills1975 on GitHub (Aug 9, 2023).

Originally assigned to: @jeremystretch on GitHub.

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

Originally created by @cpmills1975 on GitHub (Aug 9, 2023). Originally assigned to: @jeremystretch on GitHub. ### 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
adam added the status: acceptedtype: feature labels 2025-12-29 20:36:39 +01:00
adam closed this issue 2025-12-29 20:36:40 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 10, 2023):

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 object:

rendered = self.customlink.render({
    'object': record,
})

Unfortunately, I'm not sure it's feasible to access the current request from within the column.

@jeremystretch commented on GitHub (Aug 10, 2023): 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: ```python # 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 `object`: ```python rendered = self.customlink.render({ 'object': record, }) ``` Unfortunately, I'm not sure it's feasible to access the current request from within the column.
Author
Owner

@kkthxbye-code commented on GitHub (Aug 17, 2023):

@jeremystretch

Unfortunately, I'm not sure it's feasible to access the current request from within the column.

We do it here:

16e2283d19/netbox/netbox/tables/columns.py (L231-L241)

Did a quick test and seems to work fine for the CustomLinkColumn, not sure if there's any downsides though.

@kkthxbye-code commented on GitHub (Aug 17, 2023): @jeremystretch > Unfortunately, I'm not sure it's feasible to access the current request from within the column. We do it here: https://github.com/netbox-community/netbox/blob/16e2283d192c9726c5010144df576baa3b16ccd7/netbox/netbox/tables/columns.py#L231-L241 Did a quick test and seems to work fine for the CustomLinkColumn, not sure if there's any downsides though.
Author
Owner

@jeremystretch commented on GitHub (Aug 21, 2023):

Thank you! I wanted to say there was a way to do it but obviously dig far enough into it.

@jeremystretch commented on GitHub (Aug 21, 2023): Thank you! I wanted to say there was a way to do it but obviously dig far enough into it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8435