mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Replace get_component_template_actions() with ButtonsColumn
This commit is contained in:
@ -130,25 +130,28 @@ class ButtonsColumn(tables.TemplateColumn):
|
||||
:param model: Model class to use for calculating URL view names
|
||||
:param prepend_content: Additional template content to render in the column (optional)
|
||||
"""
|
||||
buttons = ('changelog', 'edit', 'delete')
|
||||
attrs = {'td': {'class': 'text-right text-nowrap noprint'}}
|
||||
# Note that braces are escaped to allow for string formatting prior to template rendering
|
||||
template_code = """
|
||||
<a href="{{% url '{app_label}:{model_name}_changelog' {pk_field}=record.{pk_field} %}}" class="btn btn-default btn-xs" title="Change log">
|
||||
<i class="fa fa-history"></i>
|
||||
</a>
|
||||
{{% if perms.{app_label}.change_{model_name} %}}
|
||||
{{% if "changelog" in buttons %}}
|
||||
<a href="{{% url '{app_label}:{model_name}_changelog' {pk_field}=record.{pk_field} %}}" class="btn btn-default btn-xs" title="Change log">
|
||||
<i class="fa fa-history"></i>
|
||||
</a>
|
||||
{{% endif %}}
|
||||
{{% if "edit" in buttons and perms.{app_label}.change_{model_name} %}}
|
||||
<a href="{{% url '{app_label}:{model_name}_edit' {pk_field}=record.{pk_field} %}}?return_url={{{{ request.path }}}}" class="btn btn-xs btn-warning" title="Edit">
|
||||
<i class="fa fa-pencil"></i>
|
||||
</a>
|
||||
{{% endif %}}
|
||||
{{% if perms.{app_label}.delete_{model_name} %}}
|
||||
{{% if "delete" in buttons and perms.{app_label}.delete_{model_name} %}}
|
||||
<a href="{{% url '{app_label}:{model_name}_delete' {pk_field}=record.{pk_field} %}}?return_url={{{{ request.path }}}}" class="btn btn-xs btn-danger" title="Delete">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
{{% endif %}}
|
||||
"""
|
||||
|
||||
def __init__(self, model, *args, pk_field='pk', prepend_template=None, **kwargs):
|
||||
def __init__(self, model, *args, pk_field='pk', buttons=None, prepend_template=None, **kwargs):
|
||||
if prepend_template:
|
||||
prepend_template = prepend_template.replace('{', '{{')
|
||||
prepend_template = prepend_template.replace('}', '}}')
|
||||
@ -157,11 +160,16 @@ class ButtonsColumn(tables.TemplateColumn):
|
||||
template_code = self.template_code.format(
|
||||
app_label=model._meta.app_label,
|
||||
model_name=model._meta.model_name,
|
||||
pk_field=pk_field
|
||||
pk_field=pk_field,
|
||||
buttons=buttons
|
||||
)
|
||||
|
||||
super().__init__(template_code=template_code, *args, **kwargs)
|
||||
|
||||
self.extra_context.update({
|
||||
'buttons': buttons or self.buttons,
|
||||
})
|
||||
|
||||
def header(self):
|
||||
return ''
|
||||
|
||||
|
Reference in New Issue
Block a user