ajout d'un boite de reception et dépot des documents (pour les contrats)

This commit is contained in:
cedrick2711
2026-07-15 18:01:00 -04:00
parent ca60f001e2
commit a129f218b6
11 changed files with 472 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
*.env
instance/
documents/
__pycache__/
*.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
+54
View File
@@ -327,3 +327,57 @@ class MatchParticipant(db.Model):
added_at = db.Column(db.DateTime, default=datetime.utcnow)
player = db.relationship('User')
class Contract(db.Model):
"""Contract documents for players to sign."""
__tablename__ = 'contracts'
id = db.Column(db.Integer, primary_key=True)
player_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
team_id = db.Column(db.Integer, db.ForeignKey('org_teams.id'), nullable=True)
uploaded_by_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
# File information
original_filename = db.Column(db.String(255), nullable=False)
stored_filename = db.Column(db.String(255), nullable=False)
file_path = db.Column(db.String(500), nullable=False)
# Signed contract information
signed_filename = db.Column(db.String(255), nullable=True)
signed_file_path = db.Column(db.String(500), nullable=True)
# Status and metadata
status = db.Column(db.String(20), default='pending') # pending, signed
notes = db.Column(db.Text, nullable=True)
uploaded_at = db.Column(db.DateTime, default=datetime.utcnow)
signed_at = db.Column(db.DateTime, nullable=True)
# Relationships
player = db.relationship('User', foreign_keys=[player_id], backref='contracts')
team = db.relationship('OrgTeam', foreign_keys=[team_id])
uploader = db.relationship('User', foreign_keys=[uploaded_by_id])
def can_view(self, user):
"""Check if a user can view this contract."""
# Player can always view their own contracts
if user.id == self.player_id:
return True
# President can view all contracts
if user.role == 'president':
return True
# Manager can view contracts for players on their teams
if user.role == 'manager':
player = User.query.get(self.player_id)
if player and player.team_id:
return True
# Coach can view contracts for players on their team
if user.role == 'coach':
org_team = OrgTeam.query.filter_by(coach_id=user.id).first()
if org_team and (not self.team_id or self.team_id == org_team.id):
return True
return False
def can_upload_signed(self, user):
"""Check if a user can upload a signed contract."""
# Only the player can upload their signed contract
return user.id == self.player_id
Binary file not shown.
+202 -4
View File
@@ -1,7 +1,9 @@
from flask import Blueprint, render_template, redirect, url_for, flash, request, jsonify
import os
from flask import Blueprint, render_template, redirect, url_for, flash, request, jsonify, send_file
from flask_login import login_required, current_user
from extensions import db, hash_password
from models import User, ROLES, ESPORT_GAMES, PlayerDisponibility, UserGamertag, GAME_PLATFORMS
from models import User, ROLES, ESPORT_GAMES, PlayerDisponibility, UserGamertag, GAME_PLATFORMS, Contract, OrgTeam
from werkzeug.utils import secure_filename
from datetime import datetime, timedelta
users_bp = Blueprint('users', __name__, url_prefix='/users')
@@ -147,7 +149,11 @@ def create_user():
@users_bp.route('/profile')
@login_required
def profile():
return render_template('pages/profile.html', user=current_user)
# Get contracts ordered by uploaded_at desc for the current user
contracts = None
if current_user.role == 'player':
contracts = Contract.query.filter_by(player_id=current_user.id).order_by(Contract.uploaded_at.desc()).all()
return render_template('pages/profile.html', user=current_user, contracts=contracts)
@users_bp.route('/profile/edit', methods=['GET', 'POST'])
@login_required
@@ -378,4 +384,196 @@ def delete_disponibility(disponibility_id):
db.session.delete(disponibility)
db.session.commit()
return jsonify({'success': True})
return jsonify({'success': True})
# Contract Dropbox Functions
def can_manage_player_contract(user, player_id):
"""Check if a user can upload contracts for a specific player."""
# President can manage all contracts
if user.role == 'president':
return True
# Manager can upload contracts for any player
if user.role == 'manager':
return True
# Coach can upload contracts only for players on their team
if user.role == 'coach':
org_team = OrgTeam.query.filter_by(coach_id=user.id).first()
if org_team:
player = User.query.get(player_id)
if player and player.team_id == org_team.id:
return True
return False
@users_bp.route('/contracts')
@login_required
def list_contracts():
"""View contracts for the current user (player) or players they manage."""
contracts = None
if current_user.role == 'player':
# Players see their own contracts
contracts = Contract.query.filter_by(player_id=current_user.id).order_by(Contract.uploaded_at.desc()).all()
elif current_user.role in ['president', 'manager', 'coach']:
# Superiors see contracts for players on their teams
players = []
if current_user.role == 'coach':
org_team = OrgTeam.query.filter_by(coach_id=current_user.id).first()
if org_team:
players = User.query.filter_by(role='player', team_id=org_team.id).all()
else: # president or manager
players = User.query.filter_by(role='player').all()
if players:
player_ids = [p.id for p in players]
contracts = Contract.query.filter(Contract.player_id.in_(player_ids)).order_by(Contract.uploaded_at.desc()).all()
return render_template('pages/contracts.html', contracts=contracts, players=players if current_user.role in ['president', 'manager', 'coach'] else None)
@users_bp.route('/contracts/upload', methods=['GET', 'POST'])
@login_required
def upload_contract():
"""Upload a contract for a player."""
if current_user.role not in ['president', 'manager', 'coach']:
flash('Only presidents, managers, and coaches can upload contracts.', 'danger')
return redirect(url_for('users.list_contracts'))
# Get players this user can manage
if current_user.role == 'coach':
org_team = OrgTeam.query.filter_by(coach_id=current_user.id).first()
players = User.query.filter_by(role='player', team_id=org_team.id).all() if org_team else []
else:
players = User.query.filter_by(role='player').all()
if request.method == 'POST':
player_id = request.form.get('player_id', type=int)
notes = request.form.get('notes', '').strip()
if not can_manage_player_contract(current_user, player_id):
flash('You do not have permission to upload a contract for this player.', 'danger')
return redirect(url_for('users.upload_contract'))
if 'contract_file' not in request.files:
flash('No file selected.', 'danger')
return redirect(url_for('users.upload_contract'))
file = request.files['contract_file']
if file.filename == '':
flash('No file selected.', 'danger')
return redirect(url_for('users.upload_contract'))
# Create upload directory
upload_dir = os.path.join(os.getcwd(), 'documents', 'contrats signés')
os.makedirs(upload_dir, exist_ok=True)
# Get player info for folder structure
player = User.query.get_or_404(player_id)
team = OrgTeam.query.get(player.team_id) if player.team_id else None
# Create team folder if team exists
if team:
team_folder = os.path.join(upload_dir, secure_filename(team.name))
os.makedirs(team_folder, exist_ok=True)
final_dir = team_folder
else:
final_dir = upload_dir
# Generate unique filename
original_filename = secure_filename(file.filename)
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
stored_filename = f"{secure_filename(player.full_name)}_{timestamp}_{original_filename}"
stored_filename = stored_filename.replace(' ', '_')
# Save file
file_path = os.path.join(final_dir, stored_filename)
file.save(file_path)
# Create database record
contract = Contract(
player_id=player_id,
team_id=player.team_id,
uploaded_by_id=current_user.id,
original_filename=original_filename,
stored_filename=stored_filename,
file_path=file_path,
notes=notes if notes else None
)
db.session.add(contract)
db.session.commit()
flash(f'Contract uploaded successfully for {player.full_name}!', 'success')
return redirect(url_for('users.list_contracts'))
return render_template('pages/upload_contract.html', players=players)
@users_bp.route('/contracts/<int:contract_id>/upload_signed', methods=['POST'])
@login_required
def upload_signed_contract(contract_id):
"""Upload a signed contract."""
contract = Contract.query.get_or_404(contract_id)
if not contract.can_upload_signed(current_user):
flash('Only the player can upload their signed contract.', 'danger')
return redirect(url_for('users.list_contracts'))
if 'signed_file' not in request.files:
flash('No file selected.', 'danger')
return redirect(url_for('users.list_contracts'))
file = request.files['signed_file']
if file.filename == '':
flash('No file selected.', 'danger')
return redirect(url_for('users.list_contracts'))
# Generate unique filename for signed contract
original_filename = secure_filename(file.filename)
signed_filename = f"signed_{contract.stored_filename}"
# Save file
file.save(contract.file_path.replace(contract.stored_filename, signed_filename))
# Update contract record
contract.signed_filename = signed_filename
contract.signed_file_path = contract.file_path.replace(contract.stored_filename, signed_filename)
contract.status = 'signed'
contract.signed_at = datetime.utcnow()
db.session.commit()
flash('Signed contract uploaded successfully!', 'success')
return redirect(url_for('users.list_contracts'))
@users_bp.route('/contracts/<int:contract_id>/download')
@login_required
def download_contract(contract_id):
"""Download a contract file."""
contract = Contract.query.get_or_404(contract_id)
if not contract.can_view(current_user):
flash('You do not have permission to download this contract.', 'danger')
return redirect(url_for('users.list_contracts'))
return send_file(contract.file_path, as_attachment=True, download_name=contract.original_filename)
@users_bp.route('/contracts/<int:contract_id>/download_signed')
@login_required
def download_signed_contract(contract_id):
"""Download a signed contract file."""
contract = Contract.query.get_or_404(contract_id)
if not contract.can_view(current_user):
flash('You do not have permission to download this contract.', 'danger')
return redirect(url_for('users.list_contracts'))
if not contract.signed_file_path:
flash('No signed contract available.', 'danger')
return redirect(url_for('users.list_contracts'))
return send_file(contract.signed_file_path, as_attachment=True, download_name=contract.signed_filename)
+6
View File
@@ -67,6 +67,12 @@
</a>
</li>
{% endif %}
<li>
<a href="{{ url_for('users.list_contracts') }}" class="{% if request.endpoint and 'contracts' in request.endpoint %}active{% endif %}">
<i class="fas fa-file-contract"></i>
<span>Contracts</span>
</a>
</li>
<li>
<a href="{{ url_for('users.profile') }}" class="{% if request.endpoint == 'users.profile' %}active{% endif %}">
<i class="fas fa-user"></i>
+120
View File
@@ -0,0 +1,120 @@
{% extends "layouts/base.html" %}
{% block title %}Contracts - TryoutPro{% endblock %}
{% block page_title %}Contracts{% endblock %}
{% block breadcrumb %}<span class="breadcrumb">Home / <a href="{{ url_for('users.profile') }}">Profile</a> / Contracts</span>{% endblock %}
{% block header_actions %}
{% if current_user.role in ['president', 'manager', 'coach'] %}
<a href="{{ url_for('users.upload_contract') }}" class="btn btn-primary">
<i class="fas fa-upload"></i> Upload Contract
</a>
{% endif %}
{% endblock %}
{% block content %}
<div class="card">
<div class="card-header">
<h3><i class="fas fa-file-contract"></i> Contract Dropbox</h3>
</div>
<div class="card-body">
{% if contracts %}
<div class="table-container">
<table class="table">
<thead>
<tr>
<th>Player</th>
<th>Team</th>
<th>Contract</th>
<th>Status</th>
<th>Uploaded</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for contract in contracts %}
<tr>
<td>{{ contract.player.full_name }}</td>
<td>{{ contract.team.name if contract.team else 'N/A' }}</td>
<td>{{ contract.original_filename }}</td>
<td>
{% if contract.status == 'signed' %}
<span class="badge badge-success">Signed</span>
{% else %}
<span class="badge badge-warning">Pending Signature</span>
{% endif %}
</td>
<td>{{ contract.uploaded_at.strftime('%Y-%m-%d %H:%M') }}</td>
<td>
<div class="btn-group">
<a href="{{ url_for('users.download_contract', contract_id=contract.id) }}" class="btn btn-sm btn-primary" title="Download">
<i class="fas fa-download"></i> Download
</a>
{% if contract.signed_file_path %}
<a href="{{ url_for('users.download_signed_contract', contract_id=contract.id) }}" class="btn btn-sm btn-success" title="Download Signed">
<i class="fas fa-file-signature"></i> Signed
</a>
{% endif %}
{% if current_user.role == 'player' and contract.status == 'pending' %}
<button class="btn btn-sm btn-warning" onclick="showUploadSignedForm({{ contract.id }})" title="Upload Signed Contract">
<i class="fas fa-upload"></i> Return Signed
</button>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="empty-state">
<i class="fas fa-file-contract"></i>
<h4>No contracts found</h4>
{% if current_user.role == 'player' %}
<p>No contracts have been uploaded for you yet. Contact your coach or manager.</p>
{% else %}
<p>No contracts have been uploaded yet. Upload a contract using the button above.</p>
{% endif %}
</div>
{% endif %}
</div>
</div>
{% if current_user.role == 'player' %}
<!-- Upload Signed Contract Modal -->
<div id="uploadSignedModal" class="modal hidden">
<div class="modal-backdrop" onclick="hideUploadSignedForm()"></div>
<div class="modal-content">
<div class="modal-header">
<h3>Upload Signed Contract</h3>
<button class="modal-close" onclick="hideUploadSignedForm()">&times;</button>
</div>
<div class="modal-body">
<form id="uploadSignedForm" method="POST" enctype="multipart/form-data" class="form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<div class="form-group">
<label for="signed_file">Select Signed Contract File</label>
<input type="file" id="signed_file" name="signed_file" accept=".pdf,.doc,.docx,.jpg,.jpeg,.png" required>
<small class="form-text text-muted">Accepted formats: PDF, DOC, DOCX, JPG, PNG</small>
</div>
<div class="form-actions">
<button type="button" class="btn btn-secondary" onclick="hideUploadSignedForm()">Cancel</button>
<button type="submit" class="btn btn-primary">Upload Signed Contract</button>
</div>
</form>
</div>
</div>
</div>
{% endif %}
<script>
function showUploadSignedForm(contractId) {
document.getElementById('uploadSignedForm').action = '/users/contracts/' + contractId + '/upload_signed';
document.getElementById('uploadSignedModal').classList.remove('hidden');
}
function hideUploadSignedForm() {
document.getElementById('uploadSignedModal').classList.add('hidden');
}
</script>
{% endblock %}
+40 -1
View File
@@ -5,6 +5,9 @@
{% block header_actions %}
<div class="header-actions">
<a href="{{ url_for('users.list_contracts') }}" class="btn btn-sm btn-info">
<i class="fas fa-file-contract"></i> Contracts
</a>
<a href="{{ url_for('users.edit_profile') }}" class="btn btn-sm btn-primary">
<i class="fas fa-edit"></i> Edit Profile
</a>
@@ -151,5 +154,41 @@
{% endif %}
</div>
</div>
<!-- Contracts Card -->
{% if user.role == 'player' %}
<div class="card">
<div class="card-header">
<h3><i class="fas fa-file-contract"></i> My Contracts</h3>
</div>
<div class="card-body">
{% if contracts %}
<div class="detail-grid">
<div class="detail-item">
<span class="detail-label">Contracts Pending</span>
<span class="detail-value">
{% set pending = contracts | selectattr('status', 'equalto', 'pending') | list %}
<span class="badge badge-{{ 'warning' if pending|length > 0 else 'success' }}">{{ pending | length }}</span>
</span>
</div>
<div class="detail-item">
<span class="detail-label">Contracts Signed</span>
<span class="detail-value">
{% set signed = contracts | selectattr('status', 'equalto', 'signed') | list %}
<span class="badge {% if signed %}badge-success{% else %}badge-secondary{% endif %}">{{ signed | length }}</span>
</span>
</div>
</div>
<div class="mt-3">
<a href="{{ url_for('users.list_contracts') }}" class="btn btn-sm btn-primary">
<i class="fas fa-folder-open"></i> View All Contracts
</a>
</div>
{% else %}
<p class="text-muted">No contracts have been uploaded for you yet.</p>
{% endif %}
</div>
</div>
{% endif %}
</div>
{% endblock %}
{% endblock %}
+45
View File
@@ -0,0 +1,45 @@
{% extends "layouts/base.html" %}
{% block title %}Upload Contract - TryoutPro{% endblock %}
{% block page_title %}Upload Contract{% endblock %}
{% block breadcrumb %}<span class="breadcrumb">Home / <a href="{{ url_for('users.list_contracts') }}">Contracts</a> / Upload</span>{% endblock %}
{% block content %}
<div class="card">
<div class="card-header">
<h3><i class="fas fa-upload"></i> Upload Contract for Player</h3>
</div>
<div class="card-body">
<form method="POST" action="{{ url_for('users.upload_contract') }}" enctype="multipart/form-data" class="form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<div class="form-group">
<label for="player_id">Select Player</label>
<select id="player_id" name="player_id" class="form-select" required>
<option value="">-- Select a player --</option>
{% for player in players %}
<option value="{{ player.id }}">{{ player.full_name }}{% if player.org_team %} - {{ player.org_team.name }}{% endif %}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="contract_file">Contract File</label>
<input type="file" id="contract_file" name="contract_file" accept=".pdf,.doc,.docx,.jpg,.jpeg,.png" required>
<small class="form-text text-muted">Accepted formats: PDF, DOC, DOCX, JPG, PNG</small>
</div>
<div class="form-group">
<label for="notes">Notes (Optional)</label>
<textarea id="notes" name="notes" rows="3" placeholder="Add any notes about this contract..."></textarea>
</div>
<div class="form-actions">
<a href="{{ url_for('users.list_contracts') }}" class="btn btn-secondary">Cancel</a>
<button type="submit" class="btn btn-primary">
<i class="fas fa-upload"></i> Upload Contract
</button>
</div>
</form>
</div>
</div>
{% endblock %}