django-orchestra/orchestra/apps/saas/services/bscw.py

54 lines
1.9 KiB
Python
Raw Normal View History

2014-09-26 19:21:09 +00:00
from django import forms
2014-11-09 10:16:07 +00:00
from django.core.exceptions import ValidationError
2014-09-26 19:21:09 +00:00
from django.utils.translation import ugettext_lazy as _
2014-11-09 10:16:07 +00:00
from rest_framework import serializers
2014-09-26 19:21:09 +00:00
2014-11-09 10:16:07 +00:00
from orchestra.core import validators
2014-09-28 12:28:57 +00:00
from orchestra.forms import PluginDataForm
2014-09-26 19:21:09 +00:00
2014-09-28 12:28:57 +00:00
from .options import SoftwareService
2014-09-26 19:21:09 +00:00
2014-09-28 12:28:57 +00:00
2014-11-09 10:16:07 +00:00
# TODO monitor quota since out of sync?
2014-09-28 12:28:57 +00:00
class BSCWForm(PluginDataForm):
username = forms.CharField(label=_("Username"), max_length=64)
2014-11-09 10:16:07 +00:00
password = forms.CharField(label=_("Password"), max_length=256, required=False)
email = forms.EmailField(label=_("Email"))
quota = forms.IntegerField(label=_("Quota"), help_text=_("Disk quota in MB."))
class SEPADirectDebitSerializer(serializers.Serializer):
username = serializers.CharField(label=_("Username"), max_length=64,
validators=[validators.validate_name])
password = serializers.CharField(label=_("Password"), max_length=256, required=False,
write_only=True)
email = serializers.EmailField(label=_("Email"))
quota = serializers.IntegerField(label=_("Quota"), help_text=_("Disk quota in MB."))
def validate(self, data):
data['username'] = data['username'].strip()
return data
2014-09-26 19:21:09 +00:00
class BSCWService(SoftwareService):
verbose_name = "BSCW"
form = BSCWForm
2014-11-09 10:16:07 +00:00
serializer = SEPADirectDebitSerializer
2014-09-26 21:24:23 +00:00
description_field = 'username'
2014-10-11 12:43:08 +00:00
icon = 'saas/icons/BSCW.png'
2014-11-09 10:16:07 +00:00
@classmethod
def clean_data(cls, saas):
try:
data = super(BSCWService, cls).clean_data(saas)
except ValidationError, error:
if not saas.pk and 'password' not in saas.data:
error.error_dict['password'] = [_("Password is required.")]
raise error
if not saas.pk and 'password' not in saas.data:
raise ValidationError({
'password': _("Password is required.")
})
return data