Merge branch 'main' of git.legaragenumerique.fr:GARAGENUM/airtable-editor

main
Maryam Bint Ibrahim 1 year ago
commit c28319b698

@ -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/<participant_number>", methods=['GET'])
@airtable_bp.route("/participants/<participant_id>/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/<participant_number>/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/<participant_id>/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/<module_id>', 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/<module_id>/workshops/<workshop_id>', 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/<module_id>/workshops/<workshop_id>/<participant_id>', 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 )

@ -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()

@ -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

@ -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
}
}

@ -0,0 +1,26 @@
{% extends 'airtable_base.html' %}
{% block content %}
{{ super() }}
<div class="column is-9">
<section class="section">
<div class="container">
<h2 class="title">Dashboard pour {{ participant['fields']['Nom complet']}}</h2>
<h3>Sessions</h3>
<ul>
{% for session in sessions %}
<li>{{ session.fields.Name }}</li>
{% endfor %}
</ul>
<h3>Formations<h3>
<ul>
{% for formation in formations %}
<li>{{ formation.fields.Name }}</li>
{% endfor %}
</ul>
</div>
</section>
</div>
{% endblock %}

@ -4,7 +4,7 @@
<div class="column is-three-quarters-desktop box is-centered has-text-centered">
<h2 class="title">Edit Participant</h2>
<form method="POST" enctype="multipart/form-data" id="editRecordForm">
<form method="POST" enctype="multipart/form-data" id="detailsForm{{ record.id }}">
<div class="field is-horizontal">
<div class="field-label is-normal">
<label class="label" for="family_name">Nom de famille</label>
@ -12,7 +12,7 @@
<div class="field-body has-text-left">
<div class="field">
<div class="control">
<input id="family_name" name="family_name" value="{{ record.fields.Nom }}" required><br><br>
<input id="family_name" name="family_name" value="{{ record.fields['Nom de famille'] }}" required readonly><br><br>
</div>
</div>
</div>
@ -24,7 +24,7 @@
<div class="field-body has-text-left">
<div class="field">
<div class="control">
<input id="first_name" name="first_name" value="{{ record.fields.Prénom }}" required><br><br>
<input id="first_name" name="first_name" value="{{ record.fields.Prénom }}" required readonly><br><br>
</div>
</div>
</div>
@ -114,8 +114,12 @@
<div class="control center">
<input class="button is-primary" type="submit" value="Submit">
<button class="button is-link" type="submit" id="saveButton{{ record.id }}" style="display: none;">Save</button>
</div>
</form>
<div class="control">
<button class="button is-link" id="editButton{{ record.id }}">Edit</button>
</div>
</div>
{% endblock %}

@ -1,21 +0,0 @@
{% extends 'airtable_base.html' %}
{% block content %}
{{ super() }}
<div class="column is-9">
<section class="section">
<div class="container">
<h2 class="title">Participant: {{ record['fields']['Nom complet'] }}</h2>
<ul>
<li>{{ record['fields']['Nom'] }}</li>
<li>{{ record['fields']['Prénom'] }}</li>
<li>{{ record['fields']['Sexe']}}</li>
<li>{{ record['fields']['Date de naissance'] }}</li>
<li>{{ record['fields']['Adresse complète'] }}</li>
<li>{{ sessions.get(record['fields']['Session Passe Numérique'][0])['fields']['Name']}}</li>
<li>{{ sessions.get(record['fields']['Session du Bac +1'][0])['fields']['Name']}}</li>
</ul>
</div>
</section>
</div>
{% endblock %}

@ -26,10 +26,9 @@
{% endfor %}
</div>
</div>
<footer class="card-footer">
<a href="{{ url_for('airtable.display_participant_form', participant_number=record['fields']['Number']) }}" class="card-footer-item">Voir</a>
<a href="{{ url_for('airtable.edit_participant', participant_number=record['fields']['Number']) }}" class="card-footer-item">Edit</a>
<a href="#" class="card-footer-item">Delete</a>
<footer class="card-footer center">
<a class="button" href="{{ url_for('airtable.participant_profile', participant_id = record['id'])}}">Fiche</a>
<a class="button" href="{{ url_for('airtable.participant_dashboard', participant_id = record['id'])}}">Dashboard</a>
</footer>
</div>
</div>

@ -52,11 +52,13 @@
{% endif %}
</td>
<td>
{% if presents %}
{% for presents in presents %}
{{ present['fields']['Nom complet']}}
{% for present in workshop['fields']['Participants présents'] %}
{% for participant in participants %}
{% if participant['id'] == present %}
{{ participant['fields']['Nom complet']}}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
</td>
<td>
<a class="button is-small is-primary" href="{{ url_for('airtable.show_workshop', module_id=module['id'], workshop_id=workshop['id']) }}">Fiche-Séance</a>

@ -48,7 +48,7 @@
</div>
{% endfor %}
{% endif %}
{% if google_login_url is defined %}
{% if google_login_url() %}
<a class="button is-rounded is-primary" href="{{ google_login_url() }}" class="button is-primary">
<span class="icon">
<i class="fab fa-google"></i>

Loading…
Cancel
Save