django-orchestra-test/orchestra/contrib/saas/serializers.py

29 lines
1.1 KiB
Python
Raw Normal View History

2015-04-23 14:34:04 +00:00
from django.forms import widgets
from django.core.validators import RegexValidator
from django.utils.translation import gettext_lazy as _
2015-04-23 14:34:04 +00:00
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
2015-04-30 09:51:55 +00:00
fields = ('url', 'id', 'name', 'service', 'is_active', 'data', 'password')
2015-04-23 14:34:04 +00:00
postonly_fields = ('name', 'service', 'password')