diff --git a/orchestra/contrib/musician/saas/forms.py b/orchestra/contrib/musician/saas/forms.py
index cb014ca6..5bf9dfb8 100644
--- a/orchestra/contrib/musician/saas/forms.py
+++ b/orchestra/contrib/musician/saas/forms.py
@@ -1,7 +1,6 @@
from django import forms
from orchestra.forms.widgets import SpanWidget
-from orchestra.forms import widgets
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from orchestra.utils.python import random_ascii
@@ -16,13 +15,6 @@ from orchestra.contrib.musician.forms import ChangePasswordForm
class SaasUpdateForm(forms.ModelForm):
site_url = forms.CharField(label=_("Site URL"), widget=SpanWidget(), required=False)
- # dos campos para wordpress
- blog_id = forms.IntegerField(label=("Blog ID"), widget=SpanWidget(), required=False,
- help_text=_("ID of this blog used by WordPress, the only attribute that doesn't change."))
- email = forms.EmailField(label=_("Email"),
- help_text=_("A new user will be created if the above email address is not in the database.
"
- "The username and password will be mailed to this email address."))
-
class Meta:
model = SaaS
fields = ("is_active", "service", "name", "data", "custom_url")
@@ -32,8 +24,6 @@ class SaasUpdateForm(forms.ModelForm):
super().__init__(*args, **kwargs)
self.fields['name'].widget.attrs['readonly'] = True
self.fields['site_url'].widget.attrs['readonly'] = True
- self.fields['email'].widget.attrs['readonly'] = True
- self.fields['blog_id'].widget.attrs['readonly'] = True
self.fields['service'].widget = HiddenInput()
self.fields['data'].widget = HiddenInput()
@@ -54,25 +44,39 @@ class SaasUpdateForm(forms.ModelForm):
if self.instance.pk:
self.fields['data'].required = False
- if self.instance.service == 'nextcloud':
- self.fields["blog_id"].widget = HiddenInput()
- self.fields["custom_url"].widget = HiddenInput()
- self.fields["email"].widget = HiddenInput()
- self.fields["email"].required = False
+
+class SaasWordpressUpdateForm(SaasUpdateForm):
+ blog_id = forms.IntegerField(label=("Blog ID"), widget=SpanWidget(), required=False,
+ help_text=_("ID of this blog used by WordPress, the only attribute that doesn't change."))
+ email = forms.EmailField(label=_("Email"),
+ help_text=_("A new user will be created if the above email address is not in the database.
"
+ "The username and password will be mailed to this email address."))
+
+ def __init__(self, *args, **kwargs):
+ # self.user = kwargs.pop('user')
+ super().__init__(*args, **kwargs)
+ self.fields['email'].widget.attrs['readonly'] = True
+ self.fields['blog_id'].widget.attrs['readonly'] = True
+
+
+ self.fields["is_active"].widget = HiddenInput()
+ self.fields["custom_url"].widget.attrs['readonly'] = True
+
+ admin_url = 'http://%s/wp-admin/' % self.instance.get_site_domain()
+ help_text = 'Admin URL: {0}'.format(admin_url)
+ self.fields['site_url'].help_text = mark_safe(help_text)
+
+ if self.instance:
+ for field in self.declared_fields:
+ initial = self.fields[field].initial
+ self.fields[field].initial = self.instance.data.get(field, initial)
- if self.instance.service == 'wordpress':
- self.fields["is_active"].widget = HiddenInput()
- self.fields["custom_url"].widget.attrs['readonly'] = True
-
- admin_url = 'http://%s/wp-admin/' % self.instance.get_site_domain()
- help_text = 'Admin URL: {0}'.format(admin_url)
- self.fields['site_url'].help_text = mark_safe(help_text)
-
- if self.instance:
- for field in self.declared_fields:
- initial = self.fields[field].initial
- self.fields[field].initial = self.instance.data.get(field, initial)
+class SaasNextcloudUpdateForm(SaasUpdateForm):
+ def __init__(self, *args, **kwargs):
+ # self.user = kwargs.pop('user')
+ super().__init__(*args, **kwargs)
+ self.fields["custom_url"].widget = HiddenInput()
class NextcloudChangePasswordForm(ChangePasswordForm):
diff --git a/orchestra/contrib/musician/saas/views.py b/orchestra/contrib/musician/saas/views.py
index da89bdf0..bc66136e 100644
--- a/orchestra/contrib/musician/saas/views.py
+++ b/orchestra/contrib/musician/saas/views.py
@@ -11,19 +11,11 @@ from django.views.generic.list import ListView
from orchestra.contrib.musician.mixins import (CustomContextMixin, ExtendedPaginationMixin,
UserTokenRequiredMixin)
-from .forms import ( SaasUpdateForm, NextcloudChangePasswordForm )
+from .forms import ( NextcloudChangePasswordForm, SaasNextcloudUpdateForm,
+ SaasWordpressUpdateForm )
from orchestra.contrib.saas.models import SaaS
-# class SaasListView(ServiceListView):
-# service_class = SaasService
-# model = SaaS
-# template_name = "musician/saas_list.html"
-# extra_context = {
-# # Translators: This message appears on the page title
-# 'title': _('Software as a Service'),
-# }
-
class SaasNextcloudListView(CustomContextMixin, UserTokenRequiredMixin, ListView):
model = SaaS
template_name = "musician/saas_nextcloud_list.html"
@@ -47,10 +39,29 @@ class SaasWordpressListView(CustomContextMixin, UserTokenRequiredMixin, ListView
def get_queryset(self):
return self.model.objects.filter(account=self.request.user, service='wordpress')
-class SaasUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
+
+class SaasWordpressUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
model = SaaS
- form_class = SaasUpdateForm
- template_name = "musician/saas_form.html"
+ form_class = SaasWordpressUpdateForm
+ template_name = "musician/saas_wordpress_form.html"
+
+ def get_queryset(self):
+ qs = SaaS.objects.filter(account=self.request.user)
+ return qs
+
+ def get_success_url(self):
+ return reverse_lazy("musician:saas-wordpress-list")
+
+ def get_form_kwargs(self):
+ kwargs = super().get_form_kwargs()
+ kwargs["user"] = self.request.user
+ return kwargs
+
+
+class SaasNextcloudUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
+ model = SaaS
+ form_class = SaasNextcloudUpdateForm
+ template_name = "musician/saas_nextcloud_form.html"
def get_queryset(self):
qs = SaaS.objects.filter(account=self.request.user)
diff --git a/orchestra/contrib/musician/templates/musician/nextcloud_change_password.html b/orchestra/contrib/musician/templates/musician/nextcloud_change_password.html
index 515ccbab..ee40c162 100644
--- a/orchestra/contrib/musician/templates/musician/nextcloud_change_password.html
+++ b/orchestra/contrib/musician/templates/musician/nextcloud_change_password.html
@@ -8,7 +8,7 @@
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
- {% trans "Cancel" %}
+ {% trans "Cancel" %}
{% endbuttons %}
diff --git a/orchestra/contrib/musician/templates/musician/saas_form.html b/orchestra/contrib/musician/templates/musician/saas_nextcloud_form.html
similarity index 81%
rename from orchestra/contrib/musician/templates/musician/saas_form.html
rename to orchestra/contrib/musician/templates/musician/saas_nextcloud_form.html
index 3f3732d2..8542a5d0 100644
--- a/orchestra/contrib/musician/templates/musician/saas_form.html
+++ b/orchestra/contrib/musician/templates/musician/saas_nextcloud_form.html
@@ -31,9 +31,7 @@
{% if form.instance.pk %}
{% trans "Name" %} | {% trans "Status" %} | {% trans "Service" %} | -- + @@ -61,5 +54,4 @@ |
---|