36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import time
|
|
|
|
from flask import Blueprint, Response, redirect, render_template, request
|
|
|
|
from app.auth import requires_admin_basic_auth
|
|
from app.services.order import get_all_orders, update_order_status
|
|
|
|
admin_bp = Blueprint("admin", __name__)
|
|
|
|
|
|
@admin_bp.route("/admin")
|
|
@requires_admin_basic_auth
|
|
def admin():
|
|
orders = get_all_orders()
|
|
return render_template("admin.html", orders=orders)
|
|
|
|
|
|
@admin_bp.route("/update_status/<int:order_id>", methods=["POST"])
|
|
@requires_admin_basic_auth
|
|
def update_status(order_id: int):
|
|
status = request.form.get("status", "Новый")
|
|
update_order_status(order_id, status)
|
|
return redirect("/admin")
|
|
|
|
|
|
@admin_bp.route("/logout", methods=["POST"])
|
|
def logout():
|
|
response = Response(
|
|
'Вы вышли из админ-панели. <a href="/admin">Войти снова</a>',
|
|
401,
|
|
{"WWW-Authenticate": f'Basic realm="Admin Logout {int(time.time())}"'},
|
|
)
|
|
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
|
response.headers["Pragma"] = "no-cache"
|
|
return response
|