musician saas nextcloud/wordpress v1

This commit is contained in:
Jorge Pastor 2024-11-07 18:05:47 +01:00
parent 9f8e6ce9b8
commit 51f61b2a30
8 changed files with 104 additions and 58 deletions

View file

@ -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.<br>"
"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.<br>"
"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: <a href="{0}">{0}</a>'.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: <a href="{0}">{0}</a>'.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):

View file

@ -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)

View file

@ -8,7 +8,7 @@
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<a class="btn btn-light mr-2" href="{% url 'musician:saas-list' %}">{% trans "Cancel" %}</a>
<a class="btn btn-light mr-2" href="{% url 'musician:saas-nextcloud-list' %}">{% trans "Cancel" %}</a>
<button type="submit" class="btn btn-secondary">{% trans "Save" %}</button>
{% endbuttons %}
</form>

View file

@ -31,9 +31,7 @@
<button type="submit" class="btn btn-secondary">{% trans "Save" %}</button>
{% if form.instance.pk %}
<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>
{% endif %}
<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-danger" href="{% url 'musician:saas-delete' view.kwargs.pk %}">{% trans "Delete" %}</a>
</div>
{% endif %}

View file

@ -33,7 +33,7 @@
<span class="sr-only">{% trans "Open service admin panel" %}</span> <i class="fas fa-external-link-alt"></i></a>
</td>
<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-nextcloud-update' saas.id %}">
<i class="fas fa-tools"></i></a>
<a class="btn btn-outline-danger" role="button" href="{% url 'musician:saas-delete' saas.id %}">
<i class="text-danger fas fa-trash"></i></a>

View file

@ -0,0 +1,41 @@
{% extends "musician/base.html" %}
{% load bootstrap4 i18n %}
{% block content %}
<style>
.form-check{
background-color: #fff;
padding: .375rem 2.0rem;
border: 1px solid #ced4da;
border-radius: 5px;
}
</style>
<a class="btn-arrow-left" href="{% url 'musician:saas-wordpress-list' %}">{% trans "Go back" %}</a>
<h1 class="service-name">
{% if form.instance.pk %}
{% trans "Update SaaS" %} <span class="font-weight-light">{{ saas.name }}</span>
{% else %}
{% trans "Create SaaS" %}
{% endif %}
</h1>
<form method="post">
{% csrf_token %}
{% bootstrap_form form %}
<!-- TODO: ya veremos si dejamos a los socios update/delete -->
<!-- {% buttons %}
<a class="btn btn-light mr-2" href="{% url 'musician:saas-wordpress-list' %}">{% trans "Cancel" %}</a>
<button type="submit" class="btn btn-secondary">{% trans "Save" %}</button>
{% if form.instance.pk %}
<div class="float-right">
<a class="btn btn-danger" href="{% url 'musician:saas-delete' view.kwargs.pk %}">{% trans "Delete" %}</a>
</div>
{% endif %}
{% endbuttons %} -->
</form>
{% endblock %}

View file

@ -8,18 +8,11 @@
<div class="table-responsive">
<table class="table service-list">
<!-- <colgroup>
<col span="1" style="width: 35%;">
<col span="1" style="width: 10%;">
<col span="1" style="width: 25%;">
<col span="1" style="width: 30%;">
</colgroup> -->
<thead class="thead-dark">
<tr>
<th scope="col">{% trans "Name" %}</th>
<th scope="col">{% trans "Status" %}</th>
<th scope="col">{% trans "Service" %}</th>
<!-- <th scope="col">{% trans "Service info" %}</th> -->
<th></th>
</tr>
</thead>
@ -40,7 +33,7 @@
<span class="sr-only">{% trans "Open service admin panel" %}</span> <i class="fas fa-external-link-alt"></i></a>
</td>
<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-wordpress-update' saas.id %}">
<i class="fas fa-tools"></i></a>
<!-- <a class="btn btn-outline-danger" role="button" href="{% url 'musician:saas-delete' saas.id %}">
<i class="text-danger fas fa-trash"></i></a> -->
@ -61,5 +54,4 @@
</table>
</div>
<!-- <a class="btn btn-primary mt-4 mb-4" href="#">{% trans "New User Nextcloud" %}</a> -->
{% endblock %}

View file

@ -50,12 +50,12 @@ urlpatterns = [
path('databases/', views.DatabaseListView.as_view(), name='database-list'),
# path('saas/', views.SaasListView.as_view(), name='saas-list'),
path('saas/nextcloud/', views.SaasNextcloudListView.as_view(), name='saas-nextcloud-list'),
path('saas/wordpress/', views.SaasWordpressListView.as_view(), name='saas-wordpress-list'),
path('saas/<int:pk>/', views.SaasUpdateView.as_view(), name='saas-update'),
path('saas/<int:pk>/delete/', views.SaasDeleteView.as_view(), name='saas-delete'),
path('saas/nextcloud/<int:pk>/', views.SaasNextcloudUpdateView.as_view(), name='saas-nextcloud-update'),
path('saas/<int:pk>/nextcloud-change-password/', views.NextcloudChangePasswordView.as_view(), name='nextcloud-password'),
path('saas/wordpress/', views.SaasWordpressListView.as_view(), name='saas-wordpress-list'),
path('saas/wordpress/<int:pk>/', views.SaasWordpressUpdateView.as_view(), name='saas-wordpress-update'),
path('saas/<int:pk>/delete/', views.SaasDeleteView.as_view(), name='saas-delete'),
path('webappusers/', views.WebappUserListView.as_view(), name='webappuser-list'),
path('webappuser/<int:pk>/change-password/', views.WebappUserChangePasswordView.as_view(), name='webappuser-password'),