musician website create contents

This commit is contained in:
Jorge Pastor 2024-05-18 14:27:03 +02:00
parent 4f258a9fe0
commit 1ebf30db33
21 changed files with 397 additions and 294 deletions

View File

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

View File

@ -31,7 +31,6 @@
</tr>
{% endfor %}
</tbody>
{% include "musician/components/table_paginator.html" %}
</table>
{% endblock %}

View File

@ -7,8 +7,7 @@
<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>
{% trans "Add Option to" %} <span class="font-weight-light">{{ form.website.name }}</span>
</h1>
<form method="post">
@ -20,4 +19,3 @@
{% endbuttons %}
</form>
{% endblock %}

View File

@ -64,7 +64,7 @@
{% endfor %}
</tbody>
</table>
<!-- <a class="btn btn-primary mt-4 mb-4" href="{% url 'musician:webapp-add-option' object.pk %}">{% trans "Add new option" %}</a></td> -->
<a class="btn btn-primary mt-4 mb-4" href="{% url 'musician:website-add-content' object.pk %}">{% trans "Assigned new Webapp" %}</a></td>
<!-- Directives -->
<h3 class="service-name">{% trans "Directives" %}</h3>

View File

@ -0,0 +1,31 @@
{% 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:website-detail' view.kwargs.pk %}">{% trans "Go back" %}</a>
<h1 class="service-name">
{% trans "Update Option of Website" %} <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

@ -38,9 +38,6 @@
<span class="sr-only">{{ website.is_active|yesno }}</span>
</td>
<td>
<!-- <button type="button" class="btn btn-outline-warning" data-toggle="modal" data-target="#websiteModal">
<i class="fas fa-tools"></i>
</button> -->
<a class="btn btn-outline-warning" href="{% url 'musician:website-detail' website.id %}">
<i class="fas fa-tools"></i></a>
</td>
@ -55,7 +52,7 @@
<td>Webapp Dir</td>
<td>/home/{{ content.webapp.account }}/webapps/{{ content.webapp }}</td>
<td class="text-right">
<a class="btn btn-outline-secondary" href="{% url 'musician:webapp-list'%}">
<a class="btn btn-outline-secondary" href="{% url 'musician:webapp-detail' content.webapp.id %}">
<i class="fas fa-tools"></i></a>
</td>
</tr>
@ -107,22 +104,4 @@
<!-- Modal -->
<!-- <div class="modal fade" id="websiteModal" tabindex="-1" role="dialog" aria-labelledby="websiteModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="websiteModalLabel">Sorry!</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
{% trans "This section is under development." %}
</div>
</div>
</div>
</div> -->
{% endblock %}

View File

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

View File

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

View File

@ -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"]})

View File

@ -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"]})

View File

@ -48,6 +48,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>/add-content/', views.WebsiteAddContentView.as_view(), name='website-add-content'),
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

@ -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"]})