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

46 lines
1.7 KiB
Python
Raw Permalink 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
from django.utils.translation import gettext_lazy as _
2015-03-23 15:36:51 +00:00
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):
2015-10-09 12:54:30 +00:00
email = forms.EmailField(label=_("Email"),
2015-09-21 10:28:49 +00:00
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."))
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-10-09 12:54:30 +00:00
class WordPressChangeForm(WordPressForm):
blog_id = forms.IntegerField(label=("Blog ID"), widget=widgets.SpanWidget, required=False,
help_text=_("ID of this blog used by WordPress, the only attribute that doesn't change."))
2015-03-23 15:36:51 +00:00
class WordPressDataSerializer(serializers.Serializer):
email = serializers.EmailField(label=_("Email"))
2015-10-09 12:54:30 +00:00
blog_id = serializers.IntegerField(label=_("Blog ID"), allow_null=True, 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
2015-10-09 12:54:30 +00:00
change_form = WordPressChangeForm
2015-03-23 15:36:51 +00:00
serializer = WordPressDataSerializer
icon = 'orchestra/icons/apps/WordPress.png'
2016-02-11 14:24:09 +00:00
change_readonly_fields = ('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