musician website edit basic

This commit is contained in:
Jorge Pastor 2024-05-16 20:41:46 +02:00
parent f3e3d45d60
commit 4f258a9fe0
5 changed files with 68 additions and 4 deletions

View file

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

View file

@ -34,7 +34,7 @@
</tr>
</tbody>
</table>
<a class="btn btn-primary mt-4 mb-4" href="{% url 'musician:website-update' object.pk %}">{% trans "Edit options" %}</a></td>
<!-- Contents -->
<h3 class="service-name">{% trans "Contents" %}</h3>

View file

@ -0,0 +1,23 @@
{% extends "musician/base.html" %}
{% load bootstrap4 i18n %}
{% block content %}
<a class="btn-arrow-left" href="{% url 'musician:website-detail' view.kwargs.pk %}">{% trans "Go back" %}</a>
<h1 class="service-name">
{% if form.instance.pk %}{% trans "Update Option of Website" %}{% else %}{% trans "Add Option to" %}{% endif %}
<span class="font-weight-light">{{ website.name }}</span>
</h1>
<form method="post">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<a class="btn btn-light mr-2" href="{% url 'musician:website-detail' view.kwargs.pk %}">{% trans "Cancel" %}</a>
<button type="submit" class="btn btn-secondary">{% trans "Save" %}</button>
{% endbuttons %}
</form>
{% endblock %}

View file

@ -47,6 +47,7 @@ urlpatterns = [
path('websites/', views.WebsiteListView.as_view(), name='website-list'),
path('websites/<int:pk>/', views.WebsiteDetailView.as_view(), name='website-detail'),
path('websites/<int:pk>/edit/', views.WebsiteUpdateView.as_view(), name='website-update'),
path('websites/<int:pk>/content/<int:content_pk>/delete/', views.WebsiteDeleteContentView.as_view(), name='website-delete-content'),
path('websites/<int:pk>/directive/<int:directive_pk>/delete/', views.WebsiteDeleteDirectiveView.as_view(), name='website-delete-directive'),

View file

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