only show attend button if user is not already attending
This commit is contained in:
13
app.py
13
app.py
@@ -2,7 +2,7 @@ import os
|
|||||||
import logging
|
import logging
|
||||||
import json
|
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
|
from werkzeug.exceptions import abort
|
||||||
|
|
||||||
import calendar_interface
|
import calendar_interface
|
||||||
@@ -21,8 +21,9 @@ app.teardown_appcontext(db.close_db)
|
|||||||
app.cli.add_command(db.init_db_command)
|
app.cli.add_command(db.init_db_command)
|
||||||
app.register_blueprint(auth.bp)
|
app.register_blueprint(auth.bp)
|
||||||
|
|
||||||
# first time start up masl token acquire for test purposes (raises if not successful)
|
# first time start up msal token acquire for test purposes (raises if not successful)
|
||||||
calendar_interface.get_access_token()
|
if not (app.config["DEBUG"] or app.config["TESTING"]):
|
||||||
|
calendar_interface.get_access_token()
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
@@ -30,7 +31,11 @@ def index():
|
|||||||
|
|
||||||
events = calendar_interface.get_future_calendar_events().get("value")
|
events = calendar_interface.get_future_calendar_events().get("value")
|
||||||
calendar_interface.convert_datetimes(events)
|
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:
|
if events is None:
|
||||||
abort(404)
|
abort(404)
|
||||||
else:
|
else:
|
||||||
|
|||||||
2
auth.py
2
auth.py
@@ -53,7 +53,7 @@ def register():
|
|||||||
confirmation_add = current_app.config.get("CONFIRMATATION_EMAIL_ADD", email)
|
confirmation_add = current_app.config.get("CONFIRMATATION_EMAIL_ADD", email)
|
||||||
calendar_interface.send_mail(confirmation_add, subject, content)
|
calendar_interface.send_mail(confirmation_add, subject, content)
|
||||||
|
|
||||||
flash("Registrierung erfolgreich.")
|
flash("Registrierung erfolgreich. Auf Freischaltung warten.")
|
||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
flash(error)
|
flash(error)
|
||||||
|
|||||||
@@ -165,6 +165,12 @@ def delte_attendee(data, email):
|
|||||||
del data["attendees"][i]
|
del data["attendees"][i]
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def check_attendee_presence(data, email):
|
||||||
|
for d in data["attendees"]:
|
||||||
|
if d["emailAddress"]["address"] == email:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,15 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<h2>{{ event['subject'] }}</h2>
|
<h2>{{ event['subject'] }}</h2>
|
||||||
|
|
||||||
<a href="{{ url_for('attend', id=event['id']) }}">
|
{% if not event["user_attends"] %}
|
||||||
<span class="badge badge-warning">Teilnehmen</span>
|
<a href="{{ url_for('attend', id=event['id']) }}">
|
||||||
</a>
|
<span class="badge badge-warning">Teilnehmen</span>
|
||||||
<a href="{{ url_for('unattend', id=event['id']) }}">
|
</a>
|
||||||
<span class="badge badge-warning">Abmelden</span>
|
{% else %}
|
||||||
</a>
|
{# <a href="{{ url_for('unattend', id=event['id']) }}"> #}
|
||||||
|
<span class="badge badge-success">Nehme Teil</span>
|
||||||
|
{# </a> #}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<span class="badge badge-primary">{{ event["start"]["time"] }}</span>
|
<span class="badge badge-primary">{{ event["start"]["time"] }}</span>
|
||||||
<span class="badge badge-primary">{{ event["duration"] }}</span>
|
<span class="badge badge-primary">{{ event["duration"] }}</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user