#10033 changes from code review

This commit is contained in:
Arthur 2022-08-23 16:17:40 -07:00
parent 374abe5214
commit 439cf1a308
2 changed files with 3 additions and 1 deletions

View File

@ -3,6 +3,7 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.utils.functional import cached_property
from ipam.choices import L2VPNTypeChoices from ipam.choices import L2VPNTypeChoices
from ipam.constants import L2VPN_ASSIGNMENT_MODELS from ipam.constants import L2VPN_ASSIGNMENT_MODELS
@ -67,6 +68,7 @@ class L2VPN(NetBoxModel):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('ipam:l2vpn', args=[self.pk]) return reverse('ipam:l2vpn', args=[self.pk])
@cached_property
def can_add_termination(self): def can_add_termination(self):
if self.type in L2VPNTypeChoices.P2P and self.terminations.count() >= 2: if self.type in L2VPNTypeChoices.P2P and self.terminations.count() >= 2:
return False return False

View File

@ -59,7 +59,7 @@
</div> </div>
{% if perms.ipam.add_l2vpntermination %} {% if perms.ipam.add_l2vpntermination %}
<div class="card-footer text-end noprint"> <div class="card-footer text-end noprint">
<a href="{% url 'ipam:l2vpntermination_add' %}?l2vpn={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-primary btn-sm{% if not object.can_add_termination %} disabled{% endif %}"{% if not object.can_add_termination %} aria-disabled="true"{% endif %}> <a href="{% url 'ipam:l2vpntermination_add' %}?l2vpn={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-primary btn-sm{% if not object.can_add_termination %} disabled" aria-disabled="true{% endif %}">
<i class="mdi mdi-plus-thick" aria-hidden="true"></i> Add a Termination <i class="mdi mdi-plus-thick" aria-hidden="true"></i> Add a Termination
</a> </a>
</div> </div>