mirror of
https://gitlab.crans.org/bde/nk20-scripts
synced 2025-06-30 18:11:14 +02:00
Improve scripts to be run with cron jobs
This commit is contained in:
@ -11,15 +11,26 @@ from note.models import NoteUser
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
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")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
activate('fr')
|
||||
notes = NoteUser.objects.filter(
|
||||
balance__lte=-1000,
|
||||
balance__lte=-options["negative_amount"],
|
||||
user__memberships__date_end__gte=timezone.now(),
|
||||
).order_by('balance').distinct().all()
|
||||
for note in notes:
|
||||
note.send_mail_negative_balance()
|
||||
activate('fr')
|
||||
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>",
|
||||
recipient_list=["respoinfo.bde@lists.crans.org", "tresorerie.bde@lists.crans.org"], html_message=html)
|
||||
|
||||
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>",
|
||||
recipient_list=["respoinfo.bde@lists.crans.org", "tresorerie.bde@lists.crans.org"],
|
||||
html_message=html)
|
||||
|
Reference in New Issue
Block a user