1
0
mirror of https://gitlab.crans.org/bde/nk20-scripts synced 2025-04-20 22:52: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.') 'events mailing list.')
parser.add_argument('--years', '-y', type=int, default=0, 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') 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): def handle(self, *args, **options):
# TODO: Improve the mailing list extraction system, and link it automatically with Mailman. # TODO: Improve the mailing list extraction system, and link it automatically with Mailman.
@ -55,12 +57,18 @@ class Command(BaseCommand):
if options["type"] == "art": if options["type"] == "art":
nb=0 nb=0
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))
else :
emails = [] emails = []
for user in User.objects.filter(profile__ml_art_registration=True).all(): for user in User.objects.filter(profile__ml_art_registration=True).all():
# self.stdout.write(user.email)
emails.append(user.email) emails.append(user.email)
nb+=1 nb+=1
# self.stdout.write(str(nb))
subject = "Liste des abonnés à la newsletter BDA" subject = "Liste des abonnés à la newsletter BDA"
message = ( message = (