mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-21 20:38:22 +02:00
Automatically create mailing lists
This commit is contained in:
@ -8,6 +8,8 @@ from django.utils.crypto import get_random_string
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from corres2math.lists import get_sympa_client
|
||||
|
||||
|
||||
class Team(models.Model):
|
||||
name = models.CharField(
|
||||
@ -36,9 +38,22 @@ class Team(models.Model):
|
||||
default=False,
|
||||
)
|
||||
|
||||
def create_mailing_list(self):
|
||||
get_sympa_client().create_list(
|
||||
f"equipe-{self.trigram.lower()}",
|
||||
f"Équipe {self.name} ({self.trigram})",
|
||||
"hotline", # TODO Use a custom sympa template
|
||||
f"Liste de diffusion pour contacter l'équipe {self.name} des Correspondances",
|
||||
"education",
|
||||
)
|
||||
|
||||
def delete_mailing_list(self):
|
||||
get_sympa_client().delete_list(f"equipe-{self.trigram}")
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.access_code:
|
||||
self.access_code = get_random_string(6)
|
||||
self.create_mailing_list()
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -10,6 +10,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, DetailView, FormView, RedirectView, UpdateView
|
||||
from magic import Magic
|
||||
|
||||
from corres2math.lists import get_sympa_client
|
||||
from .forms import JoinTeamForm, ParticipationForm, TeamForm, UploadVideoForm
|
||||
from .models import Participation, Team, Video
|
||||
|
||||
@ -36,6 +37,8 @@ class CreateTeamView(LoginRequiredMixin, CreateView):
|
||||
registration = user.registration
|
||||
registration.team = form.instance
|
||||
registration.save()
|
||||
get_sympa_client().subscribe(user.email, f"equipe-{form.instance.trigram.lower()}", False,
|
||||
f"{user.first_name} {user.last_name}")
|
||||
return ret
|
||||
|
||||
def get_success_url(self):
|
||||
@ -65,6 +68,8 @@ class JoinTeamView(LoginRequiredMixin, FormView):
|
||||
registration = user.registration
|
||||
registration.team = form.instance
|
||||
registration.save()
|
||||
get_sympa_client().subscribe(user.email, f"equipe-{form.instance.trigram.lower()}", False,
|
||||
f"{user.first_name} {user.last_name}")
|
||||
return ret
|
||||
|
||||
def get_success_url(self):
|
||||
|
Reference in New Issue
Block a user