From 4f258a9fe04a06fbc416207dc5b5f7159a711530 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Thu, 16 May 2024 20:41:46 +0200 Subject: [PATCH] musician website edit basic --- orchestra/contrib/musician/forms.py | 22 ++++++++++++++++- .../templates/musician/website_detail.html | 2 +- .../templates/musician/website_form.html | 23 ++++++++++++++++++ orchestra/contrib/musician/urls.py | 1 + orchestra/contrib/musician/views.py | 24 +++++++++++++++++-- 5 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 orchestra/contrib/musician/templates/musician/website_form.html diff --git a/orchestra/contrib/musician/forms.py b/orchestra/contrib/musician/forms.py index 2ae82134..00d69ba3 100644 --- a/orchestra/contrib/musician/forms.py +++ b/orchestra/contrib/musician/forms.py @@ -14,6 +14,7 @@ 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 @@ -265,6 +266,25 @@ class WebappOptionUpdateForm(WebappOptionForm): 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/website_detail.html b/orchestra/contrib/musician/templates/musician/website_detail.html index 4092003d..7528f242 100644 --- a/orchestra/contrib/musician/templates/musician/website_detail.html +++ b/orchestra/contrib/musician/templates/musician/website_detail.html @@ -34,7 +34,7 @@ - +{% trans "Edit options" %}

{% trans "Contents" %}

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

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

+ +
+ {% csrf_token %} + {% bootstrap_form form %} + {% buttons %} + {% trans "Cancel" %} + + {% endbuttons %} +
+{% endblock %} + diff --git a/orchestra/contrib/musician/urls.py b/orchestra/contrib/musician/urls.py index 69803735..2604b715 100644 --- a/orchestra/contrib/musician/urls.py +++ b/orchestra/contrib/musician/urls.py @@ -47,6 +47,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//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 c1efd9a5..91af6083 100644 --- a/orchestra/contrib/musician/views.py +++ b/orchestra/contrib/musician/views.py @@ -41,7 +41,8 @@ from .auth import logout as auth_logout from .forms import (LoginForm, MailboxChangePasswordForm, MailboxCreateForm, MailboxSearchForm, MailboxUpdateForm, MailForm, RecordCreateForm, RecordUpdateForm, WebappUsersChangePasswordForm, - SystemUsersChangePasswordForm, WebappOptionCreateForm, WebappOptionUpdateForm) + SystemUsersChangePasswordForm, WebappOptionCreateForm, WebappOptionUpdateForm, + WebsiteUpdateForm) from .mixins import (CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin) from .models import Address as AddressService @@ -688,7 +689,25 @@ class WebsiteDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView): 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" @@ -763,7 +782,8 @@ class WebappDetailView(CustomContextMixin, UserTokenRequiredMixin, DetailView): 'edit_allowed_PHP_options': MUSICIAN_EDIT_ENABLE_PHP_OPTIONS }) return context - + + class WebappAddOptionView(CustomContextMixin, UserTokenRequiredMixin, CreateView): model = WebAppOption form_class = WebappOptionCreateForm