mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-18 13:06:30 -06:00
Replace get_component_template_actions() with ButtonsColumn
This commit is contained in:
parent
1ed152cd49
commit
f4c14d4854
@ -110,21 +110,6 @@ POWERPANEL_POWERFEED_COUNT = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def get_component_template_actions(model_name):
|
|
||||||
return """
|
|
||||||
{{% if perms.dcim.change_{model_name} %}}
|
|
||||||
<a href="{{% url 'dcim:{model_name}_edit' pk=record.pk %}}?return_url={{{{ request.path }}}}" class="btn btn-xs btn-warning">
|
|
||||||
<i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
|
|
||||||
</a>
|
|
||||||
{{% endif %}}
|
|
||||||
{{% if perms.dcim.delete_{model_name} %}}
|
|
||||||
<a href="{{% url 'dcim:{model_name}_delete' pk=record.pk %}}?return_url={{{{ request.path }}}}" class="btn btn-xs btn-danger">
|
|
||||||
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
|
|
||||||
</a>
|
|
||||||
{{% endif %}}
|
|
||||||
""".format(model_name=model_name).strip()
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Regions
|
# Regions
|
||||||
#
|
#
|
||||||
@ -401,10 +386,9 @@ class ComponentTemplateTable(BaseTable):
|
|||||||
|
|
||||||
|
|
||||||
class ConsolePortTemplateTable(ComponentTemplateTable):
|
class ConsolePortTemplateTable(ComponentTemplateTable):
|
||||||
actions = tables.TemplateColumn(
|
actions = ButtonsColumn(
|
||||||
template_code=get_component_template_actions('consoleporttemplate'),
|
model=ConsolePortTemplate,
|
||||||
attrs={'td': {'class': 'text-right noprint'}},
|
buttons=('edit', 'delete')
|
||||||
verbose_name=''
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
@ -414,10 +398,9 @@ class ConsolePortTemplateTable(ComponentTemplateTable):
|
|||||||
|
|
||||||
|
|
||||||
class ConsoleServerPortTemplateTable(ComponentTemplateTable):
|
class ConsoleServerPortTemplateTable(ComponentTemplateTable):
|
||||||
actions = tables.TemplateColumn(
|
actions = ButtonsColumn(
|
||||||
template_code=get_component_template_actions('consoleserverporttemplate'),
|
model=ConsoleServerPortTemplate,
|
||||||
attrs={'td': {'class': 'text-right noprint'}},
|
buttons=('edit', 'delete')
|
||||||
verbose_name=''
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
@ -427,10 +410,9 @@ class ConsoleServerPortTemplateTable(ComponentTemplateTable):
|
|||||||
|
|
||||||
|
|
||||||
class PowerPortTemplateTable(ComponentTemplateTable):
|
class PowerPortTemplateTable(ComponentTemplateTable):
|
||||||
actions = tables.TemplateColumn(
|
actions = ButtonsColumn(
|
||||||
template_code=get_component_template_actions('powerporttemplate'),
|
model=PowerPortTemplate,
|
||||||
attrs={'td': {'class': 'text-right noprint'}},
|
buttons=('edit', 'delete')
|
||||||
verbose_name=''
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
@ -440,10 +422,9 @@ class PowerPortTemplateTable(ComponentTemplateTable):
|
|||||||
|
|
||||||
|
|
||||||
class PowerOutletTemplateTable(ComponentTemplateTable):
|
class PowerOutletTemplateTable(ComponentTemplateTable):
|
||||||
actions = tables.TemplateColumn(
|
actions = ButtonsColumn(
|
||||||
template_code=get_component_template_actions('poweroutlettemplate'),
|
model=PowerOutletTemplate,
|
||||||
attrs={'td': {'class': 'text-right noprint'}},
|
buttons=('edit', 'delete')
|
||||||
verbose_name=''
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
@ -456,10 +437,9 @@ class InterfaceTemplateTable(ComponentTemplateTable):
|
|||||||
mgmt_only = BooleanColumn(
|
mgmt_only = BooleanColumn(
|
||||||
verbose_name='Management Only'
|
verbose_name='Management Only'
|
||||||
)
|
)
|
||||||
actions = tables.TemplateColumn(
|
actions = ButtonsColumn(
|
||||||
template_code=get_component_template_actions('interfacetemplate'),
|
model=InterfaceTemplate,
|
||||||
attrs={'td': {'class': 'text-right noprint'}},
|
buttons=('edit', 'delete')
|
||||||
verbose_name=''
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
@ -472,10 +452,9 @@ class FrontPortTemplateTable(ComponentTemplateTable):
|
|||||||
rear_port_position = tables.Column(
|
rear_port_position = tables.Column(
|
||||||
verbose_name='Position'
|
verbose_name='Position'
|
||||||
)
|
)
|
||||||
actions = tables.TemplateColumn(
|
actions = ButtonsColumn(
|
||||||
template_code=get_component_template_actions('frontporttemplate'),
|
model=FrontPortTemplate,
|
||||||
attrs={'td': {'class': 'text-right noprint'}},
|
buttons=('edit', 'delete')
|
||||||
verbose_name=''
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
@ -485,10 +464,9 @@ class FrontPortTemplateTable(ComponentTemplateTable):
|
|||||||
|
|
||||||
|
|
||||||
class RearPortTemplateTable(ComponentTemplateTable):
|
class RearPortTemplateTable(ComponentTemplateTable):
|
||||||
actions = tables.TemplateColumn(
|
actions = ButtonsColumn(
|
||||||
template_code=get_component_template_actions('rearporttemplate'),
|
model=RearPortTemplate,
|
||||||
attrs={'td': {'class': 'text-right noprint'}},
|
buttons=('edit', 'delete')
|
||||||
verbose_name=''
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
@ -498,10 +476,9 @@ class RearPortTemplateTable(ComponentTemplateTable):
|
|||||||
|
|
||||||
|
|
||||||
class DeviceBayTemplateTable(ComponentTemplateTable):
|
class DeviceBayTemplateTable(ComponentTemplateTable):
|
||||||
actions = tables.TemplateColumn(
|
actions = ButtonsColumn(
|
||||||
template_code=get_component_template_actions('devicebaytemplate'),
|
model=DeviceBayTemplate,
|
||||||
attrs={'td': {'class': 'text-right noprint'}},
|
buttons=('edit', 'delete')
|
||||||
verbose_name=''
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
|
@ -130,25 +130,28 @@ class ButtonsColumn(tables.TemplateColumn):
|
|||||||
:param model: Model class to use for calculating URL view names
|
:param model: Model class to use for calculating URL view names
|
||||||
:param prepend_content: Additional template content to render in the column (optional)
|
:param prepend_content: Additional template content to render in the column (optional)
|
||||||
"""
|
"""
|
||||||
|
buttons = ('changelog', 'edit', 'delete')
|
||||||
attrs = {'td': {'class': 'text-right text-nowrap noprint'}}
|
attrs = {'td': {'class': 'text-right text-nowrap noprint'}}
|
||||||
# Note that braces are escaped to allow for string formatting prior to template rendering
|
# Note that braces are escaped to allow for string formatting prior to template rendering
|
||||||
template_code = """
|
template_code = """
|
||||||
|
{{% 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">
|
<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>
|
<i class="fa fa-history"></i>
|
||||||
</a>
|
</a>
|
||||||
{{% if perms.{app_label}.change_{model_name} %}}
|
{{% 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">
|
<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>
|
<i class="fa fa-pencil"></i>
|
||||||
</a>
|
</a>
|
||||||
{{% endif %}}
|
{{% 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">
|
<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>
|
<i class="fa fa-trash"></i>
|
||||||
</a>
|
</a>
|
||||||
{{% endif %}}
|
{{% 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:
|
if prepend_template:
|
||||||
prepend_template = prepend_template.replace('{', '{{')
|
prepend_template = prepend_template.replace('{', '{{')
|
||||||
prepend_template = prepend_template.replace('}', '}}')
|
prepend_template = prepend_template.replace('}', '}}')
|
||||||
@ -157,11 +160,16 @@ class ButtonsColumn(tables.TemplateColumn):
|
|||||||
template_code = self.template_code.format(
|
template_code = self.template_code.format(
|
||||||
app_label=model._meta.app_label,
|
app_label=model._meta.app_label,
|
||||||
model_name=model._meta.model_name,
|
model_name=model._meta.model_name,
|
||||||
pk_field=pk_field
|
pk_field=pk_field,
|
||||||
|
buttons=buttons
|
||||||
)
|
)
|
||||||
|
|
||||||
super().__init__(template_code=template_code, *args, **kwargs)
|
super().__init__(template_code=template_code, *args, **kwargs)
|
||||||
|
|
||||||
|
self.extra_context.update({
|
||||||
|
'buttons': buttons or self.buttons,
|
||||||
|
})
|
||||||
|
|
||||||
def header(self):
|
def header(self):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user