Динамическое получение списка материалов и поставщиков

This commit is contained in:
2024-12-10 17:22:19 +03:00
parent fd4d3ea051
commit a636897eee
4 changed files with 12 additions and 38 deletions

View File

@@ -24,7 +24,8 @@ def requests():
@check_auth @check_auth
def sklad_zapros(): def sklad_zapros():
if request.method == "GET": if request.method == "GET":
return render_template("zagotovki.html") materials = materials_names()
return render_template("zagotovki.html", materials=materials)
else: else:
zagotovki = sklad(request) zagotovki = sklad(request)
if zagotovki.status: if zagotovki.status:
@@ -39,7 +40,8 @@ def sklad_zapros():
@check_auth @check_auth
def sellers_ship(): def sellers_ship():
if request.method == "GET": if request.method == "GET":
return render_template("sellers_ship.html") sellers = sellers_names()
return render_template("sellers_ship.html", sellers=sellers)
else: else:
zagotovki = materials_per_seller(request) zagotovki = materials_per_seller(request)
if zagotovki.status: if zagotovki.status:

View File

@@ -15,31 +15,19 @@ class InfoRespronse:
status: bool status: bool
def sellers_names() -> InfoRespronse: def sellers_names() -> list:
db_config = current_app.config["db_config"] db_config = current_app.config["db_config"]
_sql = sql_provider.get("sellers_names.sql", {}) _sql = sql_provider.get("sellers_names.sql", {})
result = select_list(db_config, _sql) result = select_list(db_config, _sql)
if result is None:
return InfoRespronse(
(),
error_message="Ошибка в подключении к базе данных. Свяжитесь с администратором",
status=False,
)
return InfoRespronse(result, error_message="", status=True) return InfoRespronse(result, error_message="", status=True)
def materials_names() -> InfoRespronse: def materials_names() -> list:
db_config = current_app.config["db_config"] db_config = current_app.config["db_config"]
_sql = sql_provider.get("materials_names.sql", {}) _sql = sql_provider.get("materials_names.sql", {})
result = select_list(db_config, _sql) result = select_list(db_config, _sql)
if result is None:
return InfoRespronse(
(),
error_message="Ошибка в подключении к базе данных. Свяжитесь с администратором",
status=False,
)
return InfoRespronse(result, error_message="", status=True) return InfoRespronse(result, error_message="", status=True)
@@ -49,12 +37,6 @@ def sklad(request) -> InfoRespronse:
_sql = sql_provider.get("sklad_material.sql", material) _sql = sql_provider.get("sklad_material.sql", material)
result = select_list(db_config, _sql) result = select_list(db_config, _sql)
if result is None:
return InfoRespronse(
(),
error_message="Ошибка в подключении к базе данных. Свяжитесь с администратором",
status=False,
)
return InfoRespronse(result, error_message="", status=True) return InfoRespronse(result, error_message="", status=True)
@@ -64,10 +46,4 @@ def materials_per_seller(request) -> InfoRespronse:
seller = dict(request.form) seller = dict(request.form)
_sql = sql_provider.get("ship_seller.sql", seller) _sql = sql_provider.get("ship_seller.sql", seller)
result = select_list(db_config, _sql) result = select_list(db_config, _sql)
if result is None:
return InfoRespronse(
(),
error_message="Ошибка в подключении к базе данных. Свяжитесь с администратором",
status=False,
)
return InfoRespronse(result, error_message="", status=True) return InfoRespronse(result, error_message="", status=True)

View File

@@ -33,11 +33,9 @@
<form action="" method="post" style="display: inline-block;"> <form action="" method="post" style="display: inline-block;">
<label>Выберите поставщика</label> <label>Выберите поставщика</label>
<select class="form-select" name="seller"> <select class="form-select" name="seller">
<option value="Alpha Supplies">Alpha Supplies</option> {% for item in sellers %}
<option value="Beta Materials">Beta Materials</option> <option value="{{ item["name"] }}">{{ item["name"] }}</option>
<option value="Gamma Parts">Gamma Parts</option> {% endfor %}
<option value="Delta Components">Delta Components</option>
<option value="Epsilon Goods">Epsilon Goods</option>
</select> </select>
<button type="submit" class="btn btn-primary">Отправить</button> <button type="submit" class="btn btn-primary">Отправить</button>
</form> </form>

View File

@@ -34,11 +34,9 @@
<form action="" method="post" style="display: inline-block;"> <form action="" method="post" style="display: inline-block;">
<label>Выберите материал</label> <label>Выберите материал</label>
<select class="form-select" name="material"> <select class="form-select" name="material">
<option value="Сталь">Сталь</option> {% for item in materials %}
<option value="Алюминий">Алюминий</option> <option value="{{ item["name"] }}">{{ item["name"] }}</option>
<option value="Медь">Медь</option> {% endfor %}
<option value="Пластик">Пластик</option>
<option value="Дерево">Дерево</option>
</select> </select>
<button type="submit" class="btn btn-primary">Отправить</button> <button type="submit" class="btn btn-primary">Отправить</button>
</form> </form>