from flask import request, Blueprint, render_template, session, redirect, url_for from checker import check_auth from .model import index_waybill, form_waybill, clear, button_click, transaction_order_model from datetime import datetime 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)