From 3dd5f6e3e0a2602b536ec84d5861057495d28ff5 Mon Sep 17 00:00:00 2001 From: thomasl Date: Tue, 4 Mar 2025 16:50:49 +0100 Subject: [PATCH] Extend the possibility to send the list by email to the other newsletters --- .../commands/extract_ml_registrations.py | 59 +++++++++++++++++-- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/management/commands/extract_ml_registrations.py b/management/commands/extract_ml_registrations.py index 9196fa4..19a52a4 100644 --- a/management/commands/extract_ml_registrations.py +++ b/management/commands/extract_ml_registrations.py @@ -48,11 +48,35 @@ class Command(BaseCommand): self.stdout.write(club.email) return - # Get the list of mails that want to be registered to the events mailing list. + # Get the list of mails that want to be registered to the events mailing listn, as well as the number of mails. + # Print it or send it to the email provided by the user. # Don't filter to valid members, old members can receive these mails as long as they want. if options["type"] == "events": - for user in User.objects.filter(profile__ml_events_registration=options["lang"]).all(): - self.stdout.write(user.email) + nb=0 + + if options["email"] == "": + for user in User.objects.filter(profile__ml_events_registration=options["lang"]).all(): + self.stdout.write(user.email) + nb+=1 + self.stdout.write(str(nb)) + + else : + emails = [] + for user in User.objects.filter(profile__ml_events_registration=options["lang"]).all(): + emails.append(user.email) + nb+=1 + + subject = "Liste des abonnés à la newsletter BDE" + message = ( + f"Voici la liste des utilisateurs abonnés à la newsletter BDE:\n\n" + + "\n".join(emails) + + f"\n\nTotal des abonnés : {nb}" + ) + from_email = "Note Kfet 2020 " + recipient_list = [options["email"]] + + send_mail(subject, message, from_email, recipient_list) + return if options["type"] == "art": @@ -77,13 +101,36 @@ class Command(BaseCommand): + f"\n\nTotal des abonnés : {nb}" ) from_email = "Note Kfet 2020 " - recipient_list = ["bda.ensparissaclay@gmail.com"] + recipient_list = [options["email"]] send_mail(subject, message, from_email, recipient_list) return if options["type"] == "sport": - for user in User.objects.filter(profile__ml_sport_registration=True).all(): - self.stdout.write(user.email) + nb=0 + + if options["email"] == "": + for user in User.objects.filter(profile__ml_sport_registration=True).all(): + self.stdout.write(user.email) + nb+=1 + self.stdout.write(str(nb)) + + else : + emails = [] + for user in User.objects.filter(profile__ml_sport_registration=True).all(): + emails.append(user.email) + nb+=1 + + subject = "Liste des abonnés à la newsletter BDS" + message = ( + f"Voici la liste des utilisateurs abonnés à la newsletter BDS:\n\n" + + "\n".join(emails) + + f"\n\nTotal des abonnés : {nb}" + ) + from_email = "Note Kfet 2020 " + recipient_list = [options["email"]] + + send_mail(subject, message, from_email, recipient_list) + return