jumpserver/apps/assets/serializers/account/template.py

24 lines
723 B
Python
Raw Normal View History

2022-08-24 08:36:42 +00:00
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
from assets.models import AccountTemplate
2022-09-23 10:59:19 +00:00
from .base import BaseAccountSerializer
2022-08-24 08:36:42 +00:00
2022-09-23 10:59:19 +00:00
class AccountTemplateSerializer(BaseAccountSerializer):
class Meta(BaseAccountSerializer.Meta):
2022-08-24 08:36:42 +00:00
model = AccountTemplate
@classmethod
def validate_required(cls, attrs):
2022-09-23 10:59:19 +00:00
# Todo: why ?
2022-08-24 08:36:42 +00:00
required_field_dict = {}
error = _('This field is required.')
for k, v in cls().fields.items():
if v.required and k not in attrs:
required_field_dict[k] = error
if not required_field_dict:
return
raise serializers.ValidationError(required_field_dict)