diff --git a/server.py b/server.py index a429ca32db96a4da35dfc200ad601bac391a2bd3..a98dac6553faa7a277b7002fd490f192bf3edd12 100755 --- a/server.py +++ b/server.py @@ -1381,24 +1381,25 @@ except ImportError as exc: atexit.register(scheduler.shutdown) def check_and_send_reminders(): - print("check and send reminders") if not config.MAIL_ACTIVE: return with app.app_context(): current_time = datetime.now() current_day = current_time.date() - print("regular action for reminders") for protocol in Protocol.query.filter(Protocol.done != True).all(): day_difference = (protocol.date - current_day).days usual_time = protocol.get_time() protocol_time = datetime(1, 1, 1, usual_time.hour, usual_time.minute) hour_difference = (protocol_time - current_time).seconds // 3600 - print("diff: {} days, {} hours".format(day_difference, hour_difference)) for reminder in protocol.protocoltype.reminders: - print(reminder) if day_difference == reminder.days_before and hour_difference == 0: - print("reminder matching, sending") tasks.send_reminder(reminder, protocol) + if (day_difference < 0 + and -day_difference > config.MAX_PAST_INDEX_DAYS_BEFORE_REMINDER + and hour_difference == 0): # once per day + tasks.remind_finishing(protocol, -day_difference, + config.MAX_PAST_INDEX_DAYS_BEFORE_REMINDER) + if __name__ == "__main__": manager.run() diff --git a/tasks.py b/tasks.py index e0efdeb8948a5aa033f4bdd84bebf13ea20fdd90..080c839deef08c2be62a78cb5ce1156d8d217ba3 100644 --- a/tasks.py +++ b/tasks.py @@ -663,6 +663,20 @@ def send_reminder_async(reminder_id, protocol_id): "Tagesordnung der {}".format(protocol.protocoltype.name), reminder_text, reply_to=protocol.protocoltype.private_mail) +def remind_finishing(protocol, delay_days, min_delay_days): + remind_finishing.delay(protocol.id, delay_days, min_delay_days) + +@celery.task +def remind_finishing(protocol_id, delay_days, min_delay_days): + with app.app_context(): + protocol = Protocol.query.filter_by(id=protocol_id).first() + mail_text = render_template("remind-finishing-mail.txt", + protocol=protocol, delay_days=delay_days, + min_delay_days=min_delay_days) + send_mail(protocol, protocol.protocoltype.private_mail, + "Unfertiges Protokoll der {}".format(protocol.protocoltype.name), + mail_text, reply_to=protocol.protocoltype.private_mail) + def send_protocol_private(protocol): send_protocol_async.delay(protocol.id, show_private=True) send_todomails_async.delay(protocol.id) diff --git a/templates/remind-finishing-mail.txt b/templates/remind-finishing-mail.txt new file mode 100644 index 0000000000000000000000000000000000000000..28be2852b3dc83ba03dfdc41a05b3e952aea881a --- /dev/null +++ b/templates/remind-finishing-mail.txt @@ -0,0 +1,10 @@ +Das Protokoll {{protocol.protocoltype.name}} vom {{protocol.date|datify}} ist, obwohl diese Sitzung bereits {{delay_days}} in der Vergangenheit liegt, noch nicht fertig. +Bitte erledigt dies. + +Falls die Sitzung nicht stattgefunden hat, könnt ihr sie ohne Protokoll schließen oder von den Admins löschen lassen. +Sollte sie stattgefunden haben, stellt bitte das Protokoll fertig. + +Bis zum Erledigen wird euch diese Erinnerungsmail täglich zugesendet. + +Mit{% if (delay_days - min_delay_days) < min_delay_days %} freundlichen{% endif %} Grüßen +Euer Protokollsystem