From 91ee26f57ad6e61d821145ab7333faef64aefe3e Mon Sep 17 00:00:00 2001 From: Marc Lebreuil Date: Thu, 1 Jun 2023 20:36:59 +0000 Subject: [PATCH] Extend contract support to Device 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 --- pyproject.toml | 2 +- src/netbox_contract/__init__.py | 2 +- src/netbox_contract/tables.py | 34 +++++++++++++++++++++++-- src/netbox_contract/template_content.py | 19 ++++++++++++-- src/netbox_contract/views.py | 2 +- 5 files changed, 52 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3d637bb..8e7a930 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "netbox-contract" -version = "2.0.0" +version = "2.0.1" authors = [ { name="Marc Lebreuil", email="marc@famillelebreuil.net" }, ] diff --git a/src/netbox_contract/__init__.py b/src/netbox_contract/__init__.py index bdd277c..5c4d953 100644 --- a/src/netbox_contract/__init__.py +++ b/src/netbox_contract/__init__.py @@ -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 = 'marc@famillelebreuil.net' base_url = 'contracts' diff --git a/src/netbox_contract/tables.py b/src/netbox_contract/tables.py index fd20c29..ab9b899 100644 --- a/src/netbox_contract/tables.py +++ b/src/netbox_contract/tables.py @@ -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): diff --git a/src/netbox_contract/template_content.py b/src/netbox_contract/template_content.py index 00addf4..8de34c4 100644 --- a/src/netbox_contract/template_content.py +++ b/src/netbox_contract/template_content.py @@ -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 @@ -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] \ No newline at end of file +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] \ No newline at end of file diff --git a/src/netbox_contract/views.py b/src/netbox_contract/views.py index 2a79444..b0dd3a6 100644 --- a/src/netbox_contract/views.py +++ b/src/netbox_contract/views.py @@ -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 {