régler problème avec le bouton pour sauvegarder les dispo
This commit is contained in:
+22
-17
@@ -407,9 +407,18 @@ def add_disponibility():
|
||||
@users_bp.route('/disponibilities/add_bulk', methods=['POST'])
|
||||
@login_required
|
||||
def add_disponibilities_bulk():
|
||||
"""Add multiple disponibility blocks at once."""
|
||||
"""Replace the player's disponibilities with the submitted slots.
|
||||
|
||||
Performs a full replace (delete existing + insert submitted) so that
|
||||
deselected slots are correctly removed, mirroring the coach availability
|
||||
flow. This keeps the auto-save idempotent and correct.
|
||||
"""
|
||||
data = request.get_json()
|
||||
slots = data.get('slots', [])
|
||||
slots = data.get('slots', []) if data else []
|
||||
|
||||
# Clear existing disponibilities for the current player.
|
||||
PlayerDisponibility.query.filter_by(player_id=current_user.id).delete()
|
||||
|
||||
created = []
|
||||
for slot in slots:
|
||||
day_of_week = slot.get('day_of_week')
|
||||
@@ -422,21 +431,17 @@ def add_disponibilities_bulk():
|
||||
continue
|
||||
|
||||
end_time = add_30_minutes(start_time)
|
||||
existing = PlayerDisponibility.query.filter_by(
|
||||
player_id=current_user.id, day_of_week=day_of_week, start_time=start_time,
|
||||
).first()
|
||||
if not existing:
|
||||
disponibility = PlayerDisponibility(
|
||||
player_id=current_user.id, day_of_week=day_of_week,
|
||||
start_time=start_time, end_time=end_time,
|
||||
)
|
||||
db.session.add(disponibility)
|
||||
db.session.flush()
|
||||
created.append({
|
||||
'id': disponibility.id, 'day_of_week': disponibility.day_of_week,
|
||||
'day_name': DAY_NAMES[disponibility.day_of_week],
|
||||
'start_time': disponibility.start_time.strftime('%H:%M'),
|
||||
})
|
||||
disponibility = PlayerDisponibility(
|
||||
player_id=current_user.id, day_of_week=day_of_week,
|
||||
start_time=start_time, end_time=end_time,
|
||||
)
|
||||
db.session.add(disponibility)
|
||||
db.session.flush()
|
||||
created.append({
|
||||
'id': disponibility.id, 'day_of_week': disponibility.day_of_week,
|
||||
'day_name': DAY_NAMES[disponibility.day_of_week],
|
||||
'start_time': disponibility.start_time.strftime('%H:%M'),
|
||||
})
|
||||
db.session.commit()
|
||||
return jsonify({'success': True, 'created': created})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user