From 54c6c592374651501918a506110ee6698686b23f Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Wed, 29 May 2024 20:03:25 +0200 Subject: [PATCH] musician mailinlist edit --- orchestra/contrib/musician/lists/__init__.py | 0 orchestra/contrib/musician/lists/forms.py | 18 ++++++ orchestra/contrib/musician/lists/views.py | 61 +++++++++++++++++++ .../templates/musician/mailinglist_form.html | 31 ++++++++++ .../templates/musician/mailinglist_list.html | 17 +++++- orchestra/contrib/musician/urls.py | 1 + orchestra/contrib/musician/views.py | 32 +--------- 7 files changed, 126 insertions(+), 34 deletions(-) create mode 100644 orchestra/contrib/musician/lists/__init__.py create mode 100644 orchestra/contrib/musician/lists/forms.py create mode 100644 orchestra/contrib/musician/lists/views.py create mode 100644 orchestra/contrib/musician/templates/musician/mailinglist_form.html diff --git a/orchestra/contrib/musician/lists/__init__.py b/orchestra/contrib/musician/lists/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/orchestra/contrib/musician/lists/forms.py b/orchestra/contrib/musician/lists/forms.py new file mode 100644 index 00000000..a50fb94b --- /dev/null +++ b/orchestra/contrib/musician/lists/forms.py @@ -0,0 +1,18 @@ +from django import forms +from django.utils.translation import gettext_lazy as _ + +from orchestra.contrib.lists.models import List +from orchestra.contrib.domains.models import Domain + +class MailingUpdateForm(forms.ModelForm): + class Meta: + model = List + fields = ("is_active", "name", "address_name", "address_domain") + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop('user') + super().__init__(*args, **kwargs) + qs = Domain.objects.filter(account=self.user) + self.fields['address_domain'].queryset = qs + self.fields['address_name'].help_text = _("Additional address besides the default @grups.pangea.org") + self.fields['name'].widget.attrs['readonly'] = True diff --git a/orchestra/contrib/musician/lists/views.py b/orchestra/contrib/musician/lists/views.py new file mode 100644 index 00000000..73eea83f --- /dev/null +++ b/orchestra/contrib/musician/lists/views.py @@ -0,0 +1,61 @@ +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.list import ListView +from orchestra.contrib.musician.mixins import (CustomContextMixin, ExtendedPaginationMixin, + UserTokenRequiredMixin) +from django.views.generic.edit import (CreateView, DeleteView, FormView, + UpdateView) + +from orchestra.contrib.lists.models import List +from orchestra.contrib.domains.models import Domain, Record +from orchestra.contrib.lists.settings import LISTS_DEFAULT_DOMAIN + +from .forms import MailingUpdateForm + +class MailingListsView(CustomContextMixin, UserTokenRequiredMixin, ListView): + model = List + template_name = "musician/mailinglist_list.html" + extra_context = { + # Translators: This message appears on the page title + 'title': _('Mailing lists'), + } + + 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) + domain_id = self.request.GET.get('domain') + if domain_id: + qs = Domain.objects.filter(account=self.request.user) + context.update({ + 'active_domain': get_object_or_404(qs, pk=domain_id), + }) + context.update({'default_domain': LISTS_DEFAULT_DOMAIN}) + return context + + def get_queryfilter(self): + """Retrieve query params (if any) to filter queryset""" + domain_id = self.request.GET.get('domain') + if domain_id: + return {"address_domain_id": domain_id} + return {} + +class MailingUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView): + model = List + form_class = MailingUpdateForm + template_name = "musician/mailinglist_form.html" + + def get_queryset(self): + qs = List.objects.filter(account=self.request.user) + return qs + + def get_success_url(self): + return reverse_lazy("musician:mailing-lists") + + def get_form_kwargs(self): + kwargs = super().get_form_kwargs() + kwargs["user"] = self.request.user + return kwargs diff --git a/orchestra/contrib/musician/templates/musician/mailinglist_form.html b/orchestra/contrib/musician/templates/musician/mailinglist_form.html new file mode 100644 index 00000000..b7c57a77 --- /dev/null +++ b/orchestra/contrib/musician/templates/musician/mailinglist_form.html @@ -0,0 +1,31 @@ +{% extends "musician/base.html" %} +{% load bootstrap4 i18n %} + + +{% block content %} + + + +{% trans "Go back" %} + +

+ {% trans "Update Option of list" %} {{ list.name }} +

+ +
+ {% csrf_token %} + {% bootstrap_form form %} + {% buttons %} + {% trans "Cancel" %} + + {% endbuttons %} +
+{% endblock %} + diff --git a/orchestra/contrib/musician/templates/musician/mailinglist_list.html b/orchestra/contrib/musician/templates/musician/mailinglist_list.html index 6663f9b1..805f159f 100644 --- a/orchestra/contrib/musician/templates/musician/mailinglist_list.html +++ b/orchestra/contrib/musician/templates/musician/mailinglist_list.html @@ -13,9 +13,10 @@ - + + @@ -24,6 +25,7 @@ Address Admin email Configure + @@ -35,12 +37,21 @@ {% else %} {% trans "Inactive" %} {% endif %} - {{ resource.address_name}} + + {% if resource.address %} + {{ resource.address }} + {% else %} + {{ resource.name }}@{{ default_domain }} + {% endif %} + {{ resource.admin_email }} Mailman + + + + {% endfor %} - {% include "musician/components/table_paginator.html" %} {% endblock %} diff --git a/orchestra/contrib/musician/urls.py b/orchestra/contrib/musician/urls.py index 3ad1e1a4..81554362 100644 --- a/orchestra/contrib/musician/urls.py +++ b/orchestra/contrib/musician/urls.py @@ -41,6 +41,7 @@ urlpatterns = [ path('mailboxes//change-password/', views.MailboxChangePasswordView.as_view(), name='mailbox-password'), path('mailing-lists/', views.MailingListsView.as_view(), name='mailing-lists'), + path('mailing-lists//', views.MailingUpdateView.as_view(), name='mailing-update'), path('databases/', views.DatabaseListView.as_view(), name='database-list'), diff --git a/orchestra/contrib/musician/views.py b/orchestra/contrib/musician/views.py index 95d1ad8b..ba8b98ca 100644 --- a/orchestra/contrib/musician/views.py +++ b/orchestra/contrib/musician/views.py @@ -52,6 +52,7 @@ from .utils import get_bootstraped_percent from .webapps.views import * from .websites.views import * +from .lists.views import * logger = logging.getLogger(__name__) @@ -315,37 +316,6 @@ class AddressDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): return self.model.objects.filter(account=self.request.user) -class MailingListsView(ServiceListView): - service_class = MailinglistService - model = List - template_name = "musician/mailinglist_list.html" - extra_context = { - # Translators: This message appears on the page title - 'title': _('Mailing lists'), - } - - def get_queryset(self): - return self.model.objects.filter(account=self.request.user).order_by("name") - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - domain_id = self.request.GET.get('domain') - if domain_id: - qs = Domain.objects.filter(account=self.request.user) - context.update({ - 'active_domain': get_object_or_404(qs, pk=domain_id) - }) - return context - - def get_queryfilter(self): - """Retrieve query params (if any) to filter queryset""" - domain_id = self.request.GET.get('domain') - if domain_id: - return {"address_domain_id": domain_id} - - return {} - - class MailboxListView(ServiceListView): service_class = MailboxService model = Mailbox