From e78e2f198966badb8be22d36f8d75bf9ec7b7fb8 Mon Sep 17 00:00:00 2001 From: Florian du Garage Num Date: Thu, 8 Jun 2023 17:57:27 +0200 Subject: [PATCH] add role mechanism for participants --- project/airtableget.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/project/airtableget.py b/project/airtableget.py index 7cdb1fe..ef3f858 100644 --- a/project/airtableget.py +++ b/project/airtableget.py @@ -99,10 +99,17 @@ def airtable_dashboard(): @auth_required() def display_participants(): participants = fetch_api('participants') - print("Participants: " + str(participants)) + intervenants = fetch_api('intervenants') + records = [] - for participant in participants.get_all(): - records.append(participant) + if current_user.has_role("gestionnaire"): + for participant in participants.get_all(): + records.append(participant) + elif current_user.has_role("prof"): + for participant in participants.get_all(): + mes_intervenants = [ intervenants.get(intervenant_id)['fields'].get('email') for intervenant_id in (participant['fields'].get('Intervenants') or [])] + if current_user.email in mes_intervenants: + records.append(participant) return render_template('participants/participants_list.html', records=records) @airtable_bp.route("/participants//dashboard", methods=['GET']) @@ -346,9 +353,7 @@ def presences_workshop(module_id, workshop_id): participants_prevus = [ participants.get(participant) for participant in workshop['fields']['Participants prévus']] participants_presents = [ participants.get(participant) for participant in workshop['fields']['Participants présents']] participants_presents_ids = [ participant['id'] for participant in participants_presents ] - - - + if request.method == 'POST': participants_presents_ids = request.form['presentParticipants'].split(',') workshops.update(workshop['id'], {"Participants présents": participants_presents_ids})