From 339a55f8dad6cdeb9e0bdbd594529e41ab86e83d Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Tue, 22 Oct 2024 00:09:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BF=D1=80=D0=BE=D1=81=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=BC=D0=B0=D1=82=D0=B5=D1=80=D0=B8=D0=B0=D0=BB=D1=83?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Доработать возвращение в меню запросов --- App/Queries/req.py | 9 ++++++- App/Queries/sql/zagotovki.sql | 1 + App/Queries/sql/zapros1.sql | 3 +++ App/Queries/templates/sklad_zapros.html | 32 +++++++++++++++++++++---- App/app.py | 1 + App/db/select.py | 12 ++++++++++ config.json | 7 ------ 7 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 App/Queries/sql/zagotovki.sql create mode 100644 App/Queries/sql/zapros1.sql create mode 100644 App/db/select.py delete mode 100644 config.json diff --git a/App/Queries/req.py b/App/Queries/req.py index d5f4514..55ba9c8 100644 --- a/App/Queries/req.py +++ b/App/Queries/req.py @@ -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') \ No newline at end of file + 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) \ No newline at end of file diff --git a/App/Queries/sql/zagotovki.sql b/App/Queries/sql/zagotovki.sql new file mode 100644 index 0000000..2781f37 --- /dev/null +++ b/App/Queries/sql/zagotovki.sql @@ -0,0 +1 @@ +SELECT DISTINCT material FROM workpiece \ No newline at end of file diff --git a/App/Queries/sql/zapros1.sql b/App/Queries/sql/zapros1.sql new file mode 100644 index 0000000..d07bc9d --- /dev/null +++ b/App/Queries/sql/zapros1.sql @@ -0,0 +1,3 @@ +SELECT material, weight, price, count +FROM workpiece +WHERE material = '${material}' \ No newline at end of file diff --git a/App/Queries/templates/sklad_zapros.html b/App/Queries/templates/sklad_zapros.html index ed11431..034df6e 100644 --- a/App/Queries/templates/sklad_zapros.html +++ b/App/Queries/templates/sklad_zapros.html @@ -5,13 +5,37 @@ Hello World +

Hello World

+ {% if status %}
- + {% for item in materials %} + {% endfor %} - + +
+ {% else %} + + {% if result_table %} + + + {% for item in result_table[0] %} + + {% endfor %} + + {% for item in result_table[1] %} + + + + + + + {% endfor %} +
{{ item }}
{{ item['material'] }}{{ item['weight'] }}{{ item['price'] }}{{ item['count'] }}
+ {% endif %} + {% endif %} + diff --git a/App/app.py b/App/app.py index 6ae5a20..6e33fbe 100644 --- a/App/app.py +++ b/App/app.py @@ -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') diff --git a/App/db/select.py b/App/db/select.py new file mode 100644 index 0000000..fb7e9dd --- /dev/null +++ b/App/db/select.py @@ -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 \ No newline at end of file diff --git a/config.json b/config.json deleted file mode 100644 index b040922..0000000 --- a/config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "host": "localhost", - "port": 3306, - "user": "manager", - "password": "ilikepizza", - "db": "supermarket" -} \ No newline at end of file