Запрос по материалу заготовки
Доработать возвращение в меню запросов
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from flask import request, Blueprint, render_template, session, redirect, url_for
|
||||
from os import path
|
||||
from db.sql_provider import SQLProvider
|
||||
from db.select import select_list
|
||||
|
||||
sql_provider = SQLProvider(path.join(path.dirname(__file__), 'sql'))
|
||||
requests_bp = Blueprint('requests_bp', __name__, template_folder='templates')
|
||||
@@ -8,4 +9,10 @@ requests_bp = Blueprint('requests_bp', __name__, template_folder='templates')
|
||||
@requests_bp.route('/', methods=['GET', 'POST'])
|
||||
def sklad_zapros():
|
||||
if request.method == 'GET':
|
||||
return render_template('sklad_zapros.html')
|
||||
result = select_list(session['db_config'], sql_provider.get('zagotovki.sql', {}))
|
||||
return render_template('sklad_zapros.html', materials=result[1], status=True)
|
||||
else:
|
||||
name = dict(request.form)
|
||||
print(name)
|
||||
result = select_list(session['db_config'], sql_provider.get('zapros1.sql', name))
|
||||
return render_template('sklad_zapros.html', materials=result[1], result_table=result)
|
||||
1
App/Queries/sql/zagotovki.sql
Normal file
1
App/Queries/sql/zagotovki.sql
Normal file
@@ -0,0 +1 @@
|
||||
SELECT DISTINCT material FROM workpiece
|
||||
3
App/Queries/sql/zapros1.sql
Normal file
3
App/Queries/sql/zapros1.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
SELECT material, weight, price, count
|
||||
FROM workpiece
|
||||
WHERE material = '${material}'
|
||||
@@ -5,13 +5,37 @@
|
||||
<title>Hello World</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Input -->
|
||||
<h1>Hello World</h1>
|
||||
{% if status %}
|
||||
<form action="" method="post">
|
||||
<select name="categories" size="10" multiple>
|
||||
{% for category in categories %}
|
||||
<option value="{{ category }}">{{ category }}</option>
|
||||
<select name="material">
|
||||
{% for item in materials %}
|
||||
<option value="{{ item['material'] }}">{{ item['material'] }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</select>
|
||||
<input type="submit" value="Отправить">
|
||||
</form>
|
||||
{% else %}
|
||||
<!-- Output -->
|
||||
{% if result_table %}
|
||||
<table>
|
||||
<tr>
|
||||
{% for item in result_table[0] %}
|
||||
<th>{{ item }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% for item in result_table[1] %}
|
||||
<tr>
|
||||
<td>{{ item['material'] }}</td>
|
||||
<td>{{ item['weight'] }}</td>
|
||||
<td>{{ item['price'] }}</td>
|
||||
<td>{{ item['count'] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ app.register_blueprint(requests_bp, url_prefix='/requests')
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
session['db_config'] = app.config['db_config'] # Временное решение до момента с авторизацией
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/logout')
|
||||
|
||||
12
App/db/select.py
Normal file
12
App/db/select.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from .DBconnect import DBContextManager
|
||||
|
||||
def select_list(db_config, sql):
|
||||
with DBContextManager(db_config) as cursor:
|
||||
if cursor is None:
|
||||
raise ValueError("Cursor not created")
|
||||
else:
|
||||
cursor.execute(sql)
|
||||
result = cursor.fetchall()
|
||||
schema = [item[0] for item in cursor.description]
|
||||
lst = [dict(zip(schema, row)) for row in result]
|
||||
return schema, lst
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"host": "localhost",
|
||||
"port": 3306,
|
||||
"user": "manager",
|
||||
"password": "ilikepizza",
|
||||
"db": "supermarket"
|
||||
}
|
||||
Reference in New Issue
Block a user