Динамическое получение списка заготовок и поставщиков
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
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
|
||||
from .requests_model import sklad, materials_per_seller, sellers_names, materials_names
|
||||
import json
|
||||
|
||||
with open(path.join(path.dirname(__file__), 'zapros_menu.json')) as f:
|
||||
@@ -19,8 +19,8 @@ def requests():
|
||||
@check_auth
|
||||
def sklad_zapros():
|
||||
if request.method == 'GET':
|
||||
# materials = ['Сталь', 'Алюминий', 'Медь', 'Пластик', 'Дерево']
|
||||
return render_template('zagotovki.html', header='Количество заготовок на складе')
|
||||
materials = materials_names()
|
||||
return render_template('zagotovki.html', materials=materials.result)
|
||||
else:
|
||||
material = dict(request.form)
|
||||
zagotovki = sklad(material)
|
||||
@@ -34,8 +34,8 @@ def sklad_zapros():
|
||||
@check_auth
|
||||
def sellers_ship():
|
||||
if request.method == 'GET':
|
||||
# sellers = ['Alpha Supplies', 'Beta Materials', 'Gamma Parts', 'Delta Components', 'Epsilon Goods']
|
||||
return render_template('sellers_ship.html')
|
||||
sellers = sellers_names()
|
||||
return render_template('sellers_ship.html', sellers=sellers.result)
|
||||
else:
|
||||
seller = dict(request.form)
|
||||
zagotovki = materials_per_seller(seller)
|
||||
|
||||
@@ -11,6 +11,24 @@ class InfoRespronse:
|
||||
error_message: str
|
||||
status: bool
|
||||
|
||||
def sellers_names() -> InfoRespronse:
|
||||
_sql = sql_provider.get('sellers_names.sql', {})
|
||||
result = select_list(current_app.config['db_config'], _sql)
|
||||
if result is None:
|
||||
return InfoRespronse((),
|
||||
error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором',
|
||||
status=False)
|
||||
return InfoRespronse(result, error_message='', status=True)
|
||||
|
||||
def materials_names() -> InfoRespronse:
|
||||
_sql = sql_provider.get('materials_names.sql', {})
|
||||
result = select_list(current_app.config['db_config'], _sql)
|
||||
if result is None:
|
||||
return InfoRespronse((),
|
||||
error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором',
|
||||
status=False)
|
||||
return InfoRespronse(result, error_message='', status=True)
|
||||
|
||||
def sklad(input_data) -> InfoRespronse:
|
||||
_sql = sql_provider.get('sklad_material.sql', input_data)
|
||||
print("sql = ", _sql)
|
||||
@@ -21,6 +39,7 @@ def sklad(input_data) -> InfoRespronse:
|
||||
status=False)
|
||||
return InfoRespronse(result, error_message='', status=True)
|
||||
|
||||
|
||||
def materials_per_seller(input_data) -> InfoRespronse:
|
||||
_sql = sql_provider.get('ship_seller.sql', input_data)
|
||||
result = select_list(current_app.config['db_config'], _sql)
|
||||
|
||||
1
App/Requests/sql/materials_names.sql
Normal file
1
App/Requests/sql/materials_names.sql
Normal file
@@ -0,0 +1 @@
|
||||
SELECT DISTINCT material FROM workpiece;
|
||||
1
App/Requests/sql/sellers_names.sql
Normal file
1
App/Requests/sql/sellers_names.sql
Normal file
@@ -0,0 +1 @@
|
||||
SELECT name FROM sellers;
|
||||
@@ -15,11 +15,9 @@
|
||||
<p>Выберите поставщика</p>
|
||||
<form action="" method="post">
|
||||
<select name="seller">
|
||||
<option value="Alpha Supplies">Alpha Supplies</option>
|
||||
<option value="Beta Materials">Beta Materials</option>
|
||||
<option value="Gamma Parts">Gamma Parts</option>
|
||||
<option value="Delta Components">Delta Components</option>
|
||||
<option value="Epsilon Goods">Epsilon Goods</option>
|
||||
{% for seller in sellers %}
|
||||
<option value="{{ seller['name'] }}">{{ seller['name'] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input type="submit" value="Отправить">
|
||||
</form>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ header }}</title>
|
||||
<title>Количество заготовок на складе</title>
|
||||
<link href="/static/css/main.css" type="text/css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
@@ -10,7 +10,7 @@
|
||||
<a href="{{ url_for('logout') }}"><button>Выход</button></a>
|
||||
</div>
|
||||
<!-- Input -->
|
||||
<h1>{{ header }}</h1>
|
||||
<h1>Количество заготовок на складе</h1>
|
||||
<div class="form">
|
||||
<form action="" method="post" style="display: inline-block;">
|
||||
<p>Выберите материал<p></p>
|
||||
|
||||
Reference in New Issue
Block a user