Refactor common view functionality into mixin
This commit is contained in:
parent
f464483c7a
commit
032596c0e4
1 changed files with 35 additions and 6 deletions
|
@ -159,15 +159,15 @@ class ServiceOfferingDetailView(OrganizationViewMixin, HtmxViewMixin, DetailView
|
|||
return self.render_to_response(context)
|
||||
|
||||
|
||||
class ServiceInstanceDetailView(OrganizationViewMixin, DetailView):
|
||||
"""View to display details of a specific service instance."""
|
||||
|
||||
template_name = "frontend/organizations/service_instance_detail.html"
|
||||
context_object_name = "instance"
|
||||
class ServiceInstanceMixin:
|
||||
model = ServiceInstance
|
||||
permission_type = "view"
|
||||
context_object_name = "instance"
|
||||
slug_field = "name"
|
||||
|
||||
def dispatch(self, *args, **kwargs):
|
||||
self._has_warned = False
|
||||
return super().dispatch(*args, **kwargs)
|
||||
|
||||
def get_queryset(self):
|
||||
"""Return service instance for the current organization."""
|
||||
return ServiceInstance.objects.filter(
|
||||
|
@ -178,6 +178,35 @@ class ServiceInstanceDetailView(OrganizationViewMixin, DetailView):
|
|||
"context__service_definition__service",
|
||||
)
|
||||
|
||||
def get_object(self, **kwargs):
|
||||
instance = super().get_object(**kwargs)
|
||||
if (
|
||||
not instance.kubernetes_object
|
||||
and not instance.is_deleted
|
||||
and not self._has_warned
|
||||
):
|
||||
messages.warning(
|
||||
self.request,
|
||||
_(
|
||||
"Could not retrieve instance details from Kubernetes. It might have been deleted externally."
|
||||
),
|
||||
)
|
||||
self._has_warned = True
|
||||
return instance
|
||||
|
||||
|
||||
class ServiceInstanceDetailView(
|
||||
ServiceInstanceMixin, OrganizationViewMixin, DetailView
|
||||
):
|
||||
template_name = "frontend/organizations/service_instance_detail.html"
|
||||
permission_type = "view"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
if self.object.kubernetes_object and self.object.spec:
|
||||
context["spec_fieldsets"] = self.get_nested_spec()
|
||||
return context
|
||||
|
||||
def get_nested_spec(self):
|
||||
"""
|
||||
Organize spec data into fieldsets similar to how the form does it.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue