django-orchestra/orchestra/contrib/saas/serializers.py
Jorge Pastor 53fa5a02eb inicio 2023/07/09
edited 2023/11/24 by pedro
2023-11-26 09:52:02 +00:00

29 lines
1.1 KiB
Python

from django.forms import widgets
from django.core.validators import RegexValidator
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
from orchestra.api.serializers import SetPasswordHyperlinkedSerializer
from orchestra.contrib.accounts.serializers import AccountSerializerMixin
from orchestra.core import validators
from .models import SaaS
class SaaSSerializer(AccountSerializerMixin, SetPasswordHyperlinkedSerializer):
data = serializers.DictField(required=False)
password = serializers.CharField(write_only=True, required=False,
style={'widget': widgets.PasswordInput},
validators=[
validators.validate_password,
RegexValidator(r'^[^"\'\\]+$',
_('Enter a valid password. '
'This value may contain any ascii character except for '
' \'/"/\\/ characters.'), 'invalid'),
])
class Meta:
model = SaaS
fields = ('url', 'id', 'name', 'service', 'is_active', 'data', 'password')
postonly_fields = ('name', 'service', 'password')