perf: 平台创建自动化设置默认值

pull/11022/head
ibuler 2023-07-19 16:53:09 +08:00 committed by Bryan
parent 47195e2c44
commit 046342ceee
1 changed files with 18 additions and 4 deletions

View File

@ -51,8 +51,9 @@ class PlatformProtocolSerializer(serializers.ModelSerializer):
class Meta:
model = PlatformProtocol
fields = [
"id", "name", "port", "port_from_addr", "primary",
"required", "default", "public", "secret_types", "setting",
"id", "name", "port", "port_from_addr",
"primary", "required", "default", "public",
"secret_types", "setting",
]
extra_kwargs = {
"primary": {
@ -154,6 +155,18 @@ class PlatformSerializer(WritableNestedModelSerializer):
"domain_default": {"label": _('Default Domain')},
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.set_initial_value()
def set_initial_value(self):
if not hasattr(self, 'initial_data'):
return
if self.instance:
return
if not self.initial_data.get('automation'):
self.initial_data['automation'] = {}
@property
def platform_category_type(self):
if self.instance:
@ -199,8 +212,9 @@ class PlatformSerializer(WritableNestedModelSerializer):
def validate_automation(self, automation):
automation = automation or {}
automation = automation.get('ansible_enabled', False) \
and self.constraints['automation'].get('ansible_enabled', False)
ansible_enabled = automation.get('ansible_enabled', False) \
and self.constraints['automation'].get('ansible_enabled', False)
automation['ansible_enable'] = ansible_enabled
return automation