ajout de match régulier pour les équipes et de pratiques
Ajout d'un profil public cliquable pour les utilisateurs déplacement du profil
This commit is contained in:
+45
-7
@@ -91,6 +91,12 @@ def api_events():
|
||||
start_time_str = match.start_time.strftime('%H:%M') if match.start_time else None
|
||||
end_time_str = match.end_time.strftime('%H:%M') if match.end_time else None
|
||||
|
||||
# Find current user's participant record for presence toggle
|
||||
user_participant = MatchParticipant.query.filter_by(
|
||||
match_id=match.id,
|
||||
player_id=current_user.id
|
||||
).first()
|
||||
|
||||
events.append({
|
||||
'id': f'match_{match.id}',
|
||||
'title': match.title,
|
||||
@@ -106,7 +112,9 @@ def api_events():
|
||||
'match_id': match.id,
|
||||
'start_time': start_time_str,
|
||||
'end_time': end_time_str,
|
||||
'participants': participants_str
|
||||
'participants': participants_str,
|
||||
'user_participant_id': user_participant.id if user_participant else None,
|
||||
'user_attendance_confirmed': user_participant.attendance_confirmed if user_participant else False
|
||||
}
|
||||
})
|
||||
|
||||
@@ -297,6 +305,9 @@ def create_match(tryout_id):
|
||||
all_players = [User.query.get(r.player_id) for r in registrations if User.query.get(r.player_id)]
|
||||
all_players = sorted([p for p in all_players if p], key=lambda x: x.username)
|
||||
|
||||
# Allow pre-filling the date from query param (e.g., from calendar click)
|
||||
prefill_date = request.args.get('date', '')
|
||||
|
||||
if request.method == 'POST':
|
||||
title = request.form.get('title')
|
||||
description = request.form.get('description')
|
||||
@@ -309,13 +320,13 @@ def create_match(tryout_id):
|
||||
# Start time is now mandatory
|
||||
if not start_time_str:
|
||||
flash('Start time is required. Please select a time slot.', 'danger')
|
||||
return render_template('pages/match_form.html', tryout=tryout, teams=teams, all_players=all_players)
|
||||
return render_template('pages/match_form.html', tryout=tryout, teams=teams, all_players=all_players, prefill_date=prefill_date)
|
||||
|
||||
try:
|
||||
date_obj = datetime.strptime(date_str, '%Y-%m-%d').date() if date_str else tryout.date
|
||||
except (ValueError, TypeError):
|
||||
flash('Invalid date format.', 'danger')
|
||||
return render_template('pages/match_form.html', tryout=tryout, teams=teams, all_players=all_players)
|
||||
return render_template('pages/match_form.html', tryout=tryout, teams=teams, all_players=all_players, prefill_date=prefill_date)
|
||||
|
||||
start_time = None
|
||||
end_time = None
|
||||
@@ -638,6 +649,31 @@ def edit_match(match_id):
|
||||
participants_map=participants_map)
|
||||
|
||||
|
||||
@matches_bp.route('/api/manageable-tryouts')
|
||||
@login_required
|
||||
def api_manageable_tryouts():
|
||||
"""API endpoint returning tryouts the current user can manage.
|
||||
|
||||
Used by the calendar's "Create Event" modal to populate the tryout dropdown.
|
||||
|
||||
Returns:
|
||||
Response: JSON array of {id, title, date}.
|
||||
"""
|
||||
if not can_schedule_match():
|
||||
return jsonify([])
|
||||
|
||||
tryouts = get_visible_tryouts_for_user()
|
||||
manageable = []
|
||||
for t in tryouts:
|
||||
if current_user.can_manage_this_tryout(t):
|
||||
manageable.append({
|
||||
'id': t.id,
|
||||
'title': t.title,
|
||||
'date': t.date.strftime('%Y-%m-%d')
|
||||
})
|
||||
return jsonify(manageable)
|
||||
|
||||
|
||||
@matches_bp.route('/<int:match_id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
def delete_match(match_id):
|
||||
@@ -738,7 +774,7 @@ def api_available_players(date, time):
|
||||
def toggle_presence(match_id, participant_id):
|
||||
"""Toggle the attendance_confirmed status for a match participant.
|
||||
|
||||
Accessible only to users who can manage the tryout.
|
||||
Accessible to tryout managers AND the participant themselves.
|
||||
|
||||
Args:
|
||||
match_id: The ID of the match.
|
||||
@@ -750,13 +786,15 @@ def toggle_presence(match_id, participant_id):
|
||||
match = Match.query.get_or_404(match_id)
|
||||
tryout = match.tryout
|
||||
|
||||
if not current_user.can_manage_this_tryout(tryout):
|
||||
return jsonify({'error': 'Unauthorized'}), 403
|
||||
|
||||
participant = MatchParticipant.query.get_or_404(participant_id)
|
||||
if participant.match_id != match_id:
|
||||
return jsonify({'error': 'Participant does not belong to this match'}), 400
|
||||
|
||||
# Allow the participant themselves OR a tryout manager
|
||||
is_self = participant.player_id == current_user.id
|
||||
if not is_self and not current_user.can_manage_this_tryout(tryout):
|
||||
return jsonify({'error': 'Unauthorized'}), 403
|
||||
|
||||
participant.attendance_confirmed = not participant.attendance_confirmed
|
||||
db.session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user