fix contract
This commit is contained in:
+2
-1
@@ -32,13 +32,14 @@ def create_app(config_class=Config):
|
||||
from app.models import user
|
||||
|
||||
# Register blueprints
|
||||
from app.routes import auth_bp, classrooms_bp, main_bp, schedule_bp, genetic_bp
|
||||
from app.routes import auth_bp, classrooms_bp, main_bp, schedule_bp, genetic_bp, genetic_web_bp
|
||||
|
||||
app.register_blueprint(auth_bp, url_prefix="/")
|
||||
app.register_blueprint(classrooms_bp, url_prefix="/classrooms")
|
||||
app.register_blueprint(main_bp, url_prefix="/")
|
||||
app.register_blueprint(schedule_bp, url_prefix="/schedule")
|
||||
app.register_blueprint(genetic_bp)
|
||||
app.register_blueprint(genetic_web_bp)
|
||||
|
||||
# Babel language selector
|
||||
@app.context_processor
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ class User(UserMixin, db.Model):
|
||||
|
||||
def is_admin(self):
|
||||
"""Check if user is admin"""
|
||||
return self.role == 'admin'
|
||||
return self.role == 'ADMIN'
|
||||
|
||||
def update_last_login(self):
|
||||
"""Update last login timestamp"""
|
||||
|
||||
@@ -2,6 +2,6 @@ from .main import main_bp
|
||||
from .auth import auth_bp
|
||||
from .classrooms import classrooms_bp
|
||||
from .schedule import schedule_bp
|
||||
from .genetic_algorithm import genetic_bp
|
||||
from .genetic_algorithm import genetic_bp, genetic_web_bp
|
||||
|
||||
__all__ = ['main_bp', 'auth_bp', 'classrooms_bp', 'schedule_bp', 'genetic_bp']
|
||||
__all__ = ['main_bp', 'auth_bp', 'classrooms_bp', 'schedule_bp', 'genetic_bp', 'genetic_web_bp']
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import Blueprint, request, jsonify, current_app
|
||||
from flask import Blueprint, request, jsonify, current_app, render_template
|
||||
from datetime import datetime, timedelta
|
||||
from app.models.genetic_algorithm import ReservationOptimizer
|
||||
from app.models.reservation import Reservation, ReservationStatus
|
||||
@@ -40,7 +40,7 @@ def optimize_reservations():
|
||||
return jsonify({'error': 'Invalid end_date format. Use ISO format.'}), 400
|
||||
|
||||
# Check if user has permission (admin or teacher)
|
||||
if current_user.role not in ['admin', 'teacher']:
|
||||
if current_user.role not in ['ADMIN', 'teacher']:
|
||||
return jsonify({'error': 'Insufficient permissions to optimize reservations'}), 403
|
||||
|
||||
# Initialize optimizer and run optimization
|
||||
@@ -84,7 +84,7 @@ def apply_optimization():
|
||||
return jsonify({'error': 'reservations must be a list'}), 400
|
||||
|
||||
# Check if user has permission
|
||||
if current_user.role not in ['admin', 'teacher']:
|
||||
if current_user.role not in ['ADMIN', 'teacher']:
|
||||
return jsonify({'error': 'Insufficient permissions to apply reservations'}), 403
|
||||
|
||||
# Initialize optimizer and apply reservations
|
||||
@@ -124,7 +124,7 @@ def preview_optimization():
|
||||
return jsonify({'error': 'commission_ids must be a non-empty list'}), 400
|
||||
|
||||
# Check if user has permission
|
||||
if current_user.role not in ['admin', 'teacher']:
|
||||
if current_user.role not in ['ADMIN', 'teacher']:
|
||||
return jsonify({'error': 'Insufficient permissions to preview optimization'}), 403
|
||||
|
||||
# Initialize optimizer and run optimization
|
||||
@@ -171,7 +171,7 @@ def get_commissions():
|
||||
"""Get available commissions for optimization"""
|
||||
try:
|
||||
# Check if user has permission
|
||||
if current_user.role not in ['admin', 'teacher']:
|
||||
if current_user.role not in ['ADMIN', 'teacher']:
|
||||
return jsonify({'error': 'Insufficient permissions'}), 403
|
||||
|
||||
from app.models.subject import Commission, Subject
|
||||
@@ -201,7 +201,7 @@ def get_algorithm_status():
|
||||
"""Get genetic algorithm configuration status"""
|
||||
try:
|
||||
# Check if user has permission
|
||||
if current_user.role not in ['admin', 'teacher']:
|
||||
if current_user.role not in ['ADMIN']:
|
||||
return jsonify({'error': 'Insufficient permissions'}), 403
|
||||
|
||||
# Get system status
|
||||
@@ -238,4 +238,18 @@ def get_algorithm_status():
|
||||
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Error getting algorithm status: {str(e)}")
|
||||
return jsonify({'error': f'Status check failed: {str(e)}'}), 500
|
||||
return jsonify({'error': f'Status check failed: {str(e)}'}), 500
|
||||
|
||||
|
||||
# Web interface route (without API prefix)
|
||||
genetic_web_bp = Blueprint('genetic_algorithm_web', __name__)
|
||||
|
||||
|
||||
@genetic_web_bp.route('/genetic-optimizer')
|
||||
@login_required
|
||||
def genetic_optimizer():
|
||||
"""Render the genetic algorithm optimizer interface"""
|
||||
if current_user.role not in ['ADMIN']:
|
||||
return render_template('auth/403.html'), 403
|
||||
|
||||
return render_template('genetic_optimizer.html')
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
from flask import Blueprint, render_template, jsonify, redirect, url_for, session, request
|
||||
from flask import Blueprint, render_template, jsonify, redirect, url_for, session, request, flash
|
||||
from flask_login import login_required, current_user
|
||||
from app.models.reservation import Reservation
|
||||
from app.models.classroom import Classroom
|
||||
@@ -112,7 +112,7 @@ def dashboard_stats_api():
|
||||
@login_required
|
||||
def genetic_optimizer():
|
||||
"""Serve the genetic algorithm optimization interface"""
|
||||
if current_user.role not in ['admin', 'teacher']:
|
||||
if current_user.role not in ['ADMIN']:
|
||||
flash('You do not have permission to access the optimization tool.', 'danger')
|
||||
return redirect(url_for('main.dashboard'))
|
||||
|
||||
|
||||
@@ -119,12 +119,9 @@
|
||||
<a href="{{ url_for('schedule.today_schedule') }}" class="btn btn-outline-info">
|
||||
<i class="bi bi-calendar-today"></i> Today's Schedule
|
||||
</a>
|
||||
{# Access to Genetic Algorithm Optimizer - Only for admin/teacher roles #}
|
||||
{% if current_user and current_user.role in ['ADMIN'] %}
|
||||
<a href="{{ url_for('genetic_algorithm.genetic_optimizer') }}" class="btn btn-info text-white">
|
||||
<a href="{{ url_for('genetic_algorithm_web.genetic_optimizer') }}" class="btn btn-info text-white">
|
||||
<i class="bi bi-cpu"></i> AI Room Optimizer
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="{{ url_for('schedule.calendar_view') }}" class="btn btn-outline-secondary">
|
||||
<i class="bi bi-calendar3"></i> View Calendar
|
||||
</a>
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
<a href="{{ url_for('schedule.list_reservations') }}" class="btn btn-outline-primary ms-2">
|
||||
<i class="bi bi-list"></i> All Reservations
|
||||
</a>
|
||||
{# Access to Genetic Algorithm Optimizer - Only for admin/teacher roles #}
|
||||
{# Access to Genetic Algorithm Optimizer - Only for admin/teacher roles #}
|
||||
{% if current_user and current_user.role in ['admin', 'teacher'] %}
|
||||
<a href="{{ url_for('genetic_algorithm.genetic_optimizer') }}" class="btn btn-info text-white ms-2">
|
||||
<a href="{{ url_for('main.genetic_optimizer') }}" class="btn btn-info text-white ms-2">
|
||||
<i class="bi bi-cpu"></i> AI Optimizer
|
||||
</a>
|
||||
{% endif %}
|
||||
@@ -351,9 +351,9 @@
|
||||
<a href="{{ url_for('schedule.list_reservations') }}" class="btn btn-outline-primary ms-2">
|
||||
<i class="bi bi-calendar-week"></i>View Week Schedule
|
||||
</a>
|
||||
{# Access to Genetic Algorithm Optimizer - Only for admin/teacher roles #}
|
||||
{# Access to Genetic Algorithm Optimizer - Only for admin/teacher roles #}
|
||||
{% if current_user and current_user.role in ['admin', 'teacher'] %}
|
||||
<a href="{{ url_for('genetic_algorithm.genetic_optimizer') }}" class="btn btn-info text-white ms-2">
|
||||
<a href="{{ url_for('main.genetic_optimizer') }}" class="btn btn-info text-white ms-2">
|
||||
<i class="bi bi-cpu"></i> AI Room Optimizer
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user