1
0
mirror of https://gitlab.crans.org/bde/nk20-scripts synced 2025-04-16 12:42:15 +00:00

Add an option to send the list to an email

This commit is contained in:
thomasl 2025-03-04 16:39:04 +01:00
parent 119c1edc2f
commit 735d90e482

View File

@ -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 <notekfet2020@crans.org>"
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 <notekfet2020@crans.org>"
recipient_list = ["bda.ensparissaclay@gmail.com"]
send_mail(subject, message, from_email, recipient_list)
return