- Implemented the initial version of the web interface. refactor: Begin Telegram bot refactoring - Started restructuring the bot’s code for better maintainability. chore: Migrate to Flask project structure - Reorganized the application to follow Flask's project structure. cleanup: Extensive code cleanup - Removed redundant code and improved readability. Signed-off-by: UdoChudo <stream@udochudo.ru>
93 lines
2.8 KiB
Python
93 lines
2.8 KiB
Python
from flask import Blueprint, render_template, request
|
|
|
|
from app.models import AuditLog
|
|
from app.models import Users
|
|
from flask_login import login_required
|
|
|
|
# Создаём Blueprint
|
|
dashboard_bp = Blueprint('dashboard', __name__, url_prefix='/telezab/')
|
|
|
|
|
|
|
|
# Роуты для отображения страниц
|
|
@dashboard_bp.route('/')
|
|
@login_required
|
|
def dashboard():
|
|
return render_template('index.html')
|
|
|
|
@dashboard_bp.route('/users')
|
|
@login_required
|
|
def users_page():
|
|
users = Users.query.all()
|
|
return render_template('users.html', user=users)
|
|
|
|
@dashboard_bp.route('/logs')
|
|
@login_required
|
|
def logs_page():
|
|
# Получаем параметры фильтрации из query string
|
|
action = request.args.get('action', type=str)
|
|
username = request.args.get('username', type=str)
|
|
timestamp_from = request.args.get('timestamp_from', type=str)
|
|
timestamp_to = request.args.get('timestamp_to', type=str)
|
|
order = request.args.get('order', 'asc').lower()
|
|
page = request.args.get('page', 1, type=int)
|
|
per_page = 20
|
|
|
|
query = AuditLog.query
|
|
|
|
# Фильтрация по action
|
|
if action:
|
|
query = query.filter(AuditLog.action.ilike(f'%{action}%'))
|
|
|
|
# Фильтрация по username
|
|
if username:
|
|
query = query.filter(AuditLog.username.ilike(f'%{username}%'))
|
|
|
|
# Фильтрация по дате (начало)
|
|
if timestamp_from:
|
|
try:
|
|
from datetime import datetime
|
|
dt_from = datetime.strptime(timestamp_from, '%Y-%m-%d')
|
|
query = query.filter(AuditLog.timestamp >= dt_from)
|
|
except ValueError:
|
|
pass # Игнорируем неверный формат
|
|
|
|
# Фильтрация по дате (конец)
|
|
if timestamp_to:
|
|
try:
|
|
from datetime import datetime, timedelta
|
|
dt_to = datetime.strptime(timestamp_to, '%Y-%m-%d') + timedelta(days=1)
|
|
query = query.filter(AuditLog.timestamp < dt_to)
|
|
except ValueError:
|
|
pass
|
|
|
|
# Сортировка
|
|
if order == 'asc':
|
|
query = query.order_by(AuditLog.timestamp.asc())
|
|
else:
|
|
query = query.order_by(AuditLog.timestamp.desc())
|
|
|
|
# Пагинация
|
|
logs = query.paginate(page=page, per_page=per_page, error_out=False)
|
|
|
|
# Передаем текущие фильтры и сортировку в шаблон для отображения и генерации ссылок
|
|
filters = {
|
|
'action': action,
|
|
'username': username,
|
|
'timestamp_from': timestamp_from,
|
|
'timestamp_to': timestamp_to,
|
|
'order': order
|
|
}
|
|
|
|
return render_template('logs.html', logs=logs, filters=filters)
|
|
|
|
@dashboard_bp.route('/regions')
|
|
@login_required
|
|
def regions_page():
|
|
return render_template('regions.html')
|
|
|
|
@dashboard_bp.route('/health')
|
|
def healthcheck():
|
|
pass
|
|
|