include instance id in url to support uniqueness
All checks were successful
Tests / test (push) Successful in 32s
All checks were successful
Tests / test (push) Successful in 32s
This commit is contained in:
parent
69807d034e
commit
5e279fef38
3 changed files with 25 additions and 7 deletions
|
|
@ -578,7 +578,7 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
}
|
}
|
||||||
|
|
||||||
class urls(urlman.Urls):
|
class urls(urlman.Urls):
|
||||||
base = "{self.organization.urls.instances}{self.name}/"
|
base = "{self.organization.urls.instances}{self.name}-{self.pk}/"
|
||||||
update = "{base}update/"
|
update = "{base}update/"
|
||||||
delete = "{base}delete/"
|
delete = "{base}delete/"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@
|
||||||
{% for instance in service_instances %}
|
{% for instance in service_instances %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<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>
|
class="fw-semibold text-decoration-none">{{ instance.name }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
@ -117,13 +117,13 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-group btn-group-sm" role="group">
|
<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"
|
class="btn btn-outline-primary btn-sm"
|
||||||
title="{% translate 'View Details' %}">
|
title="{% translate 'View Details' %}">
|
||||||
<i class="bi bi-eye"></i>
|
<i class="bi bi-eye"></i>
|
||||||
</a>
|
</a>
|
||||||
{% if instance.has_change_permission %}
|
{% 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"
|
class="btn btn-outline-secondary btn-sm"
|
||||||
title="{% translate 'Edit' %}">
|
title="{% translate 'Edit' %}">
|
||||||
<i class="bi bi-pencil"></i>
|
<i class="bi bi-pencil"></i>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse, Http404
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
@ -178,7 +178,7 @@ class ServiceOfferingDetailView(OrganizationViewMixin, HtmxViewMixin, DetailView
|
||||||
class ServiceInstanceMixin:
|
class ServiceInstanceMixin:
|
||||||
model = ServiceInstance
|
model = ServiceInstance
|
||||||
context_object_name = "instance"
|
context_object_name = "instance"
|
||||||
slug_field = "name"
|
pk_url_kwarg = "slug"
|
||||||
|
|
||||||
def dispatch(self, *args, **kwargs):
|
def dispatch(self, *args, **kwargs):
|
||||||
self._has_warned = False
|
self._has_warned = False
|
||||||
|
|
@ -195,7 +195,25 @@ class ServiceInstanceMixin:
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_object(self, **kwargs):
|
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:
|
if not instance.kubernetes_object and not self._has_warned:
|
||||||
messages.warning(
|
messages.warning(
|
||||||
self.request,
|
self.request,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue