django-orchestra/orchestra/apps/saas/models.py

44 lines
1.5 KiB
Python
Raw Normal View History

2014-09-26 19:21:09 +00:00
from django.db import models
2014-09-26 21:24:23 +00:00
from django.utils.functional import cached_property
2014-09-26 19:21:09 +00:00
from django.utils.translation import ugettext_lazy as _
from jsonfield import JSONField
from orchestra.core import services
from .services import SoftwareService
class SaaS(models.Model):
service = models.CharField(_("service"), max_length=32,
choices=SoftwareService.get_plugin_choices())
2014-11-10 16:25:45 +00:00
# TODO use model username password instead of data
# username = models.CharField(_("username"), max_length=64, unique=True,
# help_text=_("Required. 64 characters or fewer. Letters, digits and ./-/_ only."),
# validators=[validators.RegexValidator(r'^[\w.-]+$',
# _("Enter a valid username."), 'invalid')])
# password = models.CharField(_("password"), max_length=128)
2014-11-09 10:16:07 +00:00
account = models.ForeignKey('accounts.Account', verbose_name=_("account"),
related_name='saas')
2014-09-26 19:21:09 +00:00
data = JSONField(_("data"))
class Meta:
verbose_name = "SaaS"
verbose_name_plural = "SaaS"
2014-09-26 21:24:23 +00:00
2014-09-28 12:28:57 +00:00
def __unicode__(self):
return "%s (%s)" % (self.description, self.service_class.verbose_name)
2014-09-26 21:24:23 +00:00
@cached_property
def service_class(self):
return SoftwareService.get_plugin(self.service)
@cached_property
def description(self):
return self.service_class().get_description(self.data)
2014-11-09 10:16:07 +00:00
def clean(self):
self.data = self.service_class().clean_data(self)
2014-09-26 19:21:09 +00:00
services.register(SaaS)