66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
import json
|
|
from datetime import date
|
|
from os import path
|
|
|
|
from checker import check_auth
|
|
from flask import Blueprint, render_template, request, url_for
|
|
|
|
from .report_model import create_report_model, view_report_model
|
|
|
|
with open(path.join(path.dirname(__file__), "reports.json"), encoding="utf-8") as f:
|
|
report_list = json.load(f)
|
|
|
|
report_bp = Blueprint(
|
|
"report_bp", __name__, template_folder="templates", static_folder="static"
|
|
)
|
|
|
|
|
|
@report_bp.route("/menu")
|
|
@check_auth
|
|
def menu():
|
|
if request.method == "GET":
|
|
return render_template("report_menu.html")
|
|
|
|
|
|
@report_bp.route("/create", methods=["GET", "POST"])
|
|
@check_auth
|
|
def create():
|
|
if request.method == "GET":
|
|
return render_template(
|
|
"report_basic.html",
|
|
is_write=True,
|
|
title="Создание отчетов",
|
|
items=report_list,
|
|
date_today=date.today(),
|
|
)
|
|
else:
|
|
result = create_report_model(request, report_list)
|
|
if result.status:
|
|
return render_template("OK.html")
|
|
else:
|
|
return render_template("error.html", error_message=result.error_message)
|
|
|
|
|
|
@report_bp.route("/view", methods=["GET", "POST"])
|
|
@check_auth
|
|
def view():
|
|
if request.method == "GET":
|
|
return render_template(
|
|
"report_basic.html",
|
|
is_write=False,
|
|
title="Просмотр отчетов",
|
|
items=report_list,
|
|
date_today=date.today(),
|
|
)
|
|
else:
|
|
result = view_report_model(request, report_list)
|
|
if result.status:
|
|
return render_template(
|
|
"output.html",
|
|
items=result.result,
|
|
header="Результаты отчёта",
|
|
link=url_for("report_bp.menu"),
|
|
)
|
|
else:
|
|
return render_template("error.html", error_message=result.error_message)
|