Remove org field from generated form
This commit is contained in:
parent
63039171c1
commit
2931315b96
1 changed files with 9 additions and 14 deletions
|
|
@ -6,7 +6,7 @@ from django.db import models
|
||||||
from django.forms.models import ModelForm, ModelFormMetaclass
|
from django.forms.models import ModelForm, ModelFormMetaclass
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from servala.core.models import ServiceInstance
|
from servala.core.models import ServiceInstance, ControlPlaneCRD
|
||||||
from servala.frontend.forms.widgets import DynamicArrayField, DynamicArrayWidget
|
from servala.frontend.forms.widgets import DynamicArrayField, DynamicArrayWidget
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ def generate_django_model(schema, group, version, kind):
|
||||||
"""
|
"""
|
||||||
# We always need these three fields to know our own name and our full namespace
|
# We always need these three fields to know our own name and our full namespace
|
||||||
model_fields = {"__module__": "crd_models"}
|
model_fields = {"__module__": "crd_models"}
|
||||||
for field_name in ("name", "organization", "context"):
|
for field_name in ("name", "context"):
|
||||||
model_fields[field_name] = duplicate_field(field_name, ServiceInstance)
|
model_fields[field_name] = duplicate_field(field_name, ServiceInstance)
|
||||||
|
|
||||||
# All other fields are generated from the schema, except for the
|
# All other fields are generated from the schema, except for the
|
||||||
|
|
@ -290,9 +290,10 @@ class FormGeneratorMixin:
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
for field in ("organization", "context"):
|
if "context" in self.fields:
|
||||||
if field in self.fields:
|
self.fields["context"].widget = forms.HiddenInput()
|
||||||
self.fields[field].widget = forms.HiddenInput()
|
if "context" in self.initial:
|
||||||
|
self.fields["context"].queryset = ControlPlaneCRD.objects.filter(pk=self.initial["context"].pk)
|
||||||
|
|
||||||
if self.instance and hasattr(self.instance, "name") and self.instance.name:
|
if self.instance and hasattr(self.instance, "name") and self.instance.name:
|
||||||
if "name" in self.fields:
|
if "name" in self.fields:
|
||||||
|
|
@ -546,7 +547,6 @@ class CustomFormMixin(FormGeneratorMixin):
|
||||||
self.fields["name"].widget = forms.HiddenInput()
|
self.fields["name"].widget = forms.HiddenInput()
|
||||||
self.fields["name"].disabled = True
|
self.fields["name"].disabled = True
|
||||||
self.fields.pop("context", None)
|
self.fields.pop("context", None)
|
||||||
self.fields.pop("organization", None)
|
|
||||||
|
|
||||||
def _apply_field_config(self):
|
def _apply_field_config(self):
|
||||||
for fieldset in self.form_config.get("fieldsets", []):
|
for fieldset in self.form_config.get("fieldsets", []):
|
||||||
|
|
@ -605,7 +605,7 @@ class CustomFormMixin(FormGeneratorMixin):
|
||||||
def get_nested_data(self):
|
def get_nested_data(self):
|
||||||
nested = {}
|
nested = {}
|
||||||
for field_name in self.fields.keys():
|
for field_name in self.fields.keys():
|
||||||
if field_name in ("organization", "context"):
|
if field_name == "context":
|
||||||
value = self.cleaned_data.get(field_name)
|
value = self.cleaned_data.get(field_name)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
nested[field_name] = value
|
nested[field_name] = value
|
||||||
|
|
@ -629,7 +629,7 @@ def generate_custom_form_class(form_config, model):
|
||||||
"""
|
"""
|
||||||
Generate a custom (user-friendly) form class from form_config JSON.
|
Generate a custom (user-friendly) form class from form_config JSON.
|
||||||
"""
|
"""
|
||||||
field_list = ["organization", "context", "name"]
|
field_list = ["context", "name"]
|
||||||
|
|
||||||
for fieldset in form_config.get("fieldsets", []):
|
for fieldset in form_config.get("fieldsets", []):
|
||||||
for field_config in fieldset.get("fields", []):
|
for field_config in fieldset.get("fields", []):
|
||||||
|
|
@ -638,13 +638,8 @@ def generate_custom_form_class(form_config, model):
|
||||||
field_list.append(field_name)
|
field_list.append(field_name)
|
||||||
|
|
||||||
fields = {
|
fields = {
|
||||||
"organization": forms.ModelChoiceField(
|
|
||||||
queryset=None,
|
|
||||||
required=True,
|
|
||||||
widget=forms.HiddenInput(),
|
|
||||||
),
|
|
||||||
"context": forms.ModelChoiceField(
|
"context": forms.ModelChoiceField(
|
||||||
queryset=None,
|
queryset=ControlPlaneCRD.objects.none(),
|
||||||
required=True,
|
required=True,
|
||||||
widget=forms.HiddenInput(),
|
widget=forms.HiddenInput(),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue