From b80f98ef4310daa8e2dd84aa826aefc66508433c Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 20 Oct 2020 15:32:13 +0200 Subject: [PATCH] Display mailing list address on team page --- apps/participation/models.py | 5 +++++ .../participation/templates/participation/team_detail.html | 3 +++ apps/participation/views.py | 7 ++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/participation/models.py b/apps/participation/models.py index e1d242c..7fc9b67 100644 --- a/apps/participation/models.py +++ b/apps/participation/models.py @@ -1,3 +1,4 @@ +import os import re from django.template.loader import render_to_string @@ -41,6 +42,10 @@ class Team(models.Model): default=False, ) + @property + def email(self): + return f"equipe-{self.trigram.lower()}@{os.getenv('SYMPA_HOST', 'localhost')}" + def create_mailing_list(self): get_sympa_client().create_list( f"equipe-{self.trigram.lower()}", diff --git a/apps/participation/templates/participation/team_detail.html b/apps/participation/templates/participation/team_detail.html index 6451db7..5ac6626 100644 --- a/apps/participation/templates/participation/team_detail.html +++ b/apps/participation/templates/participation/team_detail.html @@ -17,6 +17,9 @@
{% trans "Trigram:" %}
{{ team.trigram }}
+
{% trans "Email:" %}
+
{{ team.email }}
+
{% trans "Access code:" %}
{{ team.access_code }}
diff --git a/apps/participation/views.py b/apps/participation/views.py index 5f78982..0ca63e4 100644 --- a/apps/participation/views.py +++ b/apps/participation/views.py @@ -160,17 +160,14 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView) mail_context = dict(team=self.object, message=form.cleaned_data["message"]) mail_plain = render_to_string("participation/mails/team_validated.txt", mail_context) mail_html = render_to_string("participation/mails/team_validated.html", mail_context) - send_mail("[Corres2math] Équipe validée", mail_plain, None, - [f"equipe-{self.object.trigram.lower()}@{os.getenv('SYMPA_HOST', 'localhost')}"], - html_message=mail_html) + send_mail("[Corres2math] Équipe validée", mail_plain, None, [self.object.email], html_message=mail_html) elif "invalidate" in self.request.POST: self.object.participation.valid = None self.object.participation.save() mail_context = dict(team=self.object, message=form.cleaned_data["message"]) mail_plain = render_to_string("participation/mails/team_not_validated.txt", mail_context) mail_html = render_to_string("participation/mails/team_not_validated.html", mail_context) - send_mail("[Corres2math] Équipe non validée", mail_plain, None, - [f"equipe-{self.object.trigram.lower()}@{os.getenv('SYMPA_HOST', 'localhost')}"], + send_mail("[Corres2math] Équipe non validée", mail_plain, None, [self.object.email], html_message=mail_html) else: form.add_error(None, _("You must specify if you validate the registration or not."))