Commit 666e7a72 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Send reminder mails if protocols remain unfinished

This adds the configuration key MAX_PAST_INDEX_DAYS_BEFORE_REMINDER
ref #158
parent d7ccb38d
......@@ -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()
......@@ -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)
......
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment