Skip to content

Commit

Permalink
Extend contract support to Device
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   pyproject.toml
	modified:   src/netbox_contract/__init__.py
	modified:   src/netbox_contract/tables.py
	modified:   src/netbox_contract/template_content.py
	modified:   src/netbox_contract/views.py
  • Loading branch information
mlebreuil committed Jun 1, 2023
1 parent d700a73 commit 91ee26f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "netbox-contract"
version = "2.0.0"
version = "2.0.1"
authors = [
{ name="Marc Lebreuil", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion src/netbox_contract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ContractsConfig(PluginConfig):
name = 'netbox_contract'
verbose_name = 'Netbox contract'
description = 'Contract management plugin for Netbox'
version = '2.0.0'
version = '2.0.1'
author = 'Marc Lebreuil'
author_email = '[email protected]'
base_url = 'contracts'
Expand Down
34 changes: 32 additions & 2 deletions src/netbox_contract/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,38 @@ class ContractAssignementListTable(NetBoxTable):

class Meta(NetBoxTable.Meta):
model = ContractAssignement
fields = ('pk', 'content_type', 'content_object', 'contract', 'actions')
default_columns = ('pk', 'content_type', 'content_object', 'contract')
fields = ('pk', 'content_type', 'content_object', 'contract','contract__external_partie', 'actions')
default_columns = ('pk', 'content_type', 'content_object', 'contract','contract__external_partie')

class ContractAssignementObjectTable(NetBoxTable):
contract = tables.Column(
linkify=True
)
actions = columns.ActionsColumn(
actions=('edit', 'delete')
)

class Meta(NetBoxTable.Meta):
model = ContractAssignement
fields = ('pk','contract','contract__external_partie','contract__status', 'actions')
default_columns = ('pk', 'contract','contract__external_partie','contract__status')

class ContractAssignementContractTable(NetBoxTable):
content_type = columns.ContentTypeColumn(
verbose_name='Object Type'
)
content_object = tables.Column(
linkify=True,
orderable=False
)
actions = columns.ActionsColumn(
actions=('edit', 'delete')
)

class Meta(NetBoxTable.Meta):
model = ContractAssignement
fields = ('pk', 'content_type', 'content_object','actions')
default_columns = ('pk', 'content_type', 'content_object')

class ContractListTable(NetBoxTable):

Expand Down
19 changes: 17 additions & 2 deletions src/netbox_contract/template_content.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.contenttypes.models import ContentType
from extras.plugins import PluginTemplateExtension
from circuits.models import Circuit
from dcim.models import Device
from .models import ContractAssignement
from . import tables

Expand All @@ -23,11 +24,25 @@ def full_width_page(self):
circuit = self.context['object']
circuit_type = ContentType.objects.get_for_model(Circuit)
contract_assignements = ContractAssignement.objects.filter(content_type__pk=circuit_type.id, object_id=circuit.id)
assignements_table = tables.ContractAssignementListTable(contract_assignements)
assignements_table = tables.ContractAssignementObjectTable(contract_assignements)
assignements_table.configure(self.context['request'])

return self.render('contract_assignements_bottom.html', extra_context={
'assignements_table': assignements_table,
})

template_extensions = [ CircuitContracts, CircuitContractAssignements]
class DeviceContractAssignements(PluginTemplateExtension):
model = 'dcim.device'

def full_width_page(self):
device = self.context['object']
device_type = ContentType.objects.get_for_model(Device)
contract_assignements = ContractAssignement.objects.filter(content_type__pk=device_type.id, object_id=device.id)
assignements_table = tables.ContractAssignementObjectTable(contract_assignements)
assignements_table.configure(self.context['request'])

return self.render('contract_assignements_bottom.html', extra_context={
'assignements_table': assignements_table,
})

template_extensions = [ CircuitContracts, CircuitContractAssignements, DeviceContractAssignements]
2 changes: 1 addition & 1 deletion src/netbox_contract/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_extra_context(self, request, instance):
invoices_table.configure(request)
circuit_table = tables.ContractCircuitListTable(instance.circuit.all())
circuit_table.configure(request)
assignements_table = tables.ContractAssignementListTable(instance.assignments.all())
assignements_table = tables.ContractAssignementContractTable(instance.assignments.all())
assignements_table.configure(request)

return {
Expand Down

0 comments on commit 91ee26f

Please sign in to comment.