mirror of
https://github.com/netbox-community/netbox.git
synced 2025-09-06 14:23:36 -06:00
#19735: Fix get_context() for ObjectAction subclasses
This commit is contained in:
parent
5df4c63f28
commit
012cf3ffbf
@ -20,10 +20,7 @@ class BulkAddComponents(ObjectAction):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_context(cls, context, obj):
|
def get_context(cls, context, obj):
|
||||||
return {
|
return {
|
||||||
'perms': context.get('perms'),
|
|
||||||
'request': context.get('request'),
|
|
||||||
'formaction': context.get('formaction'),
|
'formaction': context.get('formaction'),
|
||||||
'label': cls.label,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,13 +51,23 @@ class ObjectAction:
|
|||||||
return
|
return
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def render(cls, obj, **kwargs):
|
def get_context(cls, context, obj):
|
||||||
context = {
|
"""
|
||||||
|
Return any additional context data needed to render the button.
|
||||||
|
"""
|
||||||
|
return {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def render(cls, context, obj, **kwargs):
|
||||||
|
ctx = {
|
||||||
|
'perms': context['perms'],
|
||||||
|
'request': context['request'],
|
||||||
'url': cls.get_url(obj),
|
'url': cls.get_url(obj),
|
||||||
'label': cls.label,
|
'label': cls.label,
|
||||||
|
**cls.get_context(context, obj),
|
||||||
**kwargs,
|
**kwargs,
|
||||||
}
|
}
|
||||||
return loader.render_to_string(cls.template_name, context)
|
return loader.render_to_string(cls.template_name, ctx)
|
||||||
|
|
||||||
|
|
||||||
class AddObject(ObjectAction):
|
class AddObject(ObjectAction):
|
||||||
@ -80,13 +90,10 @@ class CloneObject(ObjectAction):
|
|||||||
template_name = 'buttons/clone.html'
|
template_name = 'buttons/clone.html'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_context(cls, context, obj):
|
def get_url(cls, obj):
|
||||||
|
url = super().get_url(obj)
|
||||||
param_string = prepare_cloned_fields(obj).urlencode()
|
param_string = prepare_cloned_fields(obj).urlencode()
|
||||||
url = f'{cls.get_url(obj)}?{param_string}' if param_string else None
|
return f'{url}?{param_string}' if param_string else None
|
||||||
return {
|
|
||||||
'url': url,
|
|
||||||
'label': cls.label,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class EditObject(ObjectAction):
|
class EditObject(ObjectAction):
|
||||||
@ -142,8 +149,6 @@ class BulkExport(ObjectAction):
|
|||||||
export_templates = ExportTemplate.objects.restrict(user, 'view').filter(object_types=object_type)
|
export_templates = ExportTemplate.objects.restrict(user, 'view').filter(object_types=object_type)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'label': cls.label,
|
|
||||||
'perms': context['perms'],
|
|
||||||
'object_type': object_type,
|
'object_type': object_type,
|
||||||
'url_params': context['request'].GET.urlencode() if context['request'].GET else '',
|
'url_params': context['request'].GET.urlencode() if context['request'].GET else '',
|
||||||
'export_templates': export_templates,
|
'export_templates': export_templates,
|
||||||
|
@ -28,10 +28,11 @@ __all__ = (
|
|||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag(takes_context=True)
|
||||||
def action_buttons(actions, obj, multi=False, **kwargs):
|
def action_buttons(context, actions, obj, multi=False, **kwargs):
|
||||||
buttons = [
|
buttons = [
|
||||||
action.render(obj, **kwargs) for action in actions if action.multi == multi
|
action.render(context, obj, **kwargs)
|
||||||
|
for action in actions if action.multi == multi
|
||||||
]
|
]
|
||||||
return mark_safe(''.join(buttons))
|
return mark_safe(''.join(buttons))
|
||||||
|
|
||||||
|
@ -19,8 +19,5 @@ class BulkAddComponents(ObjectAction):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_context(cls, context, obj):
|
def get_context(cls, context, obj):
|
||||||
return {
|
return {
|
||||||
'perms': context.get('perms'),
|
|
||||||
'request': context.get('request'),
|
|
||||||
'formaction': context.get('formaction'),
|
'formaction': context.get('formaction'),
|
||||||
'label': cls.label,
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user