musician saas nextcloud/WP initial

This commit is contained in:
Jorge Pastor 2024-11-07 11:44:15 +01:00
parent ecd273bcc3
commit 228ee30d6e
4 changed files with 21 additions and 34 deletions

View file

@ -7,6 +7,10 @@ from django.forms.widgets import HiddenInput
from django.contrib.auth.hashers import make_password 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.domains.models import Domain, Record
from orchestra.contrib.mailboxes.models import Address, Mailbox from orchestra.contrib.mailboxes.models import Address, Mailbox
from orchestra.contrib.systemusers.models import WebappUsers, SystemUser from orchestra.contrib.systemusers.models import WebappUsers, SystemUser
@ -205,15 +209,12 @@ class SystemUsersChangePasswordForm(ChangePasswordForm):
fields = ("password",) fields = ("password",)
model = SystemUser 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): class SaasUpdateForm(forms.ModelForm):
site_url = forms.CharField(label=_("Site URL"), widget=SpanWidget(), required=False) site_url = forms.CharField(label=_("Site URL"), widget=SpanWidget(), required=False)
# dos campos para wordpress # 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.")) help_text=_("ID of this blog used by WordPress, the only attribute that doesn't change."))
email = forms.EmailField(label=_("Email"), email = forms.EmailField(label=_("Email"),
help_text=_("A new user will be created if the above email address is not in the database.<br>" help_text=_("A new user will be created if the above email address is not in the database.<br>"
@ -232,7 +233,6 @@ class SaasUpdateForm(forms.ModelForm):
self.fields['blog_id'].widget.attrs['readonly'] = True self.fields['blog_id'].widget.attrs['readonly'] = True
self.fields['service'].widget = HiddenInput() self.fields['service'].widget = HiddenInput()
self.fields['data'].widget = HiddenInput() self.fields['data'].widget = HiddenInput()
self.fields["custom_url"].widget = HiddenInput()
# asignar valor al field site_url # asignar valor al field site_url
site_domain = self.instance.get_site_domain() site_domain = self.instance.get_site_domain()
@ -252,12 +252,16 @@ class SaasUpdateForm(forms.ModelForm):
self.fields['data'].required = False self.fields['data'].required = False
if self.instance.service == 'nextcloud': if self.instance.service == 'nextcloud':
self.fields["email"].widget = HiddenInput()
self.fields["blog_id"].widget = HiddenInput() self.fields["blog_id"].widget = HiddenInput()
self.fields["custom_url"].widget = HiddenInput()
self.fields["email"].widget = HiddenInput()
self.fields["email"].required = False self.fields["email"].required = False
if self.instance.service == 'wordpress': 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() admin_url = 'http://%s/wp-admin/' % self.instance.get_site_domain()
help_text = 'Admin URL: <a href="{0}">{0}</a>'.format(admin_url) help_text = 'Admin URL: <a href="{0}">{0}</a>'.format(admin_url)
self.fields['site_url'].help_text = mark_safe(help_text) 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) 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 NextcloudChangePasswordForm(ChangePasswordForm):
class Meta: class Meta:
fields = ("password",) fields = ("password",)

View file

@ -31,7 +31,9 @@
<button type="submit" class="btn btn-secondary">{% trans "Save" %}</button> <button type="submit" class="btn btn-secondary">{% trans "Save" %}</button>
{% if form.instance.pk %} {% if form.instance.pk %}
<div class="float-right"> <div class="float-right">
{% if form.instance.service == 'nextcloud' %}
<a class="btn btn-outline-warning" href="{% url 'musician:nextcloud-password' form.instance.pk %}"><i class="fas fa-key"></i> {% trans "Change password" %}</a> <a class="btn btn-outline-warning" href="{% url 'musician:nextcloud-password' form.instance.pk %}"><i class="fas fa-key"></i> {% trans "Change password" %}</a>
{% endif %}
<a class="btn btn-danger" href="{% url 'musician:saas-delete' view.kwargs.pk %}">{% trans "Delete" %}</a> <a class="btn btn-danger" href="{% url 'musician:saas-delete' view.kwargs.pk %}">{% trans "Delete" %}</a>
</div> </div>
{% endif %} {% endif %}

View file

@ -19,7 +19,7 @@
<th scope="col">{% trans "Name" %}</th> <th scope="col">{% trans "Name" %}</th>
<th scope="col">{% trans "Status" %}</th> <th scope="col">{% trans "Status" %}</th>
<th scope="col">{% trans "Service" %}</th> <th scope="col">{% trans "Service" %}</th>
<th scope="col">{% trans "Service info" %}</th> <!-- <th scope="col">{% trans "Service info" %}</th> -->
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -35,15 +35,15 @@
<span class="sr-only">{{ saas.is_active|yesno }}</span> <span class="sr-only">{{ saas.is_active|yesno }}</span>
</td> </td>
<td> <td>
<a class="btn btn-sm btn-link" href="{{ saas.manager_url }}" target="_blank" rel="noopener noreferrer" title="{% trans 'Open service admin panel' %}"> <a class="btn btn-sm btn-link" href="https://{{ saas.get_site_domain|default:'#' }}" target="_blank" rel="noopener noreferrer" title="{% trans 'Open service admin panel' %}">
<i class="fab fa-{{ saas.service }}"></i> {{ saas.service|capfirst }} <i class="fab fa-{{ saas.service }}"></i> {{ saas.service|capfirst }}
<span class="sr-only">{% trans "Open service admin panel" %}</span> <i class="fas fa-external-link-alt"></i></a> <span class="sr-only">{% trans "Open service admin panel" %}</span> <i class="fas fa-external-link-alt"></i></a>
</td> </td>
<td> <!-- <td>
{% for key, value in saas.data.items %} {% for key, value in saas.data.items %}
<label>{{ key }}:</label> <strong>{{ value }}</strong><br/> <label>{{ key }}:</label> <strong>{{ value }}</strong><br/>
{% endfor %} {% endfor %}
</td> </td> -->
<td class="text-right"> <td class="text-right">
<a class="btn btn-outline-warning" role="button" href="{% url 'musician:saas-update' saas.id %}"> <a class="btn btn-outline-warning" role="button" href="{% url 'musician:saas-update' saas.id %}">
<i class="fas fa-tools"></i></a> <i class="fas fa-tools"></i></a>
@ -66,5 +66,5 @@
{% include "musician/components/table_paginator.html" %} {% include "musician/components/table_paginator.html" %}
</table> </table>
</div> </div>
<a class="btn btn-primary mt-4 mb-4" href="#">{% trans "New SaaS" %}</a> <!-- <a class="btn btn-primary mt-4 mb-4" href="#">{% trans "New SaaS" %}</a> -->
{% endblock %} {% endblock %}