recuperation de session avec gestion de filtre
This commit is contained in:
parent
4e3d3aa36f
commit
13385b233a
@ -7,6 +7,7 @@ import requests
|
||||
import os
|
||||
from base64 import b64encode
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
load_dotenv(os.path.join(os.path.dirname(basedir), '.env'))
|
||||
@ -142,13 +143,24 @@ def is_session_active():
|
||||
sessions = fetch_api('sessions')
|
||||
formations = fetch_api('formations').get_all()
|
||||
formation_id = request.args.get('formation_id')
|
||||
#print("formations", formations)
|
||||
data_session = []
|
||||
|
||||
for sessions in sessions.get_all():
|
||||
if not formation_id or sessions['fields'].get('Formation', [])[0] == formation_id:
|
||||
data_session.append(sessions)
|
||||
for session in sessions.get_all():
|
||||
date_debut = datetime.strptime(session['fields'].get('date_debut'), '%Y-%m-%d')
|
||||
date_fin = datetime.strptime(session['fields'].get('date_fin'), '%Y-%m-%d')
|
||||
#print("date_debut: " + str(date_debut))
|
||||
|
||||
if date_debut < datetime.now() and date_fin > datetime.now():
|
||||
session['fields']['Statut'] = 'Active'
|
||||
elif date_debut > datetime.now():
|
||||
session['fields']['Statut'] = 'A venir'
|
||||
elif date_fin < datetime.now():
|
||||
session['fields']['Statut'] = 'Terminée'
|
||||
if not formation_id or session['fields'].get('Formation', [None])[0] == formation_id:
|
||||
data_session.append(session)
|
||||
return render_template('/airtable/sessions/sessions_list.html', sessions=data_session, formations=formations)
|
||||
|
||||
|
||||
|
||||
@airtable_bp.route('/my_modules', methods=['GET'])
|
||||
@auth_required()
|
||||
|
||||
21
project/static/js/sessions_list.js
Normal file
21
project/static/js/sessions_list.js
Normal file
@ -0,0 +1,21 @@
|
||||
console.log("here in session_list.js");
|
||||
|
||||
// filter sessions by formation
|
||||
function filterSessionsByFormation() {
|
||||
var formation_id = (document.getElementById('formation_id').value);
|
||||
//console.log('formation_id:', formation_id);
|
||||
var sessions = document.getElementsByClassName('data-formation-id');
|
||||
// console.log('sessions:', sessions)
|
||||
|
||||
for (var i = 0; i < sessions.length; i++) {
|
||||
var session = sessions[i];
|
||||
var id = (session.getAttribute('data-formation-id'));
|
||||
//console.log('id:', id);
|
||||
if (formation_id === "" || id === (formation_id)) {
|
||||
session.style.display = 'table-row';
|
||||
} else {
|
||||
session.style.display = 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,19 +3,20 @@
|
||||
{% block content %}
|
||||
<div class="columns is-multiline">
|
||||
{% for record in records %}
|
||||
<div class="column is-one-third">
|
||||
<div class="column is-one-fifth">
|
||||
<div class="card m-4">
|
||||
<div class="card-content">
|
||||
<div class="media">
|
||||
<div class="media-left">
|
||||
<div class="media-right">
|
||||
<figure class="image is-128x128">
|
||||
<img src="https://bulma.io/images/placeholders/96x96.png" alt="Placeholder image">
|
||||
</figure>
|
||||
</div>
|
||||
<div class="media-content mt-4">
|
||||
<p class="title is-4 has-text-black">{{ record['fields']['Nom complet'] }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="media-content">
|
||||
<p class="title is-4 has-text-black mb-4">{{ record['fields']['Nom complet'] }}</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="content">
|
||||
<p>{{ record['fields']['Adresse complète'] }}</p>
|
||||
|
||||
@ -2,20 +2,14 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
||||
<!-- liste deroulante qui affiche pour chaque formation la session -->
|
||||
<form method="get">
|
||||
<select name="formation_id" onchange="this.form.submit()">
|
||||
<option value="">Toutes les formations</option>
|
||||
{% for formation in formations %}
|
||||
<option value="{{ formation['id'] }}"
|
||||
{% if request.args.get('formation_id') == formation['id'] %}
|
||||
selected
|
||||
{% endif %}
|
||||
>{{ formation['fields']['Name'] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</form>
|
||||
<select id="formation_id" onchange="filterSessionsByFormation()">
|
||||
<option value="">Toutes les formations</option>
|
||||
{% for formation in formations %}
|
||||
<option value="{{ formation['id'] }}">{{ formation['fields']['Name'] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<br><br>
|
||||
@ -25,25 +19,33 @@
|
||||
<tr>
|
||||
<th>Nom de la session</th>
|
||||
<th>Formation</th>
|
||||
<th>Date de debut</th>
|
||||
<th>Date de fin</th>
|
||||
<th>Statut</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for session in sessions %}
|
||||
<tr>
|
||||
<td>{{ session['fields']['Name'] }}</td>
|
||||
<td>
|
||||
{% for formation in formations %}
|
||||
{% if formation['id'] == session['fields']['Formation'][0] %}
|
||||
{{ formation['fields']['Name'] }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>{{ session['fields']['Statut'] }}</td>
|
||||
</tr>
|
||||
<tr class="data-formation-id" data-formation-id="{{ session['fields']['Formation'][0] }}">
|
||||
<td>{{ session['fields']['Name'] }}</td>
|
||||
<td>
|
||||
{% for formation in formations %}
|
||||
{% if formation['id'] == session['fields']['Formation'][0] %}
|
||||
{{ formation['fields']['Name'] }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td>{{ session['fields']['date_debut'] }}</td>
|
||||
<td>{{ session['fields']['date_fin'] }}</td>
|
||||
<td>{{ session['fields']['Statut'] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
{% endblock content %}
|
||||
|
||||
{% block scripts %}
|
||||
{{ super() }}
|
||||
<script src="{{ url_for('static', filename='js/sessions_list.js') }}"></script>
|
||||
{% endblock scripts %}
|
||||
Loading…
x
Reference in New Issue
Block a user