musician saas nextcloud/wordpress v1
This commit is contained in:
parent
9f8e6ce9b8
commit
51f61b2a30
|
@ -1,7 +1,6 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
from orchestra.forms.widgets import SpanWidget
|
from orchestra.forms.widgets import SpanWidget
|
||||||
from orchestra.forms import widgets
|
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from orchestra.utils.python import random_ascii
|
from orchestra.utils.python import random_ascii
|
||||||
|
@ -16,13 +15,6 @@ from orchestra.contrib.musician.forms import ChangePasswordForm
|
||||||
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
|
|
||||||
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:
|
class Meta:
|
||||||
model = SaaS
|
model = SaaS
|
||||||
fields = ("is_active", "service", "name", "data", "custom_url")
|
fields = ("is_active", "service", "name", "data", "custom_url")
|
||||||
|
@ -32,8 +24,6 @@ class SaasUpdateForm(forms.ModelForm):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['name'].widget.attrs['readonly'] = True
|
self.fields['name'].widget.attrs['readonly'] = True
|
||||||
self.fields['site_url'].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['service'].widget = HiddenInput()
|
||||||
self.fields['data'].widget = HiddenInput()
|
self.fields['data'].widget = HiddenInput()
|
||||||
|
|
||||||
|
@ -54,14 +44,21 @@ class SaasUpdateForm(forms.ModelForm):
|
||||||
if self.instance.pk:
|
if self.instance.pk:
|
||||||
self.fields['data'].required = False
|
self.fields['data'].required = False
|
||||||
|
|
||||||
if self.instance.service == 'nextcloud':
|
|
||||||
self.fields["blog_id"].widget = HiddenInput()
|
class SaasWordpressUpdateForm(SaasUpdateForm):
|
||||||
self.fields["custom_url"].widget = HiddenInput()
|
blog_id = forms.IntegerField(label=("Blog ID"), widget=SpanWidget(), required=False,
|
||||||
self.fields["email"].widget = HiddenInput()
|
help_text=_("ID of this blog used by WordPress, the only attribute that doesn't change."))
|
||||||
self.fields["email"].required = False
|
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
|
||||||
|
|
||||||
|
|
||||||
if self.instance.service == 'wordpress':
|
|
||||||
self.fields["is_active"].widget = HiddenInput()
|
self.fields["is_active"].widget = HiddenInput()
|
||||||
self.fields["custom_url"].widget.attrs['readonly'] = True
|
self.fields["custom_url"].widget.attrs['readonly'] = True
|
||||||
|
|
||||||
|
@ -75,6 +72,13 @@ class SaasUpdateForm(forms.ModelForm):
|
||||||
self.fields[field].initial = self.instance.data.get(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):
|
class NextcloudChangePasswordForm(ChangePasswordForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
fields = ("password",)
|
fields = ("password",)
|
||||||
|
|
|
@ -11,19 +11,11 @@ from django.views.generic.list import ListView
|
||||||
from orchestra.contrib.musician.mixins import (CustomContextMixin, ExtendedPaginationMixin,
|
from orchestra.contrib.musician.mixins import (CustomContextMixin, ExtendedPaginationMixin,
|
||||||
UserTokenRequiredMixin)
|
UserTokenRequiredMixin)
|
||||||
|
|
||||||
from .forms import ( SaasUpdateForm, NextcloudChangePasswordForm )
|
from .forms import ( NextcloudChangePasswordForm, SaasNextcloudUpdateForm,
|
||||||
|
SaasWordpressUpdateForm )
|
||||||
from orchestra.contrib.saas.models import SaaS
|
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):
|
class SaasNextcloudListView(CustomContextMixin, UserTokenRequiredMixin, ListView):
|
||||||
model = SaaS
|
model = SaaS
|
||||||
template_name = "musician/saas_nextcloud_list.html"
|
template_name = "musician/saas_nextcloud_list.html"
|
||||||
|
@ -47,10 +39,29 @@ class SaasWordpressListView(CustomContextMixin, UserTokenRequiredMixin, ListView
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return self.model.objects.filter(account=self.request.user, service='wordpress')
|
return self.model.objects.filter(account=self.request.user, service='wordpress')
|
||||||
|
|
||||||
class SaasUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
|
|
||||||
|
class SaasWordpressUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView):
|
||||||
model = SaaS
|
model = SaaS
|
||||||
form_class = SaasUpdateForm
|
form_class = SaasWordpressUpdateForm
|
||||||
template_name = "musician/saas_form.html"
|
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):
|
def get_queryset(self):
|
||||||
qs = SaaS.objects.filter(account=self.request.user)
|
qs = SaaS.objects.filter(account=self.request.user)
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% bootstrap_form form %}
|
{% bootstrap_form form %}
|
||||||
{% buttons %}
|
{% 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>
|
<button type="submit" class="btn btn-secondary">{% trans "Save" %}</button>
|
||||||
{% endbuttons %}
|
{% endbuttons %}
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -31,9 +31,7 @@
|
||||||
<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 %}
|
|
@ -33,7 +33,7 @@
|
||||||
<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 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-nextcloud-update' saas.id %}">
|
||||||
<i class="fas fa-tools"></i></a>
|
<i class="fas fa-tools"></i></a>
|
||||||
<a class="btn btn-outline-danger" role="button" href="{% url 'musician:saas-delete' saas.id %}">
|
<a class="btn btn-outline-danger" role="button" href="{% url 'musician:saas-delete' saas.id %}">
|
||||||
<i class="text-danger fas fa-trash"></i></a>
|
<i class="text-danger fas fa-trash"></i></a>
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -8,18 +8,11 @@
|
||||||
|
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table service-list">
|
<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">
|
<thead class="thead-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<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></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -40,7 +33,7 @@
|
||||||
<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 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-wordpress-update' saas.id %}">
|
||||||
<i class="fas fa-tools"></i></a>
|
<i class="fas fa-tools"></i></a>
|
||||||
<!-- <a class="btn btn-outline-danger" role="button" href="{% url 'musician:saas-delete' saas.id %}">
|
<!-- <a class="btn btn-outline-danger" role="button" href="{% url 'musician:saas-delete' saas.id %}">
|
||||||
<i class="text-danger fas fa-trash"></i></a> -->
|
<i class="text-danger fas fa-trash"></i></a> -->
|
||||||
|
@ -61,5 +54,4 @@
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<!-- <a class="btn btn-primary mt-4 mb-4" href="#">{% trans "New User Nextcloud" %}</a> -->
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -50,12 +50,12 @@ urlpatterns = [
|
||||||
|
|
||||||
path('databases/', views.DatabaseListView.as_view(), name='database-list'),
|
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/nextcloud/', views.SaasNextcloudListView.as_view(), name='saas-nextcloud-list'),
|
||||||
path('saas/wordpress/', views.SaasWordpressListView.as_view(), name='saas-wordpress-list'),
|
path('saas/nextcloud/<int:pk>/', views.SaasNextcloudUpdateView.as_view(), name='saas-nextcloud-update'),
|
||||||
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/<int:pk>/nextcloud-change-password/', views.NextcloudChangePasswordView.as_view(), name='nextcloud-password'),
|
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('webappusers/', views.WebappUserListView.as_view(), name='webappuser-list'),
|
||||||
path('webappuser/<int:pk>/change-password/', views.WebappUserChangePasswordView.as_view(), name='webappuser-password'),
|
path('webappuser/<int:pk>/change-password/', views.WebappUserChangePasswordView.as_view(), name='webappuser-password'),
|
||||||
|
|
Loading…
Reference in New Issue