django-orchestra-test/orchestra/apps/saas/services/options.py

44 lines
1.1 KiB
Python
Raw Normal View History

2014-09-26 19:21:09 +00:00
from django import forms
from django.utils.translation import ugettext_lazy as _
2014-09-26 21:24:23 +00:00
from orchestra.forms import PluginDataForm
2014-09-26 19:21:09 +00:00
from orchestra.utils import plugins
from orchestra.utils.functional import cached
from orchestra.utils.python import import_class
from .. import settings
2014-09-26 21:24:23 +00:00
class SoftwareServiceForm(PluginDataForm):
2014-09-26 19:21:09 +00:00
username = forms.CharField(label=_("Username"), max_length=64)
password = forms.CharField(label=_("Password"), max_length=64)
class Meta:
exclude = ('data', 'service')
class SoftwareService(plugins.Plugin):
2014-09-26 21:24:23 +00:00
description_field = ''
2014-09-26 19:21:09 +00:00
form = SoftwareServiceForm
serializer = None
@classmethod
@cached
def get_plugins(cls):
plugins = []
for cls in settings.SAAS_ENABLED_SERVICES:
plugins.append(import_class(cls))
return plugins
def get_form(self):
self.form.plugin = self
2014-09-26 21:24:23 +00:00
self.form.plugin_field = 'service'
2014-09-26 19:21:09 +00:00
return self.form
def get_serializer(self):
self.serializer.plugin = self
return self.serializer
2014-09-26 21:24:23 +00:00
def get_description(self, data):
return data[self.description_field]