from flask import request, Blueprint, render_template from os import path from checker import check_auth from .requests_model import sklad, materials_per_seller from datetime import date import json with open(path.join(path.dirname(__file__), 'zapros_menu.json')) 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 = ['Сталь', 'Золото', 'Дерево', 'Стекло', 'Медь', 'Цемент'] return render_template('zagotovki.html', materials=materials, header='Количество заготовок на складе') else: material = dict(request.form) zagotovki = sklad(material) if zagotovki.status: header = f'Заготовки на складе из материала \'{material["material"]}\'' return render_template('output.html', items=zagotovki.result, object=header) else: return render_template('error.html', error_message=zagotovki.error_message) # Под вопросом """ @requests_bp.route('/req2', methods=['GET', 'POST']) @check_auth def zagotovki_ship(): if request.method == 'GET': zagotovki = get_goods() if zagotovki.status: return render_template('zagotovki.html', materials=zagotovki.result, header='Поставки заготовок') else: return render_template('error.html', error_message=zagotovki.error_message) else: material = dict(request.form) zagotovki = route(material, 'zapros2.sql') if zagotovki.status: header = f'Поставки заготовок из материала \'{material['material']}\'' return render_template('output.html', items=zagotovki.result, object=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 = ['Car and bikes', 'Doto', 'LPD', 'Neva', 'PGG', 'Robot', 'Rost'] return render_template('sellers_ship.html', sellers=sellers, year_from='2000', year_to=str(date.today().year)) else: seller = dict(request.form) zagotovki = materials_per_seller(seller) if zagotovki.status: header = f'Поставки от поставщика \'{seller['seller']}\'' return render_template('output.html', items=zagotovki.result, object=header) else: return render_template('error.html', error_message=zagotovki.error_message)