mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-26 23:27:46 -06:00
Closes #8684: Change custom link template context variable 'obj' to 'object' (backward-compatible)
This commit is contained in:
@@ -72,9 +72,9 @@ class CustomLinkForm(BootstrapMixin, forms.ModelForm):
|
||||
'link_url': forms.Textarea(attrs={'class': 'font-monospace'}),
|
||||
}
|
||||
help_texts = {
|
||||
'link_text': 'Jinja2 template code for the link text. Reference the object as <code>{{ obj }}</code>. '
|
||||
'link_text': 'Jinja2 template code for the link text. Reference the object as <code>{{ object }}</code>. '
|
||||
'Links which render as empty text will not be displayed.',
|
||||
'link_url': 'Jinja2 template code for the link URL. Reference the object as <code>{{ obj }}</code>.',
|
||||
'link_url': 'Jinja2 template code for the link URL. Reference the object as <code>{{ object }}</code>.',
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ def custom_links(context, obj):
|
||||
|
||||
# Pass select context data when rendering the CustomLink
|
||||
link_context = {
|
||||
'obj': obj,
|
||||
'object': obj,
|
||||
'obj': obj, # TODO: Remove in NetBox v3.5
|
||||
'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
|
||||
|
||||
@@ -399,7 +399,10 @@ class CustomLinkColumn(tables.Column):
|
||||
|
||||
def render(self, record):
|
||||
try:
|
||||
rendered = self.customlink.render({'obj': record})
|
||||
rendered = self.customlink.render({
|
||||
'object': record,
|
||||
'obj': record, # TODO: Remove in NetBox v3.5
|
||||
})
|
||||
if rendered:
|
||||
return mark_safe(f'<a href="{rendered["link"]}"{rendered["link_target"]}>{rendered["text"]}</a>')
|
||||
except Exception as e:
|
||||
@@ -408,7 +411,10 @@ class CustomLinkColumn(tables.Column):
|
||||
|
||||
def value(self, record):
|
||||
try:
|
||||
rendered = self.customlink.render({'obj': record})
|
||||
rendered = self.customlink.render({
|
||||
'object': record,
|
||||
'obj': record, # TODO: Remove in NetBox v3.5
|
||||
})
|
||||
if rendered:
|
||||
return rendered['link']
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user