Merge pull request 'include instance id in url to support uniqueness' (#221) from 220-duplicate-instance-names into main
Reviewed-on: #221
This commit is contained in:
commit
985fa1907f
3 changed files with 25 additions and 7 deletions
|
|
@ -578,7 +578,7 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
|||
}
|
||||
|
||||
class urls(urlman.Urls):
|
||||
base = "{self.organization.urls.instances}{self.name}/"
|
||||
base = "{self.organization.urls.instances}{self.name}-{self.pk}/"
|
||||
update = "{base}update/"
|
||||
delete = "{base}delete/"
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@
|
|||
{% for instance in service_instances %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url 'frontend:organization.instance' organization=object.slug slug=instance.name %}"
|
||||
<a href="{{ instance.urls.base }}"
|
||||
class="fw-semibold text-decoration-none">{{ instance.name }}</a>
|
||||
</td>
|
||||
<td>
|
||||
|
|
@ -117,13 +117,13 @@
|
|||
</td>
|
||||
<td>
|
||||
<div class="btn-group btn-group-sm" role="group">
|
||||
<a href="{% url 'frontend:organization.instance' organization=object.slug slug=instance.name %}"
|
||||
<a href="{{ instance.urls.base }}"
|
||||
class="btn btn-outline-primary btn-sm"
|
||||
title="{% translate 'View Details' %}">
|
||||
<i class="bi bi-eye"></i>
|
||||
</a>
|
||||
{% if instance.has_change_permission %}
|
||||
<a href="{% url 'frontend:organization.instance.update' organization=object.slug slug=instance.name %}"
|
||||
<a href="{{ instance.urls.update }}"
|
||||
class="btn btn-outline-secondary btn-sm"
|
||||
title="{% translate 'Edit' %}">
|
||||
<i class="bi bi-pencil"></i>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from django.contrib import messages
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse, Http404
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
|
@ -178,7 +178,7 @@ class ServiceOfferingDetailView(OrganizationViewMixin, HtmxViewMixin, DetailView
|
|||
class ServiceInstanceMixin:
|
||||
model = ServiceInstance
|
||||
context_object_name = "instance"
|
||||
slug_field = "name"
|
||||
pk_url_kwarg = "slug"
|
||||
|
||||
def dispatch(self, *args, **kwargs):
|
||||
self._has_warned = False
|
||||
|
|
@ -195,7 +195,25 @@ class ServiceInstanceMixin:
|
|||
)
|
||||
|
||||
def get_object(self, **kwargs):
|
||||
instance = super().get_object(**kwargs)
|
||||
queryset = kwargs.get("queryset") or self.get_queryset()
|
||||
|
||||
# Get the slug from URL (format: "my-instance-123")
|
||||
slug = self.kwargs.get(self.pk_url_kwarg)
|
||||
if slug is None:
|
||||
raise Http404("No slug provided in URL")
|
||||
|
||||
# Extract pk from the slug (everything after the last dash)
|
||||
try:
|
||||
pk_str = slug.rsplit("-", 1)[-1]
|
||||
pk = int(pk_str)
|
||||
except (ValueError, IndexError):
|
||||
raise Http404(f"Invalid slug format: {slug}")
|
||||
|
||||
try:
|
||||
instance = queryset.get(pk=pk)
|
||||
except ServiceInstance.DoesNotExist:
|
||||
raise Http404("Service instance not found")
|
||||
|
||||
if not instance.kubernetes_object and not self._has_warned:
|
||||
messages.warning(
|
||||
self.request,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue