Skip to content

Commit

Permalink
Merge pull request #96 from mlebreuil/develop
Browse files Browse the repository at this point in the history
v2.0.8
  • Loading branch information
mlebreuil authored Sep 3, 2023
2 parents 9473c8f + 1eb2f9a commit 55debce
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/netbox_contract/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Meta:
model = ServiceProvider
fields = ('id', 'url', 'display', 'name')

class NestedContracSerializer(WritableNestedSerializer):
class NestedContractSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:contract-detail'
)
Expand Down Expand Up @@ -50,7 +50,7 @@ class ContractSerializer(NetBoxModelSerializer):
)
#circuit= NestedCircuitSerializer(many=True, required=False)
external_partie = NestedServiceProviderSerializer(many=False)
parent = NestedContracSerializer(many=False, required=False)
parent = NestedContractSerializer(many=False, required=False)
tenant= NestedTenantSerializer(many=False, required=False)

class Meta:
Expand All @@ -66,7 +66,7 @@ class InvoiceSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:invoice-detail'
)
contracts = NestedContracSerializer(many=True, required=False)
contracts = NestedContractSerializer(many=True, required=False)

class Meta:
model = Invoice
Expand Down Expand Up @@ -95,7 +95,7 @@ class ContractAssignementSerializer(NetBoxModelSerializer):
queryset=ContentType.objects.all()
)
content_object = serializers.SerializerMethodField(read_only=True)
contract = NestedContracSerializer()
contract = NestedContractSerializer()

class Meta:
model = ContractAssignement
Expand Down
17 changes: 16 additions & 1 deletion src/netbox_contract/template_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from extras.plugins import PluginTemplateExtension
from circuits.models import Circuit
from dcim.models import Device
from virtualization.models import VirtualMachine
from .models import ContractAssignement
from . import tables

Expand Down Expand Up @@ -45,4 +46,18 @@ def full_width_page(self):
'assignements_table': assignements_table,
})

template_extensions = [ CircuitContracts, CircuitContractAssignements, DeviceContractAssignements]
class VMContractAssignements(PluginTemplateExtension):
model = 'virtualization.virtualmachine'

def full_width_page(self):
device = self.context['object']
device_type = ContentType.objects.get_for_model(VirtualMachine)
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, VMContractAssignements]
2 changes: 2 additions & 0 deletions src/netbox_contract/templates/netbox_contract/contract.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends 'generic/object.html' %}
{% load plugins %}
{% load render_table from django_tables2 %}
{% block breadcrumbs %}
{{ block.super }}
Expand Down Expand Up @@ -137,4 +138,5 @@ <h5 class="card-header">Invoices</h5>
</div>
</div>
{% endif %}
{% plugin_right_page object %}
{% endblock content %}
2 changes: 2 additions & 0 deletions src/netbox_contract/templates/netbox_contract/invoice.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends 'generic/object.html' %}
{% load plugins %}
{% load render_table from django_tables2 %}
{% block breadcrumbs %}
{{ block.super }}
Expand Down Expand Up @@ -69,4 +70,5 @@ <h5 class="card-header">Contracts</h5>
{% include 'inc/panels/comments.html' %}
</div>
</div>
{% plugin_right_page object %}
{% endblock content %}

0 comments on commit 55debce

Please sign in to comment.