django-orchestra/orchestra/contrib/saas/services/wordpress.py

42 lines
1.7 KiB
Python
Raw Normal View History

2015-03-23 15:36:51 +00:00
from django import forms
2015-09-21 10:28:49 +00:00
from django.utils.safestring import mark_safe
2015-03-23 15:36:51 +00:00
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
2015-10-08 13:54:39 +00:00
from orchestra.forms import widgets
2015-09-21 10:28:49 +00:00
from .options import SoftwareService
2015-09-29 12:35:22 +00:00
from .. import settings
2015-09-21 10:28:49 +00:00
from ..forms import SaaSBaseForm
2015-03-23 15:36:51 +00:00
2015-09-21 10:28:49 +00:00
class WordPressForm(SaaSBaseForm):
email = forms.EmailField(label=_("Email"), widget=forms.TextInput(attrs={'size':'40'}),
help_text=_("A new user will be created if the above email address is not in the database.<br>"
"The username and password will be mailed to this email address."))
2015-10-08 13:54:39 +00:00
blog_id = forms.IntegerField(label=("Blog ID"), widget=widgets.SpanWidget, required=False,
help_text=_("ID of this user on the GitLab server, the only attribute that not changes."))
2015-09-21 10:28:49 +00:00
def __init__(self, *args, **kwargs):
super(WordPressForm, self).__init__(*args, **kwargs)
if self.is_change:
admin_url = 'http://%s/wp-admin/' % self.instance.get_site_domain()
help_text = 'Admin URL: <a href="{0}">{0}</a>'.format(admin_url)
self.fields['site_url'].help_text = mark_safe(help_text)
2015-03-23 15:36:51 +00:00
2015-09-21 13:57:15 +00:00
2015-03-23 15:36:51 +00:00
class WordPressDataSerializer(serializers.Serializer):
email = serializers.EmailField(label=_("Email"))
2015-10-08 13:54:39 +00:00
blog_id = serializers.IntegerField(label=_("Blog ID"), required=False)
2015-03-23 15:36:51 +00:00
class WordPressService(SoftwareService):
2015-06-09 11:16:36 +00:00
name = 'wordpress'
2015-03-23 15:36:51 +00:00
verbose_name = "WordPress"
form = WordPressForm
serializer = WordPressDataSerializer
icon = 'orchestra/icons/apps/WordPress.png'
2015-10-08 13:54:39 +00:00
change_readonly_fileds = ('email', 'blog_id')
2015-09-29 12:35:22 +00:00
site_domain = settings.SAAS_WORDPRESS_DOMAIN
allow_custom_url = settings.SAAS_WORDPRESS_ALLOW_CUSTOM_URL