diff --git a/project/airtableget.py b/project/airtableget.py index 61f5f2d..ef3f858 100644 --- a/project/airtableget.py +++ b/project/airtableget.py @@ -99,41 +99,53 @@ 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/", methods=['GET']) + +@airtable_bp.route("/participants//dashboard", methods=['GET']) @auth_required() -def display_participant_form(participant_number): - participants = fetch_api('participants') +def participant_dashboard(participant_id): + participant = fetch_api('participants').get(participant_id) + sessions_ids = participant['fields']['Sessions'] sessions = fetch_api('sessions') - participant = participants.search('Number', participant_number)[0] - return render_template('participants/participants_detail.html', record=participant, sessions=sessions) + sessions = [ sessions.get(session_id) for session_id in sessions_ids ] -@airtable_bp.route('/participants//edit', methods=['GET', 'POST']) + formation_ids = [ session['fields']['Formations'][0] for session in sessions ] + formations = fetch_api('formations') + formations = [ formations.get(formation_id) for formation_id in formation_ids] + + return render_template('participants/participant_dashboard.html', participant=participant, sessions=sessions, formations=formations) + +@airtable_bp.route("/participants//profile", methods=['GET', 'POST']) @auth_required() -def edit_participant(participant_number): +def participant_profile(participant_id): participants = fetch_api('participants') - record = participants.search('Number', participant_number)[0] - record_id = record['id'] + participant = participants.get(participant_id) + if request.method == 'POST': data = {} - if request.form['first_name'] != record['fields']['Prénom']: + if request.form['first_name'] != participant['fields']['Prénom']: data['Prénom'] = request.form['first_name'] - if request.form['family_name'] != record['fields']['Nom']: + if request.form['family_name'] != participant['fields']['Nom de famille']: data['Nom de famille'] = request.form['family_name'] - data['CNI'] = update_airtable_attachment_field(request, record, "CNI") - data["Attestation Pôle Emploi"] = update_airtable_attachment_field(request, record, "Attestation", "Attestation Pôle Emploi") + data['CNI'] = update_airtable_attachment_field(request, participant, "CNI") + data["Attestation Pôle Emploi"] = update_airtable_attachment_field(request, participant, "Attestation", "Attestation Pôle Emploi") if data: - participants.update(record_id, data) - return redirect(url_for('airtable.display_participant_form', participant_number=participant_number)) + participants.update(participant_id, data) + return redirect(url_for('airtable.participant_profile', participant_id=participant_id)) else: - return render_template('airtable/participants/participants_edit.html', record=record) + return render_template('participants/participant_profile.html', record = participant) def is_session_active(sessions, formations): formation_id = request.args.get('formation_id') @@ -236,32 +248,8 @@ def show_workshops(module_id): if modules.get(module_id)['fields'].get("Participants", []): participants_prevus = [ participant for participant in participants.get_all() if participant['id'] in modules.get(module_id)['fields']['Participants']] - participants_presents = [] - if modules.get(module_id)['fields'].get("Participants présents", []): - participants_presents = [ participant for participant in participants.get_all() if participant['id'] in modules.get(module_id)['fields']['Participants présents']] - - return render_template('/airtable/workshops/workshops.html', module = module, workshops = workshops, intervenants = intervenants, participants = participants_prevus, presents = participants_presents) - -############## affichage des participants par module session d'un prof -@airtable_bp.route('/participants/module/', methods=['GET']) -@auth_required() -def display_module_participants(module_id, intervenant_id): - modules = fetch_api('modules') - # Authentifier l'utilisateur pour déterminer son rôle (professeur ou autre) - user = current_user() - - # Vérifier si l'utilisateur est un professeur - if user.role == 'prof': - module = modules.get(module_id,intervenant_id) - if module: - # Récupérer la liste des participants prévus pour ce module - participants = fetch_api('participants') - participants_prevus = [participants.get(participant_id)['fields']['Nom'] for participant_id in module['fields']['Participants prévus']] - - return render_template('module_participants.html', participants=participants_prevus) - else: - return "Accès non autorisé" - + return render_template('/airtable/workshops/workshops.html', module = module, workshops = workshops, intervenants = intervenants, participants = participants_prevus) + ######### Affichage de la fiche d'une séance @airtable_bp.route('/modules//workshops/', methods=['GET', 'POST']) @@ -291,7 +279,7 @@ def show_workshop(module_id, workshop_id): return redirect(url_for('airtable.show_workshop', module_id=module_id, workshop_id=workshop_id)) else: - return render_template('/airtable/workshops/workshop.html', workshop = workshop, module = module, module_base = module_base, participants = participants_prevus ) + return render_template('/airtable/workshops/workshop.html', workshop = workshop, module = module, module_base = module_base, participants = participants_prevus) ####### Evaluations individuelles pour une séance @airtable_bp.route('/modules//workshops//', methods=['GET', 'POST']) @@ -365,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}) @@ -386,7 +372,17 @@ def show_module(): data_module = [] for module in modules.get_all(): - data_module.append(module) + if current_user.has_role("gestionnaire"): + data_module.append(module) + elif current_user.has_role("prof"): + if module['fields'].get('Intervenants'): + for intervenant in module['fields']['Intervenants']: + intervenant = intervenants.get(intervenant) + print("intervenant testé : " + str(intervenant)) + print("current user email : " + current_user.email) + if intervenant['fields'].get('email') and intervenant['fields']['email'] == current_user.email: + data_module.append(module) + break return render_template('/airtable/modules/modules.html' , records = data_module, sessions = sessions, intervenants = intervenants, participants = participants ) diff --git a/project/app.py b/project/app.py index e190800..b3b6a94 100644 --- a/project/app.py +++ b/project/app.py @@ -26,20 +26,32 @@ from .views import views_bp from .airtableget import airtable_bp fa = FontAwesome() +#debug_mode = False def create_app(): app = Flask(__name__, instance_relative_config=True) app.config['MAX_CONTENT_LENGTH'] = 20 * 1024 * 1024 - + if "--debug" in sys.argv: app.config.from_object(DevelopmentConfig) - debug_mode = True + print("Debug Mode " + str(app.config['DEBUG'])) + #debug_mode = False else: app.config.from_object(ProductionConfig) + print("Debug Mode " + str(app.config['DEBUG'])) google_blueprint = create_google_blueprint(app) app.register_blueprint(google_blueprint, url_prefix="/login") - app.add_url_rule('/authorized', view_func=authorized) - debug_mode = False + #debug_mode = False + + @app.context_processor + def context_processor(): + google_login_url = False + def google_login_url(): + if app.debug: + print("sorry, in debug mode, no google login available") + return None + return url_for("google.login") + return dict(google_login_url=google_login_url) global db_session with app.app_context(): @@ -63,7 +75,7 @@ def create_app(): def define_routes(app): @app.route('/authorized') def authorized(): - if debug_mode: + if app.config['DEBUG'] == True: return "Not available in development mode", 404 if not google.authorized: return redirect(url_for("google.login")) @@ -79,7 +91,13 @@ def define_routes(app): else: name = email - if email not in app.config['ALLOWED_USERS']: + def is_email_authorized(email): + for user in app.config['ALLOWED_USERS']: + if user[0] == email: + return True + return False + + if not is_email_authorized(email): flash("Your email is not authorized.", "danger") return redirect(url_for("views.home")) @@ -93,6 +111,8 @@ def define_routes(app): login_user(user) session['logged_in_with_google'] = True return redirect(url_for("views.home")) + app.add_url_rule('/authorized', view_func=authorized) + @app.route("/logout") @auth_required() @@ -109,7 +129,6 @@ def create_google_blueprint(app): ) return google_blueprint - def generate_random_password(length=12): characters = string.ascii_letters + string.digits + string.punctuation return ''.join(random.choice(characters) for i in range(length)) @@ -133,15 +152,4 @@ def create_users(app, user_datastore): app = create_app() if __name__ == "__main__": - app.run() - - - - - - - - - - - + app.run() \ No newline at end of file diff --git a/project/config.py b/project/config.py index 79ff161..7e10f7d 100644 --- a/project/config.py +++ b/project/config.py @@ -6,7 +6,6 @@ basedir = os.path.abspath(os.path.dirname(__file__)) load_dotenv(os.path.join(os.path.dirname(basedir), '.env')) class Config(): - DEBUG = False TESTING = False CSRF_ENABLED = True SQLALCHEMY_TRACK_MODIFICATIONS = False diff --git a/project/static/js/edit_form.js b/project/static/js/edit_form.js index f24c6c4..906c16d 100644 --- a/project/static/js/edit_form.js +++ b/project/static/js/edit_form.js @@ -10,7 +10,9 @@ document.querySelectorAll('[id^="editButton"]').forEach(function(editButton) { } for (var i = 0; i < form.elements.length; i++) { var element = form.elements[i]; - element.readOnly = !element.readOnly; + if (element.hasAttribute('readOnly')) { + element.readOnly = !element.readOnly + } } diff --git a/project/templates/airtable/participants/participant_dashboard.html b/project/templates/airtable/participants/participant_dashboard.html new file mode 100644 index 0000000..674ece8 --- /dev/null +++ b/project/templates/airtable/participants/participant_dashboard.html @@ -0,0 +1,26 @@ +{% extends 'airtable_base.html' %} + +{% block content %} +{{ super() }} + +
+
+
+

Dashboard pour {{ participant['fields']['Nom complet']}}

+

Sessions

+
    + {% for session in sessions %} +
  • {{ session.fields.Name }}
  • + {% endfor %} +
+

Formations

+
    + {% for formation in formations %} +
  • {{ formation.fields.Name }}
  • + {% endfor %} +
+

+
+
+ +{% endblock %} \ No newline at end of file diff --git a/project/templates/airtable/participants/participants_edit.html b/project/templates/airtable/participants/participant_profile.html similarity index 92% rename from project/templates/airtable/participants/participants_edit.html rename to project/templates/airtable/participants/participant_profile.html index b41e2cd..0369462 100644 --- a/project/templates/airtable/participants/participants_edit.html +++ b/project/templates/airtable/participants/participant_profile.html @@ -4,7 +4,7 @@

Edit Participant

-
+
@@ -12,7 +12,7 @@
-

+

@@ -24,7 +24,7 @@
-

+

@@ -114,8 +114,12 @@
- +
+
+ +
+
{% endblock %} \ No newline at end of file diff --git a/project/templates/airtable/participants/participants_detail.html b/project/templates/airtable/participants/participants_detail.html deleted file mode 100644 index 21046e0..0000000 --- a/project/templates/airtable/participants/participants_detail.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends 'airtable_base.html' %} - -{% block content %} -{{ super() }} -
-
-
-

Participant: {{ record['fields']['Nom complet'] }}

-
    -
  • {{ record['fields']['Nom'] }}
  • -
  • {{ record['fields']['Prénom'] }}
  • -
  • {{ record['fields']['Sexe']}}
  • -
  • {{ record['fields']['Date de naissance'] }}
  • -
  • {{ record['fields']['Adresse complète'] }}
  • -
  • {{ sessions.get(record['fields']['Session Passe Numérique'][0])['fields']['Name']}}
  • -
  • {{ sessions.get(record['fields']['Session du Bac +1'][0])['fields']['Name']}}
  • -
-
-
-
-{% endblock %} \ No newline at end of file diff --git a/project/templates/airtable/participants/participants_list.html b/project/templates/airtable/participants/participants_list.html index c95c851..295a21e 100644 --- a/project/templates/airtable/participants/participants_list.html +++ b/project/templates/airtable/participants/participants_list.html @@ -26,10 +26,9 @@ {% endfor %}
-