2020-08-01 19:44:01 +00:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
from django.core.mail import send_mail
|
|
|
|
from django.core.management import BaseCommand
|
|
|
|
from django.template.loader import render_to_string
|
|
|
|
from django.utils import timezone
|
|
|
|
from django.utils.translation import activate
|
|
|
|
|
|
|
|
from note.models import NoteUser
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
2020-08-05 21:15:05 +00:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument("--spam", "-s", action='store_true', help="Spam negative users")
|
|
|
|
parser.add_argument("--report", "-r", action='store_true', help="Report the list of negative users to admins")
|
|
|
|
parser.add_argument("--negative-amount", "-n", action='store', type=int, default=1000,
|
|
|
|
help="Maximum amount to be considered as very negative")
|
|
|
|
|
2020-08-01 19:44:01 +00:00
|
|
|
def handle(self, *args, **options):
|
2020-08-05 21:15:05 +00:00
|
|
|
activate('fr')
|
2020-08-01 19:44:01 +00:00
|
|
|
notes = NoteUser.objects.filter(
|
2020-08-05 21:15:05 +00:00
|
|
|
balance__lte=-options["negative_amount"],
|
2020-08-06 06:11:44 +00:00
|
|
|
user__memberships__date_end__gte=timezone.now().date(),
|
2020-08-01 19:44:01 +00:00
|
|
|
).order_by('balance').distinct().all()
|
2020-08-05 21:15:05 +00:00
|
|
|
|
|
|
|
if options["spam"]:
|
|
|
|
for note in notes:
|
|
|
|
note.send_mail_negative_balance()
|
|
|
|
|
|
|
|
if options["report"]:
|
|
|
|
plain_text = render_to_string("note/mails/negative_notes_report.txt", context=dict(notes=notes))
|
|
|
|
html = render_to_string("note/mails/negative_notes_report.html", context=dict(notes=notes))
|
|
|
|
send_mail("[Note Kfet] Liste des négatifs", plain_text, "Note Kfet 2020 <notekfet2020@crans.org>",
|
2020-08-06 06:11:44 +00:00
|
|
|
recipient_list=["respo-info.bde@lists.crans.org", "tresorerie.bde@lists.crans.org"],
|
2020-08-05 21:15:05 +00:00
|
|
|
html_message=html)
|