From cec54b66e501052901f9d70a9297a8f1bd0dafad Mon Sep 17 00:00:00 2001 From: pstruebi Date: Wed, 15 Jun 2022 12:41:43 +0200 Subject: [PATCH] only show attend button if user is not already attending --- app.py | 13 +++++++++---- auth.py | 2 +- calendar_interface.py | 6 ++++++ templates/index.html | 15 +++++++++------ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index 784cb72..47b862e 100644 --- a/app.py +++ b/app.py @@ -2,7 +2,7 @@ import os import logging import json -from flask import Flask, render_template, g, request, url_for, flash, redirect +from flask import Flask, current_app, render_template, g, request, url_for, flash, redirect from werkzeug.exceptions import abort import calendar_interface @@ -21,8 +21,9 @@ app.teardown_appcontext(db.close_db) app.cli.add_command(db.init_db_command) app.register_blueprint(auth.bp) -# first time start up masl token acquire for test purposes (raises if not successful) -calendar_interface.get_access_token() +# first time start up msal token acquire for test purposes (raises if not successful) +if not (app.config["DEBUG"] or app.config["TESTING"]): + calendar_interface.get_access_token() @app.route('/') @auth.login_required @@ -30,7 +31,11 @@ def index(): events = calendar_interface.get_future_calendar_events().get("value") calendar_interface.convert_datetimes(events) - + # Check current users attendance in event + for event in events: + ret = calendar_interface.check_attendee_presence(event, g.user["email"]) + event["user_attends"] = ret + logging.info("User %s attending: %s", g.user["email"], ret) if events is None: abort(404) else: diff --git a/auth.py b/auth.py index 5477a71..5bf9b4e 100644 --- a/auth.py +++ b/auth.py @@ -53,7 +53,7 @@ def register(): confirmation_add = current_app.config.get("CONFIRMATATION_EMAIL_ADD", email) calendar_interface.send_mail(confirmation_add, subject, content) - flash("Registrierung erfolgreich.") + flash("Registrierung erfolgreich. Auf Freischaltung warten.") return redirect(url_for("index")) flash(error) diff --git a/calendar_interface.py b/calendar_interface.py index 4c9a577..3c97022 100644 --- a/calendar_interface.py +++ b/calendar_interface.py @@ -165,6 +165,12 @@ def delte_attendee(data, email): del data["attendees"][i] break +def check_attendee_presence(data, email): + for d in data["attendees"]: + if d["emailAddress"]["address"] == email: + return True + + return False if __name__ == "__main__": diff --git a/templates/index.html b/templates/index.html index dab03e9..74ec291 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,12 +13,15 @@ {% endif %}

{{ event['subject'] }}

- - Teilnehmen - - - Abmelden - + {% if not event["user_attends"] %} + + Teilnehmen + + {% else %} + {# #} + Nehme Teil + {# #} + {% endif %} {{ event["start"]["time"] }} {{ event["duration"] }}