diff --git a/server.py b/server.py index d88bd313cc755e768d5e2a661d384d5ee07335d8..3949cbb9779f8938c7e5ec2393b5005de6b63695 100755 --- a/server.py +++ b/server.py @@ -661,6 +661,33 @@ def send_protocol(protocol): flash("Das Protokoll wurde versandt.", "alert-success") return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id)) +@app.route("/protocol/reminder/<int:protocol_id>") +@login_required +@db_lookup(Protocol) +@require_modify_right() +def send_protocol_reminder(protocol): + if not config.MAIL_ACTIVE: + flash("Die Mailfunktion ist nicht aktiviert.", "alert-error") + return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol_id)) + meetingreminders = MeetingReminder.query.filter_by(protocoltype_id=protocol.protocoltype.id).all() + if len(meetingreminders) == 0: + flash("Für diesen Protokolltyp sind keine Einladungsmails konfiguriert.", "alert-error") + return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol_id)) + day_difference = (protocol.date - datetime.now().date()).days + past_reminders = [ + meetingreminder for meetingreminder in meetingreminders + if meetingreminder.days_before > day_difference + ] + if len(past_reminders) == 0: + flash("Bisher hätte keine Einladungsmail verschickt werden sollen, schicke letzte.", "alert-info") + past_reminders = meetingreminders + past_reminders = sorted(past_reminders, key=lambda r: r.days_before) + choosen_reminder = past_reminders[0] + tasks.send_reminder(choosen_reminder, protocol) + flash("Einladungsmail ist versandt.", "alert-success") + return redirect(request.args.get("next") or url_for("show_protocol", protocol_id=protocol.id)) + + @app.route("/protocol/tops/new/<int:protocol_id>", methods=["GET", "POST"]) @login_required @db_lookup(Protocol) diff --git a/templates/protocol-show.html b/templates/protocol-show.html index 9673b8ee5abf6ca67bc3a9da0cd085321e1179ba..1316ede0991847e359e163fbd4cc0b0843d8d818 100644 --- a/templates/protocol-show.html +++ b/templates/protocol-show.html @@ -27,6 +27,9 @@ {% endif %} {% if not protocol.is_done() %} <a class="btn btn-default" href="{{url_for("get_protocol_template", protocol_id=protocol.id)}}">Vorlage</a> + {% if config.MAIL_ACTIVE %} + <a class="btn btn-default" href="{{url_for("send_protocol_reminder", protocol_id=protocol.id)}}" onclick="return confirm('Bist du dir sicher, dass du manuell eine Einladung verschicken willst? Dies wird auch automatisch geschehen.');">Einladung versenden</a> + {% endif %} {% else %} {% if config.MAIL_ACTIVE %} <a class="btn btn-default" href="{{url_for("send_protocol", protocol_id=protocol.id)}}">Mail versenden</a>