from flask import request, Blueprint, render_template, url_for from os import path from checker import check_auth from .requests_model import sklad, materials_per_seller, sellers_names, materials_names import json 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': return render_template('zagotovki.html') else: zagotovki = sklad(request) if zagotovki.status: material = dict(request.form) header = f'Заготовки на складе из материала \"{material["material"]}\"' 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': return render_template('sellers_ship.html') 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)