From 228ee30d6e188e50f5717a81b3c9d185ebf2880d Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Thu, 7 Nov 2024 11:44:15 +0100 Subject: [PATCH] musician saas nextcloud/WP initial --- orchestra/contrib/musician/forms.py | 37 ++++++------------- .../templates/musician/saas_form.html | 4 +- .../templates/musician/saas_list.html | 10 ++--- orchestra/contrib/musician/views.py | 4 +- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/orchestra/contrib/musician/forms.py b/orchestra/contrib/musician/forms.py index 2bd07a03..2769367f 100644 --- a/orchestra/contrib/musician/forms.py +++ b/orchestra/contrib/musician/forms.py @@ -7,6 +7,10 @@ from django.forms.widgets import HiddenInput from django.contrib.auth.hashers import make_password +from orchestra.forms.widgets import SpanWidget +from orchestra.forms import widgets +from django.utils.safestring import mark_safe + from orchestra.contrib.domains.models import Domain, Record from orchestra.contrib.mailboxes.models import Address, Mailbox from orchestra.contrib.systemusers.models import WebappUsers, SystemUser @@ -205,15 +209,12 @@ class SystemUsersChangePasswordForm(ChangePasswordForm): fields = ("password",) model = SystemUser -from orchestra.forms.widgets import SpanWidget -from orchestra.forms import widgets -from django.utils.safestring import mark_safe -from rest_framework import serializers + 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=widgets.SpanWidget, required=False, + 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.
" @@ -232,7 +233,6 @@ class SaasUpdateForm(forms.ModelForm): self.fields['blog_id'].widget.attrs['readonly'] = True self.fields['service'].widget = HiddenInput() self.fields['data'].widget = HiddenInput() - self.fields["custom_url"].widget = HiddenInput() # asignar valor al field site_url site_domain = self.instance.get_site_domain() @@ -252,12 +252,16 @@ class SaasUpdateForm(forms.ModelForm): self.fields['data'].required = False if self.instance.service == 'nextcloud': - self.fields["email"].widget = HiddenInput() self.fields["blog_id"].widget = HiddenInput() + self.fields["custom_url"].widget = HiddenInput() + self.fields["email"].widget = HiddenInput() self.fields["email"].required = False 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) @@ -268,25 +272,6 @@ class SaasUpdateForm(forms.ModelForm): self.fields[field].initial = self.instance.data.get(field, initial) - def clean(self): - super().clean() - data = {} - # Update data fields - for field in self.declared_fields: - try: - data[field] = self.cleaned_data[field] - except KeyError: - data[field] = self.data[field] - # Keep old data fields - for field, value in self.instance.data.items(): - if field not in data: - try: - data[field] = self.cleaned_data[field] - except KeyError: - data[field] = value - self.cleaned_data['data'] = data - - class NextcloudChangePasswordForm(ChangePasswordForm): class Meta: fields = ("password",) diff --git a/orchestra/contrib/musician/templates/musician/saas_form.html b/orchestra/contrib/musician/templates/musician/saas_form.html index 64d00c14..1cb74237 100644 --- a/orchestra/contrib/musician/templates/musician/saas_form.html +++ b/orchestra/contrib/musician/templates/musician/saas_form.html @@ -31,7 +31,9 @@ {% if form.instance.pk %}
- {% trans "Change password" %} + {% if form.instance.service == 'nextcloud' %} + {% trans "Change password" %} + {% endif %} {% trans "Delete" %}
{% endif %} diff --git a/orchestra/contrib/musician/templates/musician/saas_list.html b/orchestra/contrib/musician/templates/musician/saas_list.html index dc262071..03ba92bd 100644 --- a/orchestra/contrib/musician/templates/musician/saas_list.html +++ b/orchestra/contrib/musician/templates/musician/saas_list.html @@ -19,7 +19,7 @@ {% trans "Name" %} {% trans "Status" %} {% trans "Service" %} - {% trans "Service info" %} + @@ -35,15 +35,15 @@ {{ saas.is_active|yesno }} - + {{ saas.service|capfirst }} {% trans "Open service admin panel" %} - + @@ -66,5 +66,5 @@ {% include "musician/components/table_paginator.html" %} -{% trans "New SaaS" %} + {% endblock %} diff --git a/orchestra/contrib/musician/views.py b/orchestra/contrib/musician/views.py index f3a85314..d4ad9924 100644 --- a/orchestra/contrib/musician/views.py +++ b/orchestra/contrib/musician/views.py @@ -499,10 +499,10 @@ class MailboxListView(ServiceListView): ).filter( full_address__icontains=cleaned_data["address"] ) - + if "name" in cleaned_data: qs = qs.filter(name__icontains=cleaned_data["name"]) - + return qs