Ajout d'une catégorie jeux dans le tryouts, chacun des jeux offre des rôles différents pour les membres d'équipes. Remodelage du code un peu et ajout de docu
This commit is contained in:
+88
-13
@@ -1,3 +1,8 @@
|
||||
"""Match scheduling routes for managing scrimmages and matches within tryouts.
|
||||
|
||||
This module handles calendar views, match creation, and player availability.
|
||||
"""
|
||||
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash, request, jsonify
|
||||
from flask_login import login_required, current_user
|
||||
from extensions import db
|
||||
@@ -8,21 +13,35 @@ matches_bp = Blueprint('matches', __name__, url_prefix='/matches')
|
||||
|
||||
|
||||
def can_schedule_match():
|
||||
"""Check if user can schedule matches (coaches and above)."""
|
||||
"""Check if user can schedule matches (coaches and above).
|
||||
|
||||
Returns:
|
||||
bool: True if user is president, manager, coach, or scout.
|
||||
"""
|
||||
return current_user.role in ['president', 'manager', 'coach', 'scout']
|
||||
|
||||
|
||||
@matches_bp.route('/calendar')
|
||||
@login_required
|
||||
def calendar():
|
||||
"""Calendar view showing tryouts and matches."""
|
||||
"""Render the calendar view showing all tryouts and matches.
|
||||
|
||||
Returns:
|
||||
Response: Rendered calendar template.
|
||||
"""
|
||||
return render_template('pages/calendar.html')
|
||||
|
||||
|
||||
@matches_bp.route('/api/events')
|
||||
@login_required
|
||||
def api_events():
|
||||
"""API endpoint returning calendar events."""
|
||||
"""API endpoint returning calendar events for FullCalendar.
|
||||
|
||||
Returns tryout events and match events with participant information.
|
||||
|
||||
Returns:
|
||||
Response: JSON array of calendar events.
|
||||
"""
|
||||
events = []
|
||||
|
||||
# Get tryouts based on user permissions
|
||||
@@ -96,7 +115,14 @@ def api_events():
|
||||
@matches_bp.route('/api/events/<int:tryout_id>')
|
||||
@login_required
|
||||
def api_events_for_tryout(tryout_id):
|
||||
"""API endpoint returning calendar events for a specific tryout."""
|
||||
"""API endpoint returning calendar events for a specific tryout.
|
||||
|
||||
Args:
|
||||
tryout_id: The ID of the tryout to get events for.
|
||||
|
||||
Returns:
|
||||
Response: JSON array of calendar events for the tryout.
|
||||
"""
|
||||
tryout = Tryout.query.get_or_404(tryout_id)
|
||||
|
||||
# Check if user can view this tryout
|
||||
@@ -201,7 +227,18 @@ def api_events_for_tryout(tryout_id):
|
||||
|
||||
|
||||
def get_visible_tryouts_for_user():
|
||||
"""Get tryouts that the current user can see based on their role."""
|
||||
"""Get tryouts that the current user can see based on their role.
|
||||
|
||||
Permission hierarchy:
|
||||
- President: All tryouts
|
||||
- Manager: Only their created tryouts
|
||||
- Coach: Tryouts targeting their org team
|
||||
- Player: Tryouts they're registered for or matches they're in
|
||||
- Scout: All tryouts
|
||||
|
||||
Returns:
|
||||
list: Query result of Tryout objects.
|
||||
"""
|
||||
if current_user.role == 'president':
|
||||
return Tryout.query.order_by(Tryout.date).all()
|
||||
elif current_user.role == 'manager':
|
||||
@@ -236,7 +273,17 @@ def get_visible_tryouts_for_user():
|
||||
@matches_bp.route('/create/<int:tryout_id>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def create_match(tryout_id):
|
||||
"""Create a new match/scrimmage within a tryout."""
|
||||
"""Create a new match/scrimmage within a tryout.
|
||||
|
||||
GET: Render the match creation form.
|
||||
POST: Create a match with submitted details.
|
||||
|
||||
Args:
|
||||
tryout_id: The ID of the tryout to create the match for.
|
||||
|
||||
Returns:
|
||||
Response: Create form or redirect to tryout view.
|
||||
"""
|
||||
tryout = Tryout.query.get_or_404(tryout_id)
|
||||
|
||||
# Check if user can manage this tryout (president, manager, or coach)
|
||||
@@ -332,7 +379,17 @@ def create_match(tryout_id):
|
||||
@matches_bp.route('/<int:match_id>/edit', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def edit_match(match_id):
|
||||
"""Edit an existing match."""
|
||||
"""Edit an existing match.
|
||||
|
||||
GET: Render the match edit form.
|
||||
POST: Update match with submitted changes.
|
||||
|
||||
Args:
|
||||
match_id: The ID of the match to edit.
|
||||
|
||||
Returns:
|
||||
Response: Edit form or redirect to tryout view.
|
||||
"""
|
||||
match = Match.query.get_or_404(match_id)
|
||||
tryout = match.tryout
|
||||
|
||||
@@ -421,7 +478,14 @@ def edit_match(match_id):
|
||||
@matches_bp.route('/<int:match_id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
def delete_match(match_id):
|
||||
"""Delete a match."""
|
||||
"""Delete a match.
|
||||
|
||||
Args:
|
||||
match_id: The ID of the match to delete.
|
||||
|
||||
Returns:
|
||||
Response: Redirect to tryout view with status message.
|
||||
"""
|
||||
match = Match.query.get_or_404(match_id)
|
||||
tryout = match.tryout
|
||||
|
||||
@@ -438,12 +502,15 @@ def delete_match(match_id):
|
||||
def get_players_available_at_time(date_str, time_str):
|
||||
"""Get list of player IDs available at a specific date and time.
|
||||
|
||||
Checks player disponibility records to find who is available
|
||||
during the specified time block.
|
||||
|
||||
Args:
|
||||
date_str: Date in YYYY-MM-DD format
|
||||
time_str: Time in HH:MM format
|
||||
date_str: Date in YYYY-MM-DD format.
|
||||
time_str: Time in HH:MM format.
|
||||
|
||||
Returns:
|
||||
List of player IDs who are available at that time
|
||||
list: List of available player IDs.
|
||||
"""
|
||||
try:
|
||||
date_obj = datetime.strptime(date_str, '%Y-%m-%d').date()
|
||||
@@ -487,9 +554,17 @@ def get_players_available_at_time(date_str, time_str):
|
||||
@matches_bp.route('/api/available_players/<date>/<time>')
|
||||
@login_required
|
||||
def api_available_players(date, time):
|
||||
"""API endpoint to get players available at a specific date/time slot."""
|
||||
"""API endpoint to get players available at a specific date/time slot.
|
||||
|
||||
Args:
|
||||
date: Date in YYYY-MM-DD format.
|
||||
time: Time in HH:MM format.
|
||||
|
||||
Returns:
|
||||
Response: JSON with list of available player IDs.
|
||||
"""
|
||||
if not current_user.can_manage_teams() and not current_user.can_schedule_matches():
|
||||
return jsonify({'error': 'Unauthorized'}), 403
|
||||
|
||||
player_ids = get_players_available_at_time(date, time)
|
||||
return jsonify({'available_player_ids': player_ids})
|
||||
return jsonify({'available_player_ids': player_ids})
|
||||
Reference in New Issue
Block a user