Utiliser la zone C et synchroniser les vacances
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
This commit is contained in:
parent
e3db1794ca
commit
6b56817dbb
3 changed files with 15 additions and 2 deletions
|
|
@ -75,6 +75,19 @@ def import_vacances_scolaires(zone="A", annee=None, user_id=None):
|
||||||
if not vacances:
|
if not vacances:
|
||||||
# Données de fallback si l'API n'est pas accessible
|
# Données de fallback si l'API n'est pas accessible
|
||||||
vacances = get_vacances_fallback(zone, annee)
|
vacances = get_vacances_fallback(zone, annee)
|
||||||
|
|
||||||
|
# Les périodes importées représentent une seule zone de référence.
|
||||||
|
# Lors d'un changement de zone, retirer uniquement les anciennes
|
||||||
|
# périodes issues d'un import officiel (jamais les périodes manuelles).
|
||||||
|
imported_closures = CollegeClosure.query.filter(
|
||||||
|
CollegeClosure.closure_type == "vacances_scolaires",
|
||||||
|
CollegeClosure.notes.like("Zone académique % — import officiel"),
|
||||||
|
).all()
|
||||||
|
for existing in imported_closures:
|
||||||
|
if not (existing.notes or "").startswith(f"Zone académique {zone} "):
|
||||||
|
db.session.delete(existing)
|
||||||
|
if imported_closures:
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
ajoutees = 0
|
ajoutees = 0
|
||||||
ignorees = 0
|
ignorees = 0
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
{% for day_num, day_name in days.items() %}<div class="col-md-6"><form method="post" action="{{ url_for('planning.assign_time_template') }}" class="input-group"><span class="input-group-text">{{ day_name }}</span><input type="hidden" name="day_of_week" value="{{ day_num }}"><select class="form-select" name="template_id" onchange="this.form.submit()"><option value="">Non travaillé</option>{% for template in templates %}<option value="{{ template.id }}" {% if assignments.get(day_num) and assignments[day_num].template_id == template.id %}selected{% endif %}>{{ template.name }}</option>{% endfor %}</select></form></div>{% endfor %}
|
{% for day_num, day_name in days.items() %}<div class="col-md-6"><form method="post" action="{{ url_for('planning.assign_time_template') }}" class="input-group"><span class="input-group-text">{{ day_name }}</span><input type="hidden" name="day_of_week" value="{{ day_num }}"><select class="form-select" name="template_id" onchange="this.form.submit()"><option value="">Non travaillé</option>{% for template in templates %}<option value="{{ template.id }}" {% if assignments.get(day_num) and assignments[day_num].template_id == template.id %}selected{% endif %}>{{ template.name }}</option>{% endfor %}</select></form></div>{% endfor %}
|
||||||
</div></div></div>
|
</div></div></div>
|
||||||
|
|
||||||
<div class="card mb-3"><div class="card-header"><strong>Importer les calendriers</strong></div><div class="card-body"><div class="row g-2"><div class="col-md-6"><form method="post" action="{{ url_for('planning.import_school_vacations') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="year" value="{{ year }}"><div class="input-group"><select class="form-select" name="zone"><option value="B">Zone B (Seine-et-Marne)</option><option value="A">Zone A</option><option value="C">Zone C</option></select><button class="btn btn-outline-primary">Importer vacances</button></div></form></div><div class="col-md-6"><form method="post" action="{{ url_for('planning.import_public_holidays') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="year" value="{{ year }}"><button class="btn btn-outline-primary">Importer jours fériés {{ year }}</button></form></div></div></div></div>
|
<div class="card mb-3"><div class="card-header"><strong>Importer les calendriers</strong></div><div class="card-body"><div class="row g-2"><div class="col-md-6"><form method="post" action="{{ url_for('planning.import_school_vacations') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="year" value="{{ year }}"><div class="input-group"><select class="form-select" name="zone"><option value="C" selected>Zone C</option><option value="B">Zone B</option><option value="A">Zone A</option></select><button class="btn btn-outline-primary">Importer vacances</button></div><small class="text-muted">Changer de zone remplace les périodes scolaires importées pour l’autre zone.</small></form></div><div class="col-md-6"><form method="post" action="{{ url_for('planning.import_public_holidays') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="year" value="{{ year }}"><button class="btn btn-outline-primary">Importer jours fériés {{ year }}</button></form></div></div></div></div>
|
||||||
|
|
||||||
<div class="card mb-3"><div class="card-header"><strong>Permanences dans les vacances</strong><small class="d-block text-muted">Sélectionnez plusieurs dates puis l’horaire type à appliquer.</small></div><div class="card-body"><form method="post" action="{{ url_for('planning.save_permanences') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="year" value="{{ year }}"><div class="row g-2 align-items-end"><div class="col-md-8"><label class="form-label">Horaire type</label><select class="form-select" name="template_id" required><option value="">Choisir…</option>{% for template in templates %}<option value="{{ template.id }}">{{ template.name }} ({{ template.start_time.strftime('%H:%M') }}–{{ template.end_time.strftime('%H:%M') }})</option>{% endfor %}</select></div><div class="col-md-4"><button class="btn btn-success w-100" {% if not templates %}disabled{% endif %}>Affecter les dates sélectionnées</button></div></div><div class="row g-2 mt-2">{% for option in permanence_options %}<div class="col-xl-3 col-lg-4 col-md-6"><label class="border rounded p-2 d-block"><input type="checkbox" name="work_dates" value="{{ option.date.isoformat() }}" {% if option.entry %}checked{% endif %}> <strong>{{ option.date.strftime('%d/%m/%Y') }}</strong><br><small>{{ option.closure.name }}{% if option.entry and option.entry.template %} · {{ option.entry.template.name }}{% endif %}</small></label></div>{% else %}<div class="col-12 text-muted">Aucune période de vacances importée pour cette période. Importez d’abord le calendrier scolaire.</div>{% endfor %}</div></form></div></div>
|
<div class="card mb-3"><div class="card-header"><strong>Permanences dans les vacances</strong><small class="d-block text-muted">Sélectionnez plusieurs dates puis l’horaire type à appliquer.</small></div><div class="card-body"><form method="post" action="{{ url_for('planning.save_permanences') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="year" value="{{ year }}"><div class="row g-2 align-items-end"><div class="col-md-8"><label class="form-label">Horaire type</label><select class="form-select" name="template_id" required><option value="">Choisir…</option>{% for template in templates %}<option value="{{ template.id }}">{{ template.name }} ({{ template.start_time.strftime('%H:%M') }}–{{ template.end_time.strftime('%H:%M') }})</option>{% endfor %}</select></div><div class="col-md-4"><button class="btn btn-success w-100" {% if not templates %}disabled{% endif %}>Affecter les dates sélectionnées</button></div></div><div class="row g-2 mt-2">{% for option in permanence_options %}<div class="col-xl-3 col-lg-4 col-md-6"><label class="border rounded p-2 d-block"><input type="checkbox" name="work_dates" value="{{ option.date.isoformat() }}" {% if option.entry %}checked{% endif %}> <strong>{{ option.date.strftime('%d/%m/%Y') }}</strong><br><small>{{ option.closure.name }}{% if option.entry and option.entry.template %} · {{ option.entry.template.name }}{% endif %}</small></label></div>{% else %}<div class="col-12 text-muted">Aucune période de vacances importée pour cette période. Importez d’abord le calendrier scolaire.</div>{% endfor %}</div></form></div></div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ def save_time_entry():
|
||||||
def import_school_vacations():
|
def import_school_vacations():
|
||||||
from app_new.lib_ext.vacances_scolaires import import_vacances_scolaires
|
from app_new.lib_ext.vacances_scolaires import import_vacances_scolaires
|
||||||
year = request.form.get("year", date.today().year, type=int)
|
year = request.form.get("year", date.today().year, type=int)
|
||||||
added, ignored, errors = import_vacances_scolaires(request.form.get("zone", "B"), year, current_user.id)
|
added, ignored, errors = import_vacances_scolaires(request.form.get("zone", "C"), year, current_user.id)
|
||||||
flash(f"Vacances importées : {added} ajoutée(s), {ignored} déjà présente(s)." + (f" {len(errors)} erreur(s)." if errors else ""), "warning" if errors else "success")
|
flash(f"Vacances importées : {added} ajoutée(s), {ignored} déjà présente(s)." + (f" {len(errors)} erreur(s)." if errors else ""), "warning" if errors else "success")
|
||||||
return _redirect(year)
|
return _redirect(year)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue