diff -r b7d19cd87fcf -r 09e00f38d177 src/hdalab/management/commands/send_moderation_mail.py --- a/src/hdalab/management/commands/send_moderation_mail.py Thu Apr 12 01:27:16 2018 +0200 +++ b/src/hdalab/management/commands/send_moderation_mail.py Wed Apr 11 12:19:47 2018 +0200 @@ -1,8 +1,14 @@ # -*- coding: utf-8 -*- ''' -Created on Mar 5, 2015 +Envoie un mail récapitulatif des renkan à modérer. +Aucun mail n'est envoyé si aucune modération n'est demandée. + +L'envoi est fait aux utilisateurs marqués comme `staff `_. -@author: ymh +cette commande est typiquement prévue pour être lancée à partir d'une tâche ``cron`` périodique (1 fois par jour par exemple). + +**Usage**: ``django-admin send_moderation_mail [options]`` + ''' import logging @@ -26,30 +32,30 @@ TEMPLATE_NAME = "mails/moderation_notice" class Command(NoArgsCommand): - + def handle_noargs(self, **options): # query renkan to moderate set_script_prefix(settings.SCRIPT_PREFIX) - + renkan_query = HdalabRenkan.objects.filter(state=HdalabRenkan.MODERATED) - + renkan_count = renkan_query.count() - + if renkan_count == 0: logger.info("Send moderation email : no renkan to moderate. exiting") return logger.debug("Send moderation email : %d renkan(s) to moderate", renkan_count) - + renkan_list = list(renkan_query.select_related()[:20]) - + connection = mail.get_connection() try: connection.open() for email_recipient in User.objects.filter(is_staff=True): if not email_recipient.email: continue - + msg_html = "" msg_txt = "" try: @@ -67,7 +73,7 @@ except Exception as e: logger.error("Error rendering template %s : %r", TEMPLATE_NAME, e) raise e - + if not msg_html and not msg_txt: logger.info("Send moderation email: nothing to email exiting") continue @@ -76,4 +82,3 @@ emsg.send(fail_silently=True) finally: connection.close() - \ No newline at end of file