62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
from datetime import datetime
|
|
|
|
from checker import check_auth
|
|
from flask import (Blueprint, redirect, render_template, request, session,
|
|
url_for)
|
|
|
|
from .model import (button_click, clear, form_waybill, index_waybill,
|
|
transaction_order_model)
|
|
|
|
waybill_bp = Blueprint(
|
|
"waybill_bp", __name__, template_folder="templates", static_folder="static"
|
|
)
|
|
|
|
|
|
@waybill_bp.route("/", methods=["GET"])
|
|
@check_auth
|
|
def index():
|
|
lst = index_waybill()
|
|
if lst is not None:
|
|
waybill = form_waybill()
|
|
return render_template("waybill.html", items=lst, waybill=waybill)
|
|
else:
|
|
return render_template(
|
|
"error.html", error_message="Ошибка в подключении к СУБД"
|
|
)
|
|
|
|
|
|
@waybill_bp.route("/", methods=["POST"])
|
|
@check_auth
|
|
def waybill_main():
|
|
status = button_click(request)
|
|
if status:
|
|
return redirect(url_for("waybill_bp.index"))
|
|
else:
|
|
return render_template(
|
|
"error.html", error_message="Товар не был добавлен в корзину"
|
|
)
|
|
|
|
|
|
@waybill_bp.route("/clear", methods=["GET"])
|
|
@check_auth
|
|
def clear_waybill():
|
|
clear()
|
|
return redirect(url_for("waybill_bp.index"))
|
|
|
|
|
|
@waybill_bp.route("/save_order")
|
|
@check_auth
|
|
def save_order():
|
|
if not session.get("waybill", {}):
|
|
return redirect(url_for("waybill_bp.index"))
|
|
|
|
user_id = session.get("user_id", "")
|
|
current_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
result = transaction_order_model(user_id, current_date)
|
|
if result.status:
|
|
print("Order success")
|
|
return render_template("order_finish.html", order_id=result.result[0])
|
|
else:
|
|
return render_template("error.html", error_message=result.error_message)
|