musician mailinlist create and delete

This commit is contained in:
Jorge Pastor 2024-06-05 17:14:59 +02:00
parent 281d50acc5
commit e1d250c35f
6 changed files with 69 additions and 3 deletions

View File

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

View File

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

View File

@ -0,0 +1,12 @@
{% extends "musician/base.html" %}
{% load i18n %}
{% block content %}
<form method="post">
{% csrf_token %}
<p>{% blocktrans %}Are you sure that you want remove the list: "{{ list }}"?{% endblocktrans %}</p>
<p class="alert alert-warning"><strong>{% trans 'WARNING: This action cannot be undone.' %}</strong></p>
<a class="btn btn-light mr-2" href="{% url 'musician:mailing-lists' %}">{% trans 'Cancel' %}</a>
<input class="btn btn-danger" type="submit" value="{% trans 'Delete' %}">
</form>
{% endblock %}

View File

@ -16,7 +16,11 @@
<a class="btn-arrow-left" href="{% url 'musician:mailing-lists' %}">{% trans "Go back" %}</a>
<h1 class="service-name">
{% trans "Update Option of list" %} <span class="font-weight-light">{{ list.name }}</span>
{% if form.instance.pk %}
{% trans "Update list" %} <span class="font-weight-light">{{ list.name }}</span>
{% else %}
{% trans "Create list" %}
{% endif %}
</h1>
<form method="post">
@ -25,6 +29,11 @@
{% buttons %}
<a class="btn btn-light mr-2" href="{% url 'musician:mailing-lists' %}">{% trans "Cancel" %}</a>
<button type="submit" class="btn btn-secondary">{% trans "Save" %}</button>
{% if form.instance.pk %}
<div class="float-right">
<a class="btn btn-danger" href="{% url 'musician:mailing-delete' view.kwargs.pk %}">{% trans "Delete" %}</a>
</div>
{% endif %}
{% endbuttons %}
</form>
{% endblock %}

View File

@ -46,12 +46,16 @@
</td>
<td>{{ resource.admin_email }}</td>
<td><a href="{{ resource.get_absolute_url }}" target="_blank" rel="noopener noreferrer">Mailman <i class="fas fa-external-link-alt"></i></a></td>
<td>
<td class="text-right">
<a class="btn btn-outline-warning" href="{% url 'musician:mailing-update' resource.id %}">
<i class="fas fa-tools"></i></a>
<a href="{% url 'musician:mailing-delete' resource.id %}">
<i class="ml-3 text-danger fas fa-trash"></i></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<a class="btn btn-primary mt-4 mb-4" href="{% url 'musician:mailing-create' %}">{% trans "New list" %}</a>
{% endblock %}

View File

@ -42,6 +42,8 @@ urlpatterns = [
path('mailing-lists/', views.MailingListsView.as_view(), name='mailing-lists'),
path('mailing-lists/<int:pk>/', views.MailingUpdateView.as_view(), name='mailing-update'),
path('mailing-lists/new/', views.MailingCreateView.as_view(), name='mailing-create'),
path('mailing-lists/<int:pk>/delete/', views.MailingDeleteView.as_view(), name='mailing-delete'),
path('databases/', views.DatabaseListView.as_view(), name='database-list'),