diff --git a/orchestra/contrib/musician/lists/forms.py b/orchestra/contrib/musician/lists/forms.py index a50fb94b..611f6101 100644 --- a/orchestra/contrib/musician/lists/forms.py +++ b/orchestra/contrib/musician/lists/forms.py @@ -16,3 +16,23 @@ class MailingUpdateForm(forms.ModelForm): 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 + + +class MailingCreateForm(forms.ModelForm): + class Meta: + model = List + fields = ("name", "address_name", "address_domain", "admin_email") + + 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") + + def save(self, commit=True): + instance = super().save(commit=False) + instance.account = self.user + if commit: + super().save(commit=True) + return instance \ No newline at end of file diff --git a/orchestra/contrib/musician/lists/views.py b/orchestra/contrib/musician/lists/views.py index 73eea83f..dfd53fdb 100644 --- a/orchestra/contrib/musician/lists/views.py +++ b/orchestra/contrib/musician/lists/views.py @@ -12,7 +12,7 @@ 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 +from .forms import MailingUpdateForm, MailingCreateForm class MailingListsView(CustomContextMixin, UserTokenRequiredMixin, ListView): model = List @@ -59,3 +59,22 @@ class MailingUpdateView(CustomContextMixin, UserTokenRequiredMixin, UpdateView): kwargs = super().get_form_kwargs() kwargs["user"] = self.request.user return kwargs + +class MailingCreateView(CustomContextMixin, UserTokenRequiredMixin, CreateView): + model = List + form_class = MailingCreateForm + template_name = "musician/mailinglist_form.html" + success_url = reverse_lazy("musician:mailing-lists") + + def get_form_kwargs(self): + kwargs = super().get_form_kwargs() + kwargs['user'] = self.request.user + return kwargs + +class MailingDeleteView(CustomContextMixin, UserTokenRequiredMixin, DeleteView): + template_name = "musician/mailing_check_delete.html" + model = List + success_url = reverse_lazy("musician:mailing-lists") + + def get_queryset(self): + return self.model.objects.filter(account=self.request.user) \ No newline at end of file diff --git a/orchestra/contrib/musician/templates/musician/mailing_check_delete.html b/orchestra/contrib/musician/templates/musician/mailing_check_delete.html new file mode 100644 index 00000000..d49ba734 --- /dev/null +++ b/orchestra/contrib/musician/templates/musician/mailing_check_delete.html @@ -0,0 +1,12 @@ +{% extends "musician/base.html" %} +{% load i18n %} + +{% block content %} +
+ {% csrf_token %} +

{% blocktrans %}Are you sure that you want remove the list: "{{ list }}"?{% endblocktrans %}

+

{% trans 'WARNING: This action cannot be undone.' %}

+ {% trans 'Cancel' %} + +
+{% endblock %} diff --git a/orchestra/contrib/musician/templates/musician/mailinglist_form.html b/orchestra/contrib/musician/templates/musician/mailinglist_form.html index b7c57a77..3e2df71c 100644 --- a/orchestra/contrib/musician/templates/musician/mailinglist_form.html +++ b/orchestra/contrib/musician/templates/musician/mailinglist_form.html @@ -16,7 +16,11 @@ {% trans "Go back" %}

- {% trans "Update Option of list" %} {{ list.name }} + {% if form.instance.pk %} + {% trans "Update list" %} {{ list.name }} + {% else %} + {% trans "Create list" %} + {% endif %}

@@ -25,6 +29,11 @@ {% buttons %} {% trans "Cancel" %} + {% if form.instance.pk %} + + {% endif %} {% endbuttons %}
{% endblock %} diff --git a/orchestra/contrib/musician/templates/musician/mailinglist_list.html b/orchestra/contrib/musician/templates/musician/mailinglist_list.html index 805f159f..c7ccad2a 100644 --- a/orchestra/contrib/musician/templates/musician/mailinglist_list.html +++ b/orchestra/contrib/musician/templates/musician/mailinglist_list.html @@ -46,12 +46,16 @@ {{ resource.admin_email }} Mailman - + + + {% endfor %} +{% trans "New list" %} + {% endblock %} diff --git a/orchestra/contrib/musician/urls.py b/orchestra/contrib/musician/urls.py index 81554362..8d56bda0 100644 --- a/orchestra/contrib/musician/urls.py +++ b/orchestra/contrib/musician/urls.py @@ -42,6 +42,8 @@ urlpatterns = [ path('mailing-lists/', views.MailingListsView.as_view(), name='mailing-lists'), path('mailing-lists//', views.MailingUpdateView.as_view(), name='mailing-update'), + path('mailing-lists/new/', views.MailingCreateView.as_view(), name='mailing-create'), + path('mailing-lists//delete/', views.MailingDeleteView.as_view(), name='mailing-delete'), path('databases/', views.DatabaseListView.as_view(), name='database-list'),