57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
import json
|
|
from os import path
|
|
|
|
from checker import check_auth
|
|
from flask import Blueprint, render_template, request, url_for
|
|
|
|
from .requests_model import (materials_names, materials_per_seller,
|
|
sellers_names, sklad)
|
|
|
|
with open(path.join(path.dirname(__file__), "zapros_menu.json"), encoding="utf-8") as f:
|
|
requests_list = json.load(f)
|
|
|
|
requests_bp = Blueprint("requests_bp", __name__, template_folder="templates")
|
|
|
|
|
|
@requests_bp.route("/", methods=["GET", "POST"])
|
|
@check_auth
|
|
def requests():
|
|
if request.method == "GET":
|
|
return render_template("zapros_menu.html", options=requests_list)
|
|
|
|
|
|
@requests_bp.route("/sklad", methods=["GET", "POST"])
|
|
@check_auth
|
|
def sklad_zapros():
|
|
if request.method == "GET":
|
|
materials = materials_names()
|
|
return render_template("zagotovki.html", materials=materials)
|
|
else:
|
|
zagotovki = sklad(request)
|
|
if zagotovki.status:
|
|
header = "Поставки выбранной заготовки"
|
|
return render_template("output.html", items=zagotovki.result, header=header)
|
|
else:
|
|
return render_template("error.html", error_message=zagotovki.error_message)
|
|
|
|
|
|
@requests_bp.route("/shipments", methods=["GET", "POST"])
|
|
@check_auth
|
|
def sellers_ship():
|
|
if request.method == "GET":
|
|
sellers = sellers_names()
|
|
return render_template("sellers_ship.html", sellers=sellers)
|
|
else:
|
|
zagotovki = materials_per_seller(request)
|
|
if zagotovki.status:
|
|
seller = dict(request.form)
|
|
header = f'Поставки от поставщика "{seller["seller"]}"'
|
|
return render_template(
|
|
"output.html",
|
|
items=zagotovki.result,
|
|
header=header,
|
|
link=url_for("requests_bp.requests"),
|
|
)
|
|
else:
|
|
return render_template("error.html", error_message=zagotovki.error_message)
|