From 1ebf30db3352db303b885ab1d7a41e1fc45e90b5 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Sat, 18 May 2024 14:27:03 +0200 Subject: [PATCH] musician website create contents --- orchestra/contrib/musician/forms.py | 86 -------- .../musician/{ => webapps}/webapp_detail.html | 0 .../musician/{ => webapps}/webapp_form.html | 0 .../musician/{ => webapps}/webapp_list.html | 0 .../{ => webapps}/webapp_option_form.html | 0 .../webappoption_check_delete.html | 0 .../webappuser_change_password.html | 0 .../{ => webapps}/webappuser_list.html | 1 - .../website_create_option_form.html} | 4 +- .../{ => websites}/website_detail.html | 2 +- .../musician/websites/website_form.html | 31 +++ .../musician/{ => websites}/website_list.html | 23 +-- .../websiteoption_check_delete.html | 0 .../contrib/musician/tidy_forms/__init__.py | 0 .../contrib/musician/tidy_forms/webapps.py | 69 +++++++ .../contrib/musician/tidy_forms/websites.py | 61 ++++++ .../contrib/musician/tidy_views/__init__.py | 0 .../contrib/musician/tidy_views/webapps.py | 102 ++++++++++ .../contrib/musician/tidy_views/websites.py | 124 ++++++++++++ orchestra/contrib/musician/urls.py | 1 + orchestra/contrib/musician/views.py | 187 +----------------- 21 files changed, 397 insertions(+), 294 deletions(-) rename orchestra/contrib/musician/templates/musician/{ => webapps}/webapp_detail.html (100%) rename orchestra/contrib/musician/templates/musician/{ => webapps}/webapp_form.html (100%) rename orchestra/contrib/musician/templates/musician/{ => webapps}/webapp_list.html (100%) rename orchestra/contrib/musician/templates/musician/{ => webapps}/webapp_option_form.html (100%) rename orchestra/contrib/musician/templates/musician/{ => webapps}/webappoption_check_delete.html (100%) rename orchestra/contrib/musician/templates/musician/{ => webapps}/webappuser_change_password.html (100%) rename orchestra/contrib/musician/templates/musician/{ => webapps}/webappuser_list.html (94%) rename orchestra/contrib/musician/templates/musician/{website_form.html => websites/website_create_option_form.html} (75%) rename orchestra/contrib/musician/templates/musician/{ => websites}/website_detail.html (95%) create mode 100644 orchestra/contrib/musician/templates/musician/websites/website_form.html rename orchestra/contrib/musician/templates/musician/{ => websites}/website_list.html (82%) rename orchestra/contrib/musician/templates/musician/{ => websites}/websiteoption_check_delete.html (100%) create mode 100644 orchestra/contrib/musician/tidy_forms/__init__.py create mode 100644 orchestra/contrib/musician/tidy_forms/webapps.py create mode 100644 orchestra/contrib/musician/tidy_forms/websites.py create mode 100644 orchestra/contrib/musician/tidy_views/__init__.py create mode 100644 orchestra/contrib/musician/tidy_views/webapps.py create mode 100644 orchestra/contrib/musician/tidy_views/websites.py diff --git a/orchestra/contrib/musician/forms.py b/orchestra/contrib/musician/forms.py index 00d69ba3..fa7f4503 100644 --- a/orchestra/contrib/musician/forms.py +++ b/orchestra/contrib/musician/forms.py @@ -2,8 +2,6 @@ from django import forms from django.contrib.auth.forms import AuthenticationForm from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ -from django.utils.encoding import force_str -from orchestra.forms.widgets import DynamicHelpTextSelect from django.contrib.auth.hashers import make_password @@ -11,13 +9,8 @@ from orchestra.contrib.domains.models import Domain, Record from orchestra.contrib.mailboxes.models import Address, Mailbox from orchestra.contrib.systemusers.models import WebappUsers, SystemUser from orchestra.contrib.musician.validators import ValidateZoneMixin -from orchestra.contrib.webapps.models import WebApp, WebAppOption -from orchestra.contrib.webapps.options import AppOption -from orchestra.contrib.webapps.types import AppType -from orchestra.contrib.websites.models import Website from . import api -from .settings import MUSICIAN_EDIT_ENABLE_PHP_OPTIONS class LoginForm(AuthenticationForm): @@ -209,82 +202,3 @@ class SystemUsersChangePasswordForm(ChangePasswordForm): fields = ("password",) model = SystemUser - -class WebappOptionForm(forms.ModelForm): - - OPTIONS_HELP_TEXT = { - op.name: force_str(op.help_text) for op in AppOption.get_plugins() - } - - class Meta: - model = WebAppOption - fields = ("name", "value") - - def __init__(self, *args, **kwargs): - try: - self.webapp = kwargs.pop('webapp') - super().__init__(*args, **kwargs) - except: - super().__init__(*args, **kwargs) - self.webapp = self.instance.webapp - - target = 'this.id.replace("name", "value")' - self.fields['name'].widget.attrs = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT).attrs - - def save(self, commit=True): - instance = super().save(commit=False) - instance.webapp = self.webapp - if commit: - super().save(commit=True) - self.webapp.save() - return instance - - -class WebappOptionCreateForm(WebappOptionForm): - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - plugin = AppType.get(self.webapp.type) - choices = list(plugin.get_group_options_choices()) - for grupo, opciones in enumerate(choices): - if isinstance(opciones[1], list): - nueva_lista = [opc for opc in opciones[1] if opc[0] in MUSICIAN_EDIT_ENABLE_PHP_OPTIONS] - choices[grupo] = (opciones[0], nueva_lista) - self.fields['name'].widget.choices = choices - - def clean(self): - cleaned_data = super().clean() - name = self.cleaned_data.get("name") - if WebAppOption.objects.filter(webapp=self.webapp, name=name).exists(): - raise ValidationError(_("This option already exist.")) - return cleaned_data - -class WebappOptionUpdateForm(WebappOptionForm): - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.fields['name'].widget.choices = [(self.initial['name'], self.initial['name'])] - - -class WebsiteUpdateForm(forms.ModelForm): - class Meta: - model = Website - fields = ("is_active", "protocol", "domains") - help_texts = { - 'domains': _('Hold down "Control", or "Command" on a Mac, to select more than one.') - } - - def __init__(self, *args, **kwargs): - self.user = kwargs.pop('user') - super().__init__(*args, **kwargs) - # Excluir dominios de otros websites - qs = Website.objects.filter(account=self.user).exclude(id=self.instance.id) - used_domains = [] - for website in qs: - dominios = website.domains.all() - for dominio in dominios: - used_domains.append(dominio) - self.fields['domains'].queryset = Domain.objects.filter(account=self.user).exclude(name__in=used_domains) - - - diff --git a/orchestra/contrib/musician/templates/musician/webapp_detail.html b/orchestra/contrib/musician/templates/musician/webapps/webapp_detail.html similarity index 100% rename from orchestra/contrib/musician/templates/musician/webapp_detail.html rename to orchestra/contrib/musician/templates/musician/webapps/webapp_detail.html diff --git a/orchestra/contrib/musician/templates/musician/webapp_form.html b/orchestra/contrib/musician/templates/musician/webapps/webapp_form.html similarity index 100% rename from orchestra/contrib/musician/templates/musician/webapp_form.html rename to orchestra/contrib/musician/templates/musician/webapps/webapp_form.html diff --git a/orchestra/contrib/musician/templates/musician/webapp_list.html b/orchestra/contrib/musician/templates/musician/webapps/webapp_list.html similarity index 100% rename from orchestra/contrib/musician/templates/musician/webapp_list.html rename to orchestra/contrib/musician/templates/musician/webapps/webapp_list.html diff --git a/orchestra/contrib/musician/templates/musician/webapp_option_form.html b/orchestra/contrib/musician/templates/musician/webapps/webapp_option_form.html similarity index 100% rename from orchestra/contrib/musician/templates/musician/webapp_option_form.html rename to orchestra/contrib/musician/templates/musician/webapps/webapp_option_form.html diff --git a/orchestra/contrib/musician/templates/musician/webappoption_check_delete.html b/orchestra/contrib/musician/templates/musician/webapps/webappoption_check_delete.html similarity index 100% rename from orchestra/contrib/musician/templates/musician/webappoption_check_delete.html rename to orchestra/contrib/musician/templates/musician/webapps/webappoption_check_delete.html diff --git a/orchestra/contrib/musician/templates/musician/webappuser_change_password.html b/orchestra/contrib/musician/templates/musician/webapps/webappuser_change_password.html similarity index 100% rename from orchestra/contrib/musician/templates/musician/webappuser_change_password.html rename to orchestra/contrib/musician/templates/musician/webapps/webappuser_change_password.html diff --git a/orchestra/contrib/musician/templates/musician/webappuser_list.html b/orchestra/contrib/musician/templates/musician/webapps/webappuser_list.html similarity index 94% rename from orchestra/contrib/musician/templates/musician/webappuser_list.html rename to orchestra/contrib/musician/templates/musician/webapps/webappuser_list.html index bde24e3a..c2ae2713 100644 --- a/orchestra/contrib/musician/templates/musician/webappuser_list.html +++ b/orchestra/contrib/musician/templates/musician/webapps/webappuser_list.html @@ -31,7 +31,6 @@ {% endfor %} - {% include "musician/components/table_paginator.html" %} {% endblock %} diff --git a/orchestra/contrib/musician/templates/musician/website_form.html b/orchestra/contrib/musician/templates/musician/websites/website_create_option_form.html similarity index 75% rename from orchestra/contrib/musician/templates/musician/website_form.html rename to orchestra/contrib/musician/templates/musician/websites/website_create_option_form.html index 9304bc36..b72f3c4a 100644 --- a/orchestra/contrib/musician/templates/musician/website_form.html +++ b/orchestra/contrib/musician/templates/musician/websites/website_create_option_form.html @@ -7,8 +7,7 @@ {% trans "Go back" %}

- {% if form.instance.pk %}{% trans "Update Option of Website" %}{% else %}{% trans "Add Option to" %}{% endif %} - {{ website.name }} + {% trans "Add Option to" %} {{ form.website.name }}

@@ -20,4 +19,3 @@ {% endbuttons %}
{% endblock %} - diff --git a/orchestra/contrib/musician/templates/musician/website_detail.html b/orchestra/contrib/musician/templates/musician/websites/website_detail.html similarity index 95% rename from orchestra/contrib/musician/templates/musician/website_detail.html rename to orchestra/contrib/musician/templates/musician/websites/website_detail.html index 7528f242..d3c3b0ce 100644 --- a/orchestra/contrib/musician/templates/musician/website_detail.html +++ b/orchestra/contrib/musician/templates/musician/websites/website_detail.html @@ -64,7 +64,7 @@ {% endfor %} - +{% trans "Assigned new Webapp" %}

{% trans "Directives" %}

diff --git a/orchestra/contrib/musician/templates/musician/websites/website_form.html b/orchestra/contrib/musician/templates/musician/websites/website_form.html new file mode 100644 index 00000000..131a5ef1 --- /dev/null +++ b/orchestra/contrib/musician/templates/musician/websites/website_form.html @@ -0,0 +1,31 @@ +{% extends "musician/base.html" %} +{% load bootstrap4 i18n %} + + +{% block content %} + + + +{% trans "Go back" %} + +

+ {% trans "Update Option of Website" %} {{ website.name }} +

+ +
+ {% csrf_token %} + {% bootstrap_form form %} + {% buttons %} + {% trans "Cancel" %} + + {% endbuttons %} +
+{% endblock %} + diff --git a/orchestra/contrib/musician/templates/musician/website_list.html b/orchestra/contrib/musician/templates/musician/websites/website_list.html similarity index 82% rename from orchestra/contrib/musician/templates/musician/website_list.html rename to orchestra/contrib/musician/templates/musician/websites/website_list.html index 1f75a980..f8fd0724 100644 --- a/orchestra/contrib/musician/templates/musician/website_list.html +++ b/orchestra/contrib/musician/templates/musician/websites/website_list.html @@ -38,9 +38,6 @@ {{ website.is_active|yesno }} - @@ -55,7 +52,7 @@ Webapp Dir /home/{{ content.webapp.account }}/webapps/{{ content.webapp }} - + @@ -107,22 +104,4 @@ - - - {% endblock %} \ No newline at end of file diff --git a/orchestra/contrib/musician/templates/musician/websiteoption_check_delete.html b/orchestra/contrib/musician/templates/musician/websites/websiteoption_check_delete.html similarity index 100% rename from orchestra/contrib/musician/templates/musician/websiteoption_check_delete.html rename to orchestra/contrib/musician/templates/musician/websites/websiteoption_check_delete.html diff --git a/orchestra/contrib/musician/tidy_forms/__init__.py b/orchestra/contrib/musician/tidy_forms/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/orchestra/contrib/musician/tidy_forms/webapps.py b/orchestra/contrib/musician/tidy_forms/webapps.py new file mode 100644 index 00000000..a6e64b19 --- /dev/null +++ b/orchestra/contrib/musician/tidy_forms/webapps.py @@ -0,0 +1,69 @@ +from django import forms +from orchestra.forms.widgets import DynamicHelpTextSelect + +from django.core.exceptions import ValidationError +from django.utils.translation import gettext_lazy as _ +from django.utils.encoding import force_str + +from orchestra.contrib.webapps.models import WebApp, WebAppOption +from orchestra.contrib.webapps.options import AppOption +from orchestra.contrib.webapps.types import AppType + +from orchestra.contrib.musician.settings import MUSICIAN_EDIT_ENABLE_PHP_OPTIONS + + + +class WebappOptionForm(forms.ModelForm): + + OPTIONS_HELP_TEXT = { + op.name: force_str(op.help_text) for op in AppOption.get_plugins() + } + + class Meta: + model = WebAppOption + fields = ("name", "value") + + def __init__(self, *args, **kwargs): + try: + self.webapp = kwargs.pop('webapp') + super().__init__(*args, **kwargs) + except: + super().__init__(*args, **kwargs) + self.webapp = self.instance.webapp + + target = 'this.id.replace("name", "value")' + self.fields['name'].widget.attrs = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT).attrs + + def save(self, commit=True): + instance = super().save(commit=False) + instance.webapp = self.webapp + if commit: + super().save(commit=True) + self.webapp.save() + return instance + + +class WebappOptionCreateForm(WebappOptionForm): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + plugin = AppType.get(self.webapp.type) + choices = list(plugin.get_group_options_choices()) + for grupo, opciones in enumerate(choices): + if isinstance(opciones[1], list): + nueva_lista = [opc for opc in opciones[1] if opc[0] in MUSICIAN_EDIT_ENABLE_PHP_OPTIONS] + choices[grupo] = (opciones[0], nueva_lista) + self.fields['name'].widget.choices = choices + + def clean(self): + cleaned_data = super().clean() + name = self.cleaned_data.get("name") + if WebAppOption.objects.filter(webapp=self.webapp, name=name).exists(): + raise ValidationError(_("This option already exist.")) + return cleaned_data + +class WebappOptionUpdateForm(WebappOptionForm): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['name'].widget.choices = [(self.initial['name'], self.initial['name'])] diff --git a/orchestra/contrib/musician/tidy_forms/websites.py b/orchestra/contrib/musician/tidy_forms/websites.py new file mode 100644 index 00000000..d1cd2ef5 --- /dev/null +++ b/orchestra/contrib/musician/tidy_forms/websites.py @@ -0,0 +1,61 @@ +from django import forms +from orchestra.forms.widgets import DynamicHelpTextSelect + +from django.core.exceptions import ValidationError +from django.utils.translation import gettext_lazy as _ + +from orchestra.contrib.websites.models import Website, Content, WebsiteDirective +from orchestra.contrib.webapps.models import WebApp +from orchestra.contrib.domains.models import Domain + + + +class WebsiteUpdateForm(forms.ModelForm): + class Meta: + model = Website + fields = ("is_active", "protocol", "domains") + help_texts = { + 'domains': _('Hold down "Control", or "Command" on a Mac, to select more than one.') + } + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop('user') + super().__init__(*args, **kwargs) + # Excluir dominios de otros websites + qs = Website.objects.filter(account=self.user).exclude(id=self.instance.id) + used_domains = [] + for website in qs: + dominios = website.domains.all() + for dominio in dominios: + used_domains.append(dominio) + self.fields['domains'].queryset = Domain.objects.filter(account=self.user).exclude(name__in=used_domains) + + +class WesiteContentCreateForm(forms.ModelForm): + + class Meta: + model = Content + fields = ("webapp", "path") + + def __init__(self, *args, **kwargs): + self.website = kwargs.pop('website') + self.user = kwargs.pop('user') + super().__init__(*args, **kwargs) + self.fields['webapp'].queryset = WebApp.objects.filter(account=self.user, target_server=self.website.target_server) + + def clean(self): + cleaned_data = super().clean() + path = self.cleaned_data.get("path") + path = "/" if path == "" else path + print(f"mypath: {path}") + if Content.objects.filter(website=self.website, path=path).exists(): + self.add_error('path',_("This Path already exists on this Website.")) + return cleaned_data + + def save(self, commit=True): + instance = super().save(commit=False) + instance.website = self.website + if commit: + super().save(commit=True) + self.website.save() + return instance \ No newline at end of file diff --git a/orchestra/contrib/musician/tidy_views/__init__.py b/orchestra/contrib/musician/tidy_views/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/orchestra/contrib/musician/tidy_views/webapps.py b/orchestra/contrib/musician/tidy_views/webapps.py new file mode 100644 index 00000000..f54e14de --- /dev/null +++ b/orchestra/contrib/musician/tidy_views/webapps.py @@ -0,0 +1,102 @@ +from django.utils.translation import gettext_lazy as _ +from django.shortcuts import get_object_or_404 +from django.urls import reverse_lazy + +from django.views.generic.detail import DetailView +from django.views.generic.edit import CreateView, DeleteView, UpdateView +from django.views.generic.list import ListView + +from orchestra.contrib.musician.mixins import (CustomContextMixin, ExtendedPaginationMixin, + UserTokenRequiredMixin) + +from orchestra.contrib.webapps.models import WebApp, WebAppOption +from orchestra.contrib.musician.tidy_forms.webapps import WebappOptionCreateForm, WebappOptionUpdateForm + +from orchestra.contrib.musician.settings import MUSICIAN_EDIT_ENABLE_PHP_OPTIONS + + + + +class WebappListView(CustomContextMixin, UserTokenRequiredMixin, ListView): + model = WebApp + template_name = "musician/webapps/webapp_list.html" + extra_context = { + # Translators: This message appears on the page title + 'title': _('Webapps'), + } + + def get_queryset(self): + return self.model.objects.filter(account=self.request.user) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context.update({ + 'description': _("A web app is the directory where your website is stored. Through SFTP, you can access this directory and upload/edit/delete files."), + 'description2': _("Each Webapp has its own SFTP user, which is created automatically when the Webapp is created.") + }) + return context + + +class WebappDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView): + template_name = "musician/webapps/webapp_detail.html" + extra_context = { + # Translators: This message appears on the page title + 'title': _('webapp details'), + } + + def get_queryset(self): + return WebApp.objects.filter(account=self.request.user) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context.update({ + 'edit_allowed_PHP_options': MUSICIAN_EDIT_ENABLE_PHP_OPTIONS + }) + return context + + +class WebappAddOptionView(CustomContextMixin, UserTokenRequiredMixin, CreateView): + model = WebAppOption + form_class = WebappOptionCreateForm + template_name = "musician/webapps/webapp_option_form.html" + + def get_form_kwargs(self): + kwargs = super().get_form_kwargs() + webapp = get_object_or_404(WebApp, account=self.request.user, pk=self.kwargs["pk"]) + kwargs['webapp'] = webapp + return kwargs + + def get_success_url(self): + return reverse_lazy("musician:webapp-detail", kwargs={"pk": self.kwargs["pk"]}) + +class WebappDeleteOptionView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): + model = WebAppOption + template_name = "musician/webapps/webappoption_check_delete.html" + pk_url_kwarg = "option_pk" + + def get_queryset(self): + qs = WebAppOption.objects.filter(webapp__account=self.request.user, webapp=self.kwargs["pk"]) + return qs + + def get_success_url(self): + return reverse_lazy("musician:webapp-detail", kwargs={"pk": self.kwargs["pk"]}) + + def delete(self, request, *args, **kwargs): + object = self.get_object() + response = super().delete(request, *args, **kwargs) + object.webapp.save() + return response + + +class WebappUpdateOptionView(CustomContextMixin, UserTokenRequiredMixin, UpdateView): + model = WebAppOption + form_class = WebappOptionUpdateForm + template_name = "musician/webapps/webapp_option_form.html" + pk_url_kwarg = "option_pk" + + def get_queryset(self): + qs = WebAppOption.objects.filter(webapp__account=self.request.user, webapp=self.kwargs["pk"]) + return qs + + def get_success_url(self): + return reverse_lazy("musician:webapp-detail", kwargs={"pk": self.kwargs["pk"]}) diff --git a/orchestra/contrib/musician/tidy_views/websites.py b/orchestra/contrib/musician/tidy_views/websites.py new file mode 100644 index 00000000..e0de6e0b --- /dev/null +++ b/orchestra/contrib/musician/tidy_views/websites.py @@ -0,0 +1,124 @@ +from django.utils.translation import gettext_lazy as _ +from django.shortcuts import get_object_or_404 +from django.urls import reverse_lazy + +from django.views.generic.base import RedirectView, TemplateView +from django.views.generic.detail import DetailView +from django.views.generic.edit import (CreateView, DeleteView, FormView, + UpdateView) +from django.views.generic.list import ListView + +from orchestra.contrib.musician.mixins import (CustomContextMixin, ExtendedPaginationMixin, + UserTokenRequiredMixin) + +from orchestra.contrib.websites.models import Website, Content, WebsiteDirective +from orchestra.contrib.musician.tidy_forms.websites import WebsiteUpdateForm, WesiteContentCreateForm + + +class WebsiteListView(CustomContextMixin, UserTokenRequiredMixin, ListView): + model = Website + template_name = "musician/websites/website_list.html" + extra_context = { + # Translators: This message appears on the page title + 'title': _('Websites'), + } + + def get_queryset(self): + return self.model.objects.filter(account=self.request.user) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context.update({ + 'description': _("A website is the place where a domain is associated with the directory where the web files are located. (WebApp)"), + }) + return context + + +class WebsiteDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView): + template_name = "musician/websites/website_detail.html" + extra_context = { + # Translators: This message appears on the page title + 'title': _('website details'), + } + + def get_queryset(self): + return Website.objects.filter(account=self.request.user) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['content'] = Content.objects.filter(website=self.object) + context['directives'] = WebsiteDirective.objects.filter(website=self.object) + return context + + +class WebsiteUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView): + model = Website + form_class = WebsiteUpdateForm + template_name = "musician/websites/website_form.html" + + def get_queryset(self): + qs = Website.objects.filter(account=self.request.user) + return qs + + def get_success_url(self): + return reverse_lazy("musician:website-detail", kwargs={"pk": self.kwargs["pk"]}) + + def get_form_kwargs(self): + kwargs = super().get_form_kwargs() + kwargs["user"] = self.request.user + return kwargs + + +class WebsiteDeleteContentView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): + model = Content + template_name = "musician/websites/websiteoption_check_delete.html" + pk_url_kwarg = "content_pk" + + def get_queryset(self): + qs = Content.objects.filter(website__account=self.request.user, website=self.kwargs["pk"]) + return qs + + def get_success_url(self): + return reverse_lazy("musician:website-detail", kwargs={"pk": self.kwargs["pk"]}) + + def delete(self, request, *args, **kwargs): + object = self.get_object() + response = super().delete(request, *args, **kwargs) + object.website.save() + return response + + +class WebsiteDeleteDirectiveView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): + model = WebsiteDirective + template_name = "musician/websites/websiteoption_check_delete.html" + pk_url_kwarg = "directive_pk" + + def get_queryset(self): + qs = WebsiteDirective.objects.filter(website__account=self.request.user, website=self.kwargs["pk"]) + return qs + + def get_success_url(self): + return reverse_lazy("musician:website-detail", kwargs={"pk": self.kwargs["pk"]}) + + def delete(self, request, *args, **kwargs): + object = self.get_object() + response = super().delete(request, *args, **kwargs) + object.website.save() + return response + + +class WebsiteAddContentView(CustomContextMixin, UserTokenRequiredMixin, CreateView): + model = Content + form_class = WesiteContentCreateForm + template_name = "musician/websites/website_create_option_form.html" + + def get_form_kwargs(self): + kwargs = super().get_form_kwargs() + website = get_object_or_404(Website, account=self.request.user, pk=self.kwargs["pk"]) + kwargs['website'] = website + kwargs["user"] = self.request.user + return kwargs + + def get_success_url(self): + return reverse_lazy("musician:website-detail", kwargs={"pk": self.kwargs["pk"]}) + \ No newline at end of file diff --git a/orchestra/contrib/musician/urls.py b/orchestra/contrib/musician/urls.py index 2604b715..75950373 100644 --- a/orchestra/contrib/musician/urls.py +++ b/orchestra/contrib/musician/urls.py @@ -48,6 +48,7 @@ urlpatterns = [ path('websites/', views.WebsiteListView.as_view(), name='website-list'), path('websites//', views.WebsiteDetailView.as_view(), name='website-detail'), path('websites//edit/', views.WebsiteUpdateView.as_view(), name='website-update'), + path('websites//add-content/', views.WebsiteAddContentView.as_view(), name='website-add-content'), path('websites//content//delete/', views.WebsiteDeleteContentView.as_view(), name='website-delete-content'), path('websites//directive//delete/', views.WebsiteDeleteDirectiveView.as_view(), name='website-delete-directive'), diff --git a/orchestra/contrib/musician/views.py b/orchestra/contrib/musician/views.py index 91af6083..6a7f0e0f 100644 --- a/orchestra/contrib/musician/views.py +++ b/orchestra/contrib/musician/views.py @@ -33,16 +33,13 @@ from orchestra.contrib.mailboxes.models import Address, Mailbox from orchestra.contrib.resources.models import Resource, ResourceData from orchestra.contrib.saas.models import SaaS from orchestra.contrib.systemusers.models import WebappUsers, SystemUser -from orchestra.contrib.websites.models import Website, Content, WebsiteDirective -from orchestra.contrib.webapps.models import WebApp, WebAppOption from orchestra.utils.html import html_to_pdf from .auth import logout as auth_logout from .forms import (LoginForm, MailboxChangePasswordForm, MailboxCreateForm, MailboxSearchForm, MailboxUpdateForm, MailForm, RecordCreateForm, RecordUpdateForm, WebappUsersChangePasswordForm, - SystemUsersChangePasswordForm, WebappOptionCreateForm, WebappOptionUpdateForm, - WebsiteUpdateForm) + SystemUsersChangePasswordForm) from .mixins import (CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin) from .models import Address as AddressService @@ -53,6 +50,9 @@ from .models import MailinglistService, SaasService from .settings import ALLOWED_RESOURCES, MUSICIAN_EDIT_ENABLE_PHP_OPTIONS from .utils import get_bootstraped_percent +from .tidy_views.webapps import * +from .tidy_views.websites import * + logger = logging.getLogger(__name__) @@ -621,14 +621,14 @@ class LogoutView(RedirectView): class WebappUserListView(ServiceListView): model = WebappUsers - template_name = "musician/webappuser_list.html" + template_name = "musician/webapps/webappuser_list.html" extra_context = { # Translators: This message appears on the page title 'title': _('Webapp users'), } class WebappUserChangePasswordView(CustomContextMixin, UserTokenRequiredMixin, UpdateView): - template_name = "musician/webappuser_change_password.html" + template_name = "musician/webapps/webappuser_change_password.html" model = WebappUsers form_class = WebappUsersChangePasswordForm success_url = reverse_lazy("musician:webappuser-list") @@ -654,178 +654,3 @@ class SystemUserChangePasswordView(CustomContextMixin, UserTokenRequiredMixin, U def get_queryset(self): return self.model.objects.filter(account=self.request.user) -class WebsiteListView(CustomContextMixin, UserTokenRequiredMixin, ListView): - model = Website - template_name = "musician/website_list.html" - extra_context = { - # Translators: This message appears on the page title - 'title': _('Websites'), - } - - def get_queryset(self): - return self.model.objects.filter(account=self.request.user) - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context.update({ - 'description': _("A website is the place where a domain is associated with the directory where the web files are located. (WebApp)"), - }) - return context - - -class WebsiteDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView): - template_name = "musician/website_detail.html" - extra_context = { - # Translators: This message appears on the page title - 'title': _('website details'), - } - - def get_queryset(self): - return Website.objects.filter(account=self.request.user) - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context['content'] = Content.objects.filter(website=self.object) - context['directives'] = WebsiteDirective.objects.filter(website=self.object) - return context - - -class WebsiteUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView): - model = Website - form_class = WebsiteUpdateForm - template_name = "musician/website_form.html" - - def get_queryset(self): - qs = Website.objects.filter(account=self.request.user) - return qs - - def get_success_url(self): - return reverse_lazy("musician:website-detail", kwargs={"pk": self.kwargs["pk"]}) - - def get_form_kwargs(self): - kwargs = super().get_form_kwargs() - kwargs["user"] = self.request.user - return kwargs - - -class WebsiteDeleteContentView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): - model = Content - template_name = "musician/websiteoption_check_delete.html" - pk_url_kwarg = "content_pk" - - def get_queryset(self): - qs = Content.objects.filter(website__account=self.request.user, website=self.kwargs["pk"]) - return qs - - def get_success_url(self): - return reverse_lazy("musician:website-detail", kwargs={"pk": self.kwargs["pk"]}) - - def delete(self, request, *args, **kwargs): - object = self.get_object() - response = super().delete(request, *args, **kwargs) - object.website.save() - return response - - -class WebsiteDeleteDirectiveView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): - model = WebsiteDirective - template_name = "musician/websiteoption_check_delete.html" - pk_url_kwarg = "directive_pk" - - def get_queryset(self): - qs = WebsiteDirective.objects.filter(website__account=self.request.user, website=self.kwargs["pk"]) - return qs - - def get_success_url(self): - return reverse_lazy("musician:website-detail", kwargs={"pk": self.kwargs["pk"]}) - - def delete(self, request, *args, **kwargs): - object = self.get_object() - response = super().delete(request, *args, **kwargs) - object.website.save() - return response - - -class WebappListView(CustomContextMixin, UserTokenRequiredMixin, ListView): - model = WebApp - template_name = "musician/webapp_list.html" - extra_context = { - # Translators: This message appears on the page title - 'title': _('Webapps'), - } - - def get_queryset(self): - return self.model.objects.filter(account=self.request.user) - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context.update({ - 'description': _("A web app is the directory where your website is stored. Through SFTP, you can access this directory and upload/edit/delete files."), - 'description2': _("Each Webapp has its own SFTP user, which is created automatically when the Webapp is created.") - }) - return context - - -class WebappDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView): - template_name = "musician/webapp_detail.html" - extra_context = { - # Translators: This message appears on the page title - 'title': _('webapp details'), - } - - def get_queryset(self): - return WebApp.objects.filter(account=self.request.user) - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context.update({ - 'edit_allowed_PHP_options': MUSICIAN_EDIT_ENABLE_PHP_OPTIONS - }) - return context - - -class WebappAddOptionView(CustomContextMixin, UserTokenRequiredMixin, CreateView): - model = WebAppOption - form_class = WebappOptionCreateForm - template_name = "musician/webapp_option_form.html" - - def get_form_kwargs(self): - kwargs = super().get_form_kwargs() - webapp = get_object_or_404(WebApp, account=self.request.user, pk=self.kwargs["pk"]) - kwargs['webapp'] = webapp - return kwargs - - def get_success_url(self): - return reverse_lazy("musician:webapp-detail", kwargs={"pk": self.kwargs["pk"]}) - -class WebappDeleteOptionView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): - model = WebAppOption - template_name = "musician/webappoption_check_delete.html" - pk_url_kwarg = "option_pk" - - def get_queryset(self): - qs = WebAppOption.objects.filter(webapp__account=self.request.user, webapp=self.kwargs["pk"]) - return qs - - def get_success_url(self): - return reverse_lazy("musician:webapp-detail", kwargs={"pk": self.kwargs["pk"]}) - - def delete(self, request, *args, **kwargs): - object = self.get_object() - response = super().delete(request, *args, **kwargs) - object.webapp.save() - return response - - -class WebappUpdateOptionView(CustomContextMixin, UserTokenRequiredMixin, UpdateView): - model = WebAppOption - form_class = WebappOptionUpdateForm - template_name = "musician/webapp_option_form.html" - pk_url_kwarg = "option_pk" - - def get_queryset(self): - qs = WebAppOption.objects.filter(webapp__account=self.request.user, webapp=self.kwargs["pk"]) - return qs - - def get_success_url(self): - return reverse_lazy("musician:webapp-detail", kwargs={"pk": self.kwargs["pk"]})