More code reuse
This commit is contained in:
parent
7fbb70e016
commit
58d6f583e5
3 changed files with 15 additions and 8 deletions
|
|
@ -139,13 +139,11 @@ def get_nested_data(instance):
|
||||||
"""
|
"""
|
||||||
if not instance.spec:
|
if not instance.spec:
|
||||||
return []
|
return []
|
||||||
if (
|
if instance.context and instance.context.use_custom_form:
|
||||||
instance.context
|
|
||||||
and instance.context.service_definition
|
|
||||||
and instance.context.service_definition.form_config
|
|
||||||
):
|
|
||||||
return get_form_config_fieldsets(
|
return get_form_config_fieldsets(
|
||||||
instance.spec, instance.context.service_defintion.form_config, instance.name
|
instance.spec,
|
||||||
|
instance.context.service_definition.form_config,
|
||||||
|
instance.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
return get_auto_generated_fieldsets(instance.spec)
|
return get_auto_generated_fieldsets(instance.spec)
|
||||||
|
|
|
||||||
|
|
@ -546,6 +546,14 @@ class ControlPlaneCRD(ServalaModelMixin, models.Model):
|
||||||
return
|
return
|
||||||
return generate_model_form_class(self.django_model)
|
return generate_model_form_class(self.django_model)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def use_custom_form(self):
|
||||||
|
return (
|
||||||
|
self.service_definition
|
||||||
|
and self.service_definition.form_config
|
||||||
|
and self.service_definition.form_config.get("fieldsets")
|
||||||
|
)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def custom_model_form_class(self):
|
def custom_model_form_class(self):
|
||||||
from servala.core.crd import generate_custom_form_class
|
from servala.core.crd import generate_custom_form_class
|
||||||
|
|
@ -1251,7 +1259,8 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
|
|
||||||
def calculate_pricing(self):
|
def calculate_pricing(self):
|
||||||
"""Calculate hourly and monthly pricing."""
|
"""Calculate hourly and monthly pricing."""
|
||||||
from servala.core.crd.utils import get_value_from_path, parse_disk_size_gib
|
from servala.core.crd.data import get_value_from_path
|
||||||
|
from servala.core.crd.utils import parse_disk_size_gib
|
||||||
|
|
||||||
pricing = {
|
pricing = {
|
||||||
"compute_hourly": None,
|
"compute_hourly": None,
|
||||||
|
|
|
||||||
|
|
@ -359,7 +359,7 @@ class ServiceInstanceDetailView(
|
||||||
|
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
if self.object.kubernetes_object and self.object.spec:
|
if self.object.kubernetes_object and self.object.spec:
|
||||||
context["spec_fieldsets"] = get_nested_data(self.object.spec)
|
context["spec_fieldsets"] = get_nested_data(self.object)
|
||||||
context["has_change_permission"] = self.request.user.has_perm(
|
context["has_change_permission"] = self.request.user.has_perm(
|
||||||
ServiceInstance.get_perm("change"), self.object
|
ServiceInstance.get_perm("change"), self.object
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue