Skip to content

Commit

Permalink
16546 define get_absolute_url method in NetBoxModel (#17693)
Browse files Browse the repository at this point in the history
* 16546 define get_absolute_url method in NetBoxModel

* 16546 define get_absolute_url method in NetBoxModel

* 16546 define get_absolute_url method in NetBoxModel

* 16546 move get_absolute_url to NetBoxFeatureSet

* 16546 fix CircuitTermination

* Fix linebreaks

---------

Co-authored-by: Jeremy Stretch <[email protected]>
  • Loading branch information
2 people authored and bctiemann committed Oct 16, 2024
1 parent cda9e05 commit 40fc025
Show file tree
Hide file tree
Showing 24 changed files with 4 additions and 228 deletions.
9 changes: 0 additions & 9 deletions netbox/circuits/models/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class CircuitType(OrganizationalModel):
blank=True
)

def get_absolute_url(self):
return reverse('circuits:circuittype', args=[self.pk])

class Meta:
ordering = ('name',)
verbose_name = _('circuit type')
Expand Down Expand Up @@ -140,9 +137,6 @@ class Meta:
def __str__(self):
return self.cid

def get_absolute_url(self):
return reverse('circuits:circuit', args=[self.pk])

def get_status_color(self):
return CircuitStatusChoices.colors.get(self.status)

Expand Down Expand Up @@ -173,9 +167,6 @@ class Meta:
def __str__(self):
return self.name

def get_absolute_url(self):
return reverse('circuits:circuitgroup', args=[self.pk])


class CircuitGroupAssignment(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedModel):
"""
Expand Down
9 changes: 0 additions & 9 deletions netbox/circuits/models/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ class Meta:
def __str__(self):
return self.name

def get_absolute_url(self):
return reverse('circuits:provider', args=[self.pk])


class ProviderAccount(ContactsMixin, PrimaryModel):
"""
Expand Down Expand Up @@ -91,9 +88,6 @@ def __str__(self):
return f'{self.account} ({self.name})'
return f'{self.account}'

def get_absolute_url(self):
return reverse('circuits:provideraccount', args=[self.pk])


class ProviderNetwork(PrimaryModel):
"""
Expand Down Expand Up @@ -128,6 +122,3 @@ class Meta:

def __str__(self):
return self.name

def get_absolute_url(self):
return reverse('circuits:providernetwork', args=[self.pk])
3 changes: 0 additions & 3 deletions netbox/core/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ class Meta:
def __str__(self):
return f'{self.name}'

def get_absolute_url(self):
return reverse('core:datasource', args=[self.pk])

@property
def docs_url(self):
return f'{settings.STATIC_URL}docs/models/{self._meta.app_label}/{self._meta.model_name}/'
Expand Down
3 changes: 0 additions & 3 deletions netbox/dcim/models/cables.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ def __str__(self):
pk = self.pk or self._pk
return self.label or f'#{pk}'

def get_absolute_url(self):
return reverse('dcim:cable', args=[self.pk])

@property
def a_terminations(self):
if hasattr(self, '_a_terminations'):
Expand Down
33 changes: 0 additions & 33 deletions netbox/dcim/models/device_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,6 @@ class Meta(ModularComponentModel.Meta):
verbose_name = _('console port')
verbose_name_plural = _('console ports')

def get_absolute_url(self):
return reverse('dcim:consoleport', kwargs={'pk': self.pk})


class ConsoleServerPort(ModularComponentModel, CabledObjectModel, PathEndpoint, TrackingModelMixin):
"""
Expand All @@ -329,9 +326,6 @@ class Meta(ModularComponentModel.Meta):
verbose_name = _('console server port')
verbose_name_plural = _('console server ports')

def get_absolute_url(self):
return reverse('dcim:consoleserverport', kwargs={'pk': self.pk})


#
# Power components
Expand Down Expand Up @@ -369,9 +363,6 @@ class Meta(ModularComponentModel.Meta):
verbose_name = _('power port')
verbose_name_plural = _('power ports')

def get_absolute_url(self):
return reverse('dcim:powerport', kwargs={'pk': self.pk})

def clean(self):
super().clean()

Expand Down Expand Up @@ -491,9 +482,6 @@ class Meta(ModularComponentModel.Meta):
verbose_name = _('power outlet')
verbose_name_plural = _('power outlets')

def get_absolute_url(self):
return reverse('dcim:poweroutlet', kwargs={'pk': self.pk})

def clean(self):
super().clean()

Expand Down Expand Up @@ -749,9 +737,6 @@ class Meta(ModularComponentModel.Meta):
verbose_name = _('interface')
verbose_name_plural = _('interfaces')

def get_absolute_url(self):
return reverse('dcim:interface', kwargs={'pk': self.pk})

def clean(self):
super().clean()

Expand Down Expand Up @@ -1010,9 +995,6 @@ class Meta(ModularComponentModel.Meta):
verbose_name = _('front port')
verbose_name_plural = _('front ports')

def get_absolute_url(self):
return reverse('dcim:frontport', kwargs={'pk': self.pk})

def clean(self):
super().clean()

Expand Down Expand Up @@ -1068,9 +1050,6 @@ class Meta(ModularComponentModel.Meta):
verbose_name = _('rear port')
verbose_name_plural = _('rear ports')

def get_absolute_url(self):
return reverse('dcim:rearport', kwargs={'pk': self.pk})

def clean(self):
super().clean()

Expand Down Expand Up @@ -1127,9 +1106,6 @@ class Meta(ModularComponentModel.Meta):
class MPTTMeta:
order_insertion_by = ('module',)

def get_absolute_url(self):
return reverse('dcim:modulebay', kwargs={'pk': self.pk})

def clean(self):
super().clean()

Expand Down Expand Up @@ -1168,9 +1144,6 @@ class Meta(ComponentModel.Meta):
verbose_name = _('device bay')
verbose_name_plural = _('device bays')

def get_absolute_url(self):
return reverse('dcim:devicebay', kwargs={'pk': self.pk})

def clean(self):
super().clean()

Expand Down Expand Up @@ -1214,9 +1187,6 @@ class Meta:
verbose_name = _('inventory item role')
verbose_name_plural = _('inventory item roles')

def get_absolute_url(self):
return reverse('dcim:inventoryitemrole', args=[self.pk])


class InventoryItem(MPTTModel, ComponentModel, TrackingModelMixin):
"""
Expand Down Expand Up @@ -1310,9 +1280,6 @@ class Meta:
verbose_name = _('inventory item')
verbose_name_plural = _('inventory items')

def get_absolute_url(self):
return reverse('dcim:inventoryitem', kwargs={'pk': self.pk})

def clean(self):
super().clean()

Expand Down
27 changes: 0 additions & 27 deletions netbox/dcim/models/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ class Meta:
verbose_name = _('manufacturer')
verbose_name_plural = _('manufacturers')

def get_absolute_url(self):
return reverse('dcim:manufacturer', args=[self.pk])


class DeviceType(ImageAttachmentsMixin, PrimaryModel, WeightMixin):
"""
Expand Down Expand Up @@ -217,9 +214,6 @@ def __init__(self, *args, **kwargs):
self._original_front_image = self.__dict__.get('front_image')
self._original_rear_image = self.__dict__.get('rear_image')

def get_absolute_url(self):
return reverse('dcim:devicetype', args=[self.pk])

@property
def full_name(self):
return f"{self.manufacturer} {self.model}"
Expand Down Expand Up @@ -414,9 +408,6 @@ class Meta:
def __str__(self):
return self.model

def get_absolute_url(self):
return reverse('dcim:moduletype', args=[self.pk])

@property
def full_name(self):
return f"{self.manufacturer} {self.model}"
Expand Down Expand Up @@ -497,9 +488,6 @@ class Meta:
verbose_name = _('device role')
verbose_name_plural = _('device roles')

def get_absolute_url(self):
return reverse('dcim:devicerole', args=[self.pk])


class Platform(OrganizationalModel):
"""
Expand Down Expand Up @@ -527,9 +515,6 @@ class Meta:
verbose_name = _('platform')
verbose_name_plural = _('platforms')

def get_absolute_url(self):
return reverse('dcim:platform', args=[self.pk])


def update_interface_bridges(device, interface_templates, module=None):
"""
Expand Down Expand Up @@ -823,9 +808,6 @@ def __str__(self):
return f'{self.device_type.manufacturer} {self.device_type.model} ({self.pk})'
return super().__str__()

def get_absolute_url(self):
return reverse('dcim:device', args=[self.pk])

def clean(self):
super().clean()

Expand Down Expand Up @@ -1199,9 +1181,6 @@ class Meta:
def __str__(self):
return f'{self.module_bay.name}: {self.module_type} ({self.pk})'

def get_absolute_url(self):
return reverse('dcim:module', args=[self.pk])

def get_status_color(self):
return ModuleStatusChoices.colors.get(self.status)

Expand Down Expand Up @@ -1350,9 +1329,6 @@ class Meta:
def __str__(self):
return self.name

def get_absolute_url(self):
return reverse('dcim:virtualchassis', kwargs={'pk': self.pk})

def clean(self):
super().clean()

Expand Down Expand Up @@ -1452,9 +1428,6 @@ class Meta:
def __str__(self):
return self.name

def get_absolute_url(self):
return reverse('dcim:virtualdevicecontext', kwargs={'pk': self.pk})

def get_status_color(self):
return VirtualDeviceContextStatusChoices.colors.get(self.status)

Expand Down
6 changes: 0 additions & 6 deletions netbox/dcim/models/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ class Meta:
def __str__(self):
return self.name

def get_absolute_url(self):
return reverse('dcim:powerpanel', args=[self.pk])

def clean(self):
super().clean()

Expand Down Expand Up @@ -167,9 +164,6 @@ class Meta:
def __str__(self):
return self.name

def get_absolute_url(self):
return reverse('dcim:powerfeed', args=[self.pk])

def clean(self):
super().clean()

Expand Down
12 changes: 0 additions & 12 deletions netbox/dcim/models/racks.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ class Meta:
def __str__(self):
return self.model

def get_absolute_url(self):
return reverse('dcim:racktype', args=[self.pk])

@property
def full_name(self):
return f"{self.manufacturer} {self.model}"
Expand Down Expand Up @@ -230,9 +227,6 @@ class Meta:
verbose_name = _('rack role')
verbose_name_plural = _('rack roles')

def get_absolute_url(self):
return reverse('dcim:rackrole', args=[self.pk])


class Rack(ContactsMixin, ImageAttachmentsMixin, RackBase):
"""
Expand Down Expand Up @@ -364,9 +358,6 @@ def __str__(self):
return f'{self.name} ({self.facility_id})'
return self.name

def get_absolute_url(self):
return reverse('dcim:rack', args=[self.pk])

def clean(self):
super().clean()

Expand Down Expand Up @@ -699,9 +690,6 @@ class Meta:
def __str__(self):
return "Reservation for rack {}".format(self.rack)

def get_absolute_url(self):
return reverse('dcim:rackreservation', args=[self.pk])

def clean(self):
super().clean()

Expand Down
12 changes: 0 additions & 12 deletions netbox/dcim/models/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ class Meta:
verbose_name = _('region')
verbose_name_plural = _('regions')

def get_absolute_url(self):
return reverse('dcim:region', args=[self.pk])

def get_site_count(self):
return Site.objects.filter(
Q(region=self) |
Expand Down Expand Up @@ -115,9 +112,6 @@ class Meta:
verbose_name = _('site group')
verbose_name_plural = _('site groups')

def get_absolute_url(self):
return reverse('dcim:sitegroup', args=[self.pk])

def get_site_count(self):
return Site.objects.filter(
Q(group=self) |
Expand Down Expand Up @@ -241,9 +235,6 @@ class Meta:
def __str__(self):
return self.name

def get_absolute_url(self):
return reverse('dcim:site', args=[self.pk])

def get_status_color(self):
return SiteStatusChoices.colors.get(self.status)

Expand Down Expand Up @@ -322,9 +313,6 @@ class Meta:
verbose_name = _('location')
verbose_name_plural = _('locations')

def get_absolute_url(self):
return reverse('dcim:location', args=[self.pk])

def get_status_color(self):
return LocationStatusChoices.colors.get(self.status)

Expand Down
6 changes: 0 additions & 6 deletions netbox/ipam/models/asns.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ class Meta:
def __str__(self):
return f'{self.name} ({self.range_as_string()})'

def get_absolute_url(self):
return reverse('ipam:asnrange', args=[self.pk])

@property
def range(self):
return range(self.start, self.end + 1)
Expand Down Expand Up @@ -128,9 +125,6 @@ class Meta:
def __str__(self):
return f'AS{self.asn_with_asdot}'

def get_absolute_url(self):
return reverse('ipam:asn', args=[self.pk])

@property
def asn_asdot(self):
"""
Expand Down
Loading

0 comments on commit 40fc025

Please sign in to comment.