Skip to content

Commit

Permalink
Merge pull request #112 from mlebreuil/111-assignment-spelling-is-wrong
Browse files Browse the repository at this point in the history
Correct assignment spelling. Apologize ...
  • Loading branch information
mlebreuil authored Mar 24, 2024
2 parents 4a3bca2 + daf0779 commit 43452d2
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 124 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,5 @@ Add support for Netbox 3.5 which become the minimum version supported to accomod
* [99](https://github.com/mlebreuil/netbox-contract/issues/99) list child contracts in on the parent view.
#### version 2.0.10
* [107](https://github.com/mlebreuil/netbox-contract/issues/107) Add the contacts tab to the service provider detail view.
* [111](https://github.com/mlebreuil/netbox-contract/issues/111) Correct assignment spelling.

File renamed without changes.
14 changes: 7 additions & 7 deletions src/netbox_contract/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tenancy.api.nested_serializers import NestedTenantSerializer
from utilities.api import get_serializer_for_model

from ..models import Contract, ContractAssignement, Invoice, ServiceProvider
from ..models import Contract, ContractAssignment, Invoice, ServiceProvider


class NestedServiceProviderSerializer(WritableNestedSerializer):
Expand Down Expand Up @@ -40,13 +40,13 @@ class Meta:
fields = ('id', 'url', 'display', 'number')


class NestedContractAssignementSerializer(WritableNestedSerializer):
class NestedContractAssignmentSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:ContractAssignement-detail'
view_name='plugins-api:netbox_contract-api:ContractAssignment-detail'
)

class Meta:
model = ContractAssignement
model = ContractAssignment
fields = ('id', 'url', 'display', 'contract', 'content_object')


Expand Down Expand Up @@ -137,16 +137,16 @@ class Meta:
)


class ContractAssignementSerializer(NetBoxModelSerializer):
class ContractAssignmentSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_contract-api:contractassignement-detail'
view_name='plugins-api:netbox_contract-api:contractassignment-detail'
)
content_type = ContentTypeField(queryset=ContentType.objects.all())
content_object = serializers.SerializerMethodField(read_only=True)
contract = NestedContractSerializer()

class Meta:
model = ContractAssignement
model = ContractAssignment
fields = [
'id',
'url',
Expand Down
2 changes: 1 addition & 1 deletion src/netbox_contract/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
router.register('contracts', views.ContractViewSet)
router.register('invoices', views.InvoiceViewSet)
router.register('serviceproviders', views.ServiceProviderViewSet)
router.register('contractassignement', views.ContractAssignementViewSet)
router.register('contractassignment', views.ContractAssignmentViewSet)

urlpatterns = router.urls
8 changes: 4 additions & 4 deletions src/netbox_contract/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .. import filtersets, models
from .serializers import (
ContractAssignementSerializer,
ContractAssignmentSerializer,
ContractSerializer,
InvoiceSerializer,
ServiceProviderSerializer,
Expand All @@ -25,6 +25,6 @@ class ServiceProviderViewSet(NetBoxModelViewSet):
serializer_class = ServiceProviderSerializer


class ContractAssignementViewSet(NetBoxModelViewSet):
queryset = models.ContractAssignement.objects.prefetch_related('contract', 'tags')
serializer_class = ContractAssignementSerializer
class ContractAssignmentViewSet(NetBoxModelViewSet):
queryset = models.ContractAssignment.objects.prefetch_related('contract', 'tags')
serializer_class = ContractAssignmentSerializer
6 changes: 3 additions & 3 deletions src/netbox_contract/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db.models import Q
from netbox.filtersets import NetBoxModelFilterSet

from .models import Contract, ContractAssignement, Invoice, ServiceProvider
from .models import Contract, ContractAssignment, Invoice, ServiceProvider


class ContractFilterSet(NetBoxModelFilterSet):
Expand Down Expand Up @@ -37,9 +37,9 @@ def search(self, queryset, name, value):
return queryset.filter(name__icontains=value)


class ContractAssignementFilterSet(NetBoxModelFilterSet):
class ContractAssignmentFilterSet(NetBoxModelFilterSet):
class Meta:
model = ContractAssignement
model = ContractAssignment
fields = ('id', 'contract')

def search(self, queryset, name, value):
Expand Down
16 changes: 8 additions & 8 deletions src/netbox_contract/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .constants import SERVICE_PROVIDER_MODELS
from .models import (
Contract,
ContractAssignement,
ContractAssignment,
InternalEntityChoices,
Invoice,
ServiceProvider,
Expand Down Expand Up @@ -314,27 +314,27 @@ class ServiceProviderBulkEditForm(NetBoxModelBulkEditForm):
model = ServiceProvider


# ContractAssignement
# ContractAssignment


class ContractAssignementForm(NetBoxModelForm):
class ContractAssignmentForm(NetBoxModelForm):
contract = DynamicModelChoiceField(queryset=Contract.objects.all())

class Meta:
model = ContractAssignement
model = ContractAssignment
fields = ['content_type', 'object_id', 'contract', 'tags']
widgets = {
'content_type': forms.HiddenInput(),
'object_id': forms.HiddenInput(),
}


class ContractAssignementFilterSetForm(NetBoxModelFilterSetForm):
model = ContractAssignement
class ContractAssignmentFilterSetForm(NetBoxModelFilterSetForm):
model = ContractAssignment
contract = DynamicModelChoiceField(queryset=Contract.objects.all())


class ContractAssignementImportForm(NetBoxModelImportForm):
class ContractAssignmentImportForm(NetBoxModelImportForm):
content_type = CSVContentTypeField(
queryset=ContentType.objects.all(),
help_text='Content Type in the form <app>.<model>',
Expand All @@ -344,5 +344,5 @@ class ContractAssignementImportForm(NetBoxModelImportForm):
)

class Meta:
model = ContractAssignement
model = ContractAssignment
fields = ['content_type', 'object_id', 'contract', 'tags']
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.10 on 2024-03-24 11:18

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
('extras', '0107_cachedvalue_extras_cachedvalue_object'),
('contenttypes', '0002_remove_content_type_name'),
(
'netbox_contract',
'0022_alter_contract_internal_partie_alter_contract_parent',
),
]

operations = [
migrations.RenameModel(
old_name='ContractAssignement',
new_name='ContractAssignment',
),
migrations.RenameIndex(
model_name='contractassignment',
new_name='netbox_cont_content_3bf04f_idx',
old_name='netbox_cont_content_ff787b_idx',
),
]
4 changes: 2 additions & 2 deletions src/netbox_contract/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_absolute_url(self):
return reverse('plugins:netbox_contract:serviceprovider', args=[self.pk])


class ContractAssignement(NetBoxModel):
class ContractAssignment(NetBoxModel):
content_type = models.ForeignKey(to=ContentType, on_delete=models.CASCADE)
object_id = models.PositiveBigIntegerField()
content_object = GenericForeignKey(ct_field='content_type', fk_field='object_id')
Expand All @@ -73,7 +73,7 @@ class Meta:
]

def get_absolute_url(self):
return reverse('plugins:netbox_contract:contractassignement', args=[self.pk])
return reverse('plugins:netbox_contract:contractassignment', args=[self.pk])


class Contract(NetBoxModel):
Expand Down
6 changes: 3 additions & 3 deletions src/netbox_contract/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
permissions=['netbox_contract.view_serviceprovider'],
)
contract_assignemnt_menu_item = PluginMenuItem(
link='plugins:netbox_contract:contractassignement_list',
link_text='Contract assignements',
permissions=['netbox_contract.view_contractassignement'],
link='plugins:netbox_contract:contractassignment_list',
link_text='Contract assignments',
permissions=['netbox_contract.view_contractassignment'],
)

items = (
Expand Down
14 changes: 7 additions & 7 deletions src/netbox_contract/tables.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import django_tables2 as tables
from netbox.tables import NetBoxTable, columns

from .models import Contract, ContractAssignement, Invoice, ServiceProvider
from .models import Contract, ContractAssignment, Invoice, ServiceProvider


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

class Meta(NetBoxTable.Meta):
model = ContractAssignement
model = ContractAssignment
fields = (
'pk',
'content_type',
Expand All @@ -32,13 +32,13 @@ class Meta(NetBoxTable.Meta):
)


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

class Meta(NetBoxTable.Meta):
model = ContractAssignement
model = ContractAssignment
fields = (
'pk',
'contract',
Expand All @@ -64,14 +64,14 @@ class Meta(NetBoxTable.Meta):
)


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

class Meta(NetBoxTable.Meta):
model = ContractAssignement
model = ContractAssignment
fields = (
'pk',
'content_type',
Expand Down
66 changes: 29 additions & 37 deletions src/netbox_contract/template_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,100 +5,92 @@
from virtualization.models import VirtualMachine

from . import tables
from .models import ContractAssignement
from .models import ContractAssignment


class CircuitContractAssignements(PluginTemplateExtension):
class CircuitContractAssignments(PluginTemplateExtension):
model = 'circuits.circuit'

def full_width_page(self):
circuit = self.context['object']
circuit_type = ContentType.objects.get_for_model(Circuit)
contract_assignements = ContractAssignement.objects.filter(
contract_assignments = ContractAssignment.objects.filter(
content_type__pk=circuit_type.id, object_id=circuit.id
)
assignements_table = tables.ContractAssignementObjectTable(
contract_assignements
)
assignements_table.configure(self.context['request'])
assignments_table = tables.ContractAssignmentObjectTable(contract_assignments)
assignments_table.configure(self.context['request'])

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


class DeviceContractAssignements(PluginTemplateExtension):
class DeviceContractAssignments(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(
contract_assignments = ContractAssignment.objects.filter(
content_type__pk=device_type.id, object_id=device.id
)
assignements_table = tables.ContractAssignementObjectTable(
contract_assignements
)
assignements_table.configure(self.context['request'])
assignments_table = tables.ContractAssignmentObjectTable(contract_assignments)
assignments_table.configure(self.context['request'])

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


class VMContractAssignements(PluginTemplateExtension):
class VMContractAssignments(PluginTemplateExtension):
model = 'virtualization.virtualmachine'

def full_width_page(self):
vm = self.context['object']
vm_type = ContentType.objects.get_for_model(VirtualMachine)
contract_assignements = ContractAssignement.objects.filter(
contract_assignments = ContractAssignment.objects.filter(
content_type__pk=vm_type.id, object_id=vm.id
)
assignements_table = tables.ContractAssignementObjectTable(
contract_assignements
)
assignements_table.configure(self.context['request'])
assignments_table = tables.ContractAssignmentObjectTable(contract_assignments)
assignments_table.configure(self.context['request'])

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


class SiteContractAssignements(PluginTemplateExtension):
class SiteContractAssignments(PluginTemplateExtension):
model = 'dcim.site'

def full_width_page(self):
site = self.context['object']
site_type = ContentType.objects.get_for_model(Site)
contract_assignements = ContractAssignement.objects.filter(
contract_assignments = ContractAssignment.objects.filter(
content_type__pk=site_type.id, object_id=site.id
)
assignements_table = tables.ContractAssignementObjectTable(
contract_assignements
)
assignements_table.configure(self.context['request'])
assignments_table = tables.ContractAssignmentObjectTable(contract_assignments)
assignments_table.configure(self.context['request'])

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


template_extensions = [
CircuitContractAssignements,
DeviceContractAssignements,
VMContractAssignements,
SiteContractAssignements,
CircuitContractAssignments,
DeviceContractAssignments,
VMContractAssignments,
SiteContractAssignments,
]
Loading

0 comments on commit 43452d2

Please sign in to comment.