Fix template issues after moving to base template

- Added user=None to login, register, and config routes to prevent undefined user errors
- Updated config.html to extend base template for consistent notifications
- Simplified config.html styling to work with base template design
parent d710866e
...@@ -72,15 +72,16 @@ ...@@ -72,15 +72,16 @@
<nav class="nav"> <nav class="nav">
<a href="/dashboard" {% if active_page == 'dashboard' %}class="active"{% endif %}>Dashboard</a> <a href="/dashboard" {% if active_page == 'dashboard' %}class="active"{% endif %}>Dashboard</a>
<a href="/analyze" {% if active_page == 'analyze' %}class="active"{% endif %}>Analyze</a> <a href="/analyze" {% if active_page == 'analyze' %}class="active"{% endif %}>Analyze</a>
{% if user.get('role') == 'admin' %} {% if user and user.get('role') == 'admin' %}
<a href="/train" {% if active_page == 'train' %}class="active"{% endif %}>Train</a> <a href="/train" {% if active_page == 'train' %}class="active"{% endif %}>Train</a>
{% endif %} {% endif %}
<a href="/history" {% if active_page == 'history' %}class="active"{% endif %}>History</a> <a href="/history" {% if active_page == 'history' %}class="active"{% endif %}>History</a>
{% if user.get('role') == 'admin' %} {% if user and user.get('role') == 'admin' %}
<a href="/api_tokens" {% if active_page == 'api_tokens' %}class="active"{% endif %}>API Tokens</a> <a href="/api_tokens" {% if active_page == 'api_tokens' %}class="active"{% endif %}>API Tokens</a>
{% endif %} {% endif %}
<a href="/settings" {% if active_page == 'settings' %}class="active"{% endif %}>Settings</a> <a href="/settings" {% if active_page == 'settings' %}class="active"{% endif %}>Settings</a>
</nav> </nav>
{% if user %}
<div class="user-menu"> <div class="user-menu">
<div class="user-icon" onclick="toggleUserMenu()"> <div class="user-icon" onclick="toggleUserMenu()">
<i class="fas fa-user"></i> <i class="fas fa-user"></i>
...@@ -96,6 +97,7 @@ ...@@ -96,6 +97,7 @@
<a href="/logout">Logout</a> <a href="/logout">Logout</a>
</div> </div>
</div> </div>
{% endif %}
</div> </div>
</header> </header>
......
<!DOCTYPE html> {% extends "base.html" %}
<html>
<head> {% block title %}Configuration - VidAI{% endblock %}
<title>Configuration</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> {% block head %}
<style> <style>
body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; } .config-container { max-width: 800px; margin: 2rem auto; background: white; padding: 2rem; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.container { max-width: 800px; margin: auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); } .config-title { color: #333; text-align: center; margin-bottom: 2rem; font-size: 2rem; font-weight: 600; }
h1 { color: #333; text-align: center; } .config-form { margin-bottom: 2rem; }
nav { margin-bottom: 20px; } .form-group { margin-bottom: 1.5rem; }
nav a { margin-right: 10px; text-decoration: none; color: #007bff; } .form-group label { display: block; margin-bottom: 0.5rem; color: #374151; font-weight: 500; }
form { margin-bottom: 20px; } .form-group select { width: 100%; padding: 0.75rem; border: 2px solid #e5e7eb; border-radius: 8px; font-size: 1rem; }
label { display: block; margin-bottom: 5px; } .form-group select:focus { outline: none; border-color: #667eea; }
select { width: 100%; padding: 8px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 4px; } .btn-submit { width: 100%; padding: 0.75rem; background: #667eea; color: white; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; }
input[type="submit"] { background: #007bff; color: white; padding: 10px; border: none; border-radius: 4px; cursor: pointer; } .btn-submit:hover { background: #5a67d8; }
.user-menu { position: relative; display: inline-block; margin-left: 20px; } </style>
.user-icon { cursor: pointer; padding: 0.5rem; border-radius: 50%; background: #f4f4f4; transition: background 0.2s; } {% endblock %}
.user-icon:hover { background: #e0e0e0; }
.user-icon i { font-size: 1.2rem; color: #333; } {% block content %}
.user-dropdown { display: none; position: absolute; top: 100%; right: 0; background: white; min-width: 200px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); border-radius: 8px; z-index: 1000; border: 1px solid #ccc; } <div class="config-container">
.user-dropdown a { display: block; padding: 0.75rem 1rem; text-decoration: none; color: #333; border-bottom: 1px solid #f1f5f9; } <h1 class="config-title">Configuration</h1>
.user-dropdown a:last-child { border-bottom: none; color: #dc2626; } <form method="post" class="config-form">
.user-dropdown a:hover { background: #f4f4f4; } <div class="form-group">
</style> <label for="analysis_backend">Analysis Backend:</label>
</head> <select name="analysis_backend" id="analysis_backend">
<body> <option value="cuda" {% if current_config.get('analysis_backend') == 'cuda' %}selected{% endif %}>CUDA</option>
<div class="container"> <option value="rocm" {% if current_config.get('analysis_backend') == 'rocm' %}selected{% endif %}>ROCm</option>
<h1>Configuration</h1>
<nav><a href="/">Analysis</a> | <a href="/train">Training</a> | <a href="/config">Configuration</a>
<div class="user-menu">
<div class="user-icon" onclick="toggleUserMenu()">
<i class="fas fa-user"></i>
</div>
<div id="userDropdown" class="user-dropdown">
<a href="/admin">Menu Management</a>
<a href="/config">Configurations</a>
<a href="/logout">Logout</a>
</div>
</div>
</nav>
<form method="post">
<label>Analysis Backend:
<select name="analysis_backend">
<option value="cuda" {% if current_config.analysis_backend == 'cuda' %}selected{% endif %}>CUDA</option>
<option value="rocm" {% if current_config.analysis_backend == 'rocm' %}selected{% endif %}>ROCm</option>
</select> </select>
</label> </div>
<label>Training Backend: <div class="form-group">
<select name="training_backend"> <label for="training_backend">Training Backend:</label>
<option value="cuda" {% if current_config.training_backend == 'cuda' %}selected{% endif %}>CUDA</option> <select name="training_backend" id="training_backend">
<option value="rocm" {% if current_config.training_backend == 'rocm' %}selected{% endif %}>ROCm</option> <option value="cuda" {% if current_config.get('training_backend') == 'cuda' %}selected{% endif %}>CUDA</option>
<option value="rocm" {% if current_config.get('training_backend') == 'rocm' %}selected{% endif %}>ROCm</option>
</select> </select>
</label>
<input type="submit" value="Save Configuration">
</form>
</div> </div>
<button type="submit" class="btn-submit">Save Configuration</button>
<script> </form>
function toggleUserMenu() { </div>
const dropdown = document.getElementById('userDropdown'); {% endblock %}
dropdown.style.display = dropdown.style.display === 'block' ? 'none' : 'block'; \ No newline at end of file
}
// Close dropdown when clicking outside
window.onclick = function(event) {
const dropdown = document.getElementById('userDropdown');
const icon = document.querySelector('.user-icon');
if (!icon.contains(event.target) && !dropdown.contains(event.target)) {
dropdown.style.display = 'none';
}
}
</script>
</body>
</html>
\ No newline at end of file
...@@ -186,7 +186,7 @@ def login(): ...@@ -186,7 +186,7 @@ def login():
else: else:
flash('Invalid username or password', 'error') flash('Invalid username or password', 'error')
return render_template('login.html') return render_template('login.html', user=None)
@app.route('/register', methods=['GET', 'POST']) @app.route('/register', methods=['GET', 'POST'])
def register(): def register():
...@@ -207,7 +207,7 @@ def register(): ...@@ -207,7 +207,7 @@ def register():
else: else:
flash(message, 'error') flash(message, 'error')
return render_template('register.html') return render_template('register.html', user=None)
@app.route('/logout') @app.route('/logout')
def logout(): def logout():
...@@ -369,7 +369,7 @@ def config(): ...@@ -369,7 +369,7 @@ def config():
config_data = get_result(msg_id) config_data = get_result(msg_id)
current_config = config_data.get('data', {}) current_config = config_data.get('data', {})
return render_template('config.html', current_config=current_config, active_page='config') return render_template('config.html', current_config=current_config, active_page='config', user=None)
@app.route('/history') @app.route('/history')
@login_required @login_required
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment