diff --git a/management/commands/extract_ml_registrations.py b/management/commands/extract_ml_registrations.py index 6f49ede..9196fa4 100644 --- a/management/commands/extract_ml_registrations.py +++ b/management/commands/extract_ml_registrations.py @@ -22,6 +22,8 @@ class Command(BaseCommand): 'events mailing list.') parser.add_argument('--years', '-y', type=int, default=0, help='Select the cumulative registred users of a membership from years ago. 0 means the current users') + parser.add_argument('--email', '-e', type=str, default="", + help='Put the email supposed to receive the emails of the mailing list (only for art). If nothing is put, the script will just print the emails.') def handle(self, *args, **options): # TODO: Improve the mailing list extraction system, and link it automatically with Mailman. @@ -55,23 +57,29 @@ class Command(BaseCommand): if options["type"] == "art": nb=0 - emails = [] - for user in User.objects.filter(profile__ml_art_registration=True).all(): - # self.stdout.write(user.email) - emails.append(user.email) - nb+=1 - # self.stdout.write(str(nb)) - subject = "Liste des abonnés à la newsletter BDA" - message = ( - f"Voici la liste des utilisateurs abonnés à la newsletter BDA:\n\n" - + "\n".join(emails) - + f"\n\nTotal des abonnés : {nb}" - ) - from_email = "Note Kfet 2020 " - recipient_list = ["bda.ensparissaclay@gmail.com"] + if options["email"] == "": + for user in User.objects.filter(profile__ml_art_registration=True).all(): + self.stdout.write(user.email) + nb+=1 + self.stdout.write(str(nb)) - send_mail(subject, message, from_email, recipient_list) + else : + emails = [] + for user in User.objects.filter(profile__ml_art_registration=True).all(): + emails.append(user.email) + nb+=1 + + subject = "Liste des abonnés à la newsletter BDA" + message = ( + f"Voici la liste des utilisateurs abonnés à la newsletter BDA:\n\n" + + "\n".join(emails) + + f"\n\nTotal des abonnés : {nb}" + ) + from_email = "Note Kfet 2020 " + recipient_list = ["bda.ensparissaclay@gmail.com"] + + send_mail(subject, message, from_email, recipient_list) return