From 771946eae5e32aa47a4e2819d61e5f7194516495 Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Thu, 7 Nov 2024 18:39:13 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=B3=D0=BE=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B?= =?UTF-8?q?=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Auth/__init__.py | 1 - App/Auth/templates/auth.html | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/App/Auth/__init__.py b/App/Auth/__init__.py index 6e92707..79e03e1 100644 --- a/App/Auth/__init__.py +++ b/App/Auth/__init__.py @@ -9,7 +9,6 @@ def auth(): return render_template('auth.html') else: data = request.form.to_dict() - print(data) auth_data = auth_model(data) if auth_data.status: session.update({ diff --git a/App/Auth/templates/auth.html b/App/Auth/templates/auth.html index 3bed3b2..08ef3c2 100644 --- a/App/Auth/templates/auth.html +++ b/App/Auth/templates/auth.html @@ -7,6 +7,7 @@ +

Авторизация

From 9fda5692709bcbb3aabf898dcec51439d8e058bd Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Fri, 8 Nov 2024 11:56:46 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=20html-=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=86=20+=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=B3=D0=BE=D0=BB=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Requests/templates/error.html | 2 +- App/Requests/templates/output.html | 2 +- App/Requests/templates/sellers_ship.html | 6 +++--- App/Requests/templates/zagotovki.html | 2 +- App/Requests/templates/zapros_menu.html | 2 +- App/Requests/zapros_menu.json | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/App/Requests/templates/error.html b/App/Requests/templates/error.html index c1a8828..bd6bb48 100644 --- a/App/Requests/templates/error.html +++ b/App/Requests/templates/error.html @@ -1,5 +1,5 @@ - + Ошибка diff --git a/App/Requests/templates/output.html b/App/Requests/templates/output.html index e632081..b485fbb 100644 --- a/App/Requests/templates/output.html +++ b/App/Requests/templates/output.html @@ -1,5 +1,5 @@ - + {{ header }} diff --git a/App/Requests/templates/sellers_ship.html b/App/Requests/templates/sellers_ship.html index afc6eea..1a5a66a 100644 --- a/App/Requests/templates/sellers_ship.html +++ b/App/Requests/templates/sellers_ship.html @@ -1,8 +1,8 @@ - + - Все поставки поставщиком + Поставки поставщиком @@ -10,7 +10,7 @@
-

Все поставки поставщиком

+

Поставки поставщиком

Выберите поставщика

diff --git a/App/Requests/templates/zagotovki.html b/App/Requests/templates/zagotovki.html index eef759a..41b860c 100644 --- a/App/Requests/templates/zagotovki.html +++ b/App/Requests/templates/zagotovki.html @@ -1,5 +1,5 @@ - + {{ header }} diff --git a/App/Requests/templates/zapros_menu.html b/App/Requests/templates/zapros_menu.html index 852a439..e7d38b8 100644 --- a/App/Requests/templates/zapros_menu.html +++ b/App/Requests/templates/zapros_menu.html @@ -1,5 +1,5 @@ - + Запросы diff --git a/App/Requests/zapros_menu.json b/App/Requests/zapros_menu.json index 77b9a68..a34b0e7 100644 --- a/App/Requests/zapros_menu.json +++ b/App/Requests/zapros_menu.json @@ -1,5 +1,5 @@ [ {"name": "Количество заготовок на складе", "url": "requests_bp.sklad_zapros"}, - {"name": "Поставки поставщиком за год", "url": "requests_bp.sellers_ship"} + {"name": "Поставки поставщиками", "url": "requests_bp.sellers_ship"} ] \ No newline at end of file From c11283f0742ca03843b38512396866dee6722200 Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Fri, 8 Nov 2024 18:11:27 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=20+=20=D0=BF=D1=80=D0=B5=D0=B2=D1=80=D0=B0=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=20=D1=88?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=BE=D0=B2=20=D0=B2=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Requests/__init__.py | 8 ++++---- App/Requests/templates/sellers_ship.html | 8 +++++--- App/Requests/templates/zagotovki.html | 8 +++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/App/Requests/__init__.py b/App/Requests/__init__.py index 879897f..a639f30 100644 --- a/App/Requests/__init__.py +++ b/App/Requests/__init__.py @@ -20,8 +20,8 @@ def requests(): @check_auth def sklad_zapros(): if request.method == 'GET': - materials = ['Сталь', 'Алюминий', 'Медь', 'Пластик', 'Дерево'] - return render_template('zagotovki.html', materials=materials, header='Количество заготовок на складе') + # materials = ['Сталь', 'Алюминий', 'Медь', 'Пластик', 'Дерево'] + return render_template('zagotovki.html', header='Количество заготовок на складе') else: material = dict(request.form) zagotovki = sklad(material) @@ -54,8 +54,8 @@ def zagotovki_ship(): @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) + # sellers = ['Alpha Supplies', 'Beta Materials', 'Gamma Parts', 'Delta Components', 'Epsilon Goods'] + return render_template('sellers_ship.html') else: seller = dict(request.form) zagotovki = materials_per_seller(seller) diff --git a/App/Requests/templates/sellers_ship.html b/App/Requests/templates/sellers_ship.html index 1a5a66a..c14c1a8 100644 --- a/App/Requests/templates/sellers_ship.html +++ b/App/Requests/templates/sellers_ship.html @@ -15,9 +15,11 @@

Выберите поставщика

diff --git a/App/Requests/templates/zagotovki.html b/App/Requests/templates/zagotovki.html index 41b860c..9d2de58 100644 --- a/App/Requests/templates/zagotovki.html +++ b/App/Requests/templates/zagotovki.html @@ -15,9 +15,11 @@

Выберите материал

From cde558d27844abd7d2c7c53c40edce63c14e9bf4 Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Thu, 14 Nov 2024 15:09:53 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=20?= =?UTF-8?q?=D1=81=D0=BF=D0=B5=D1=86=D0=B8=D1=84=D0=B8=D1=87=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D0=B1=D1=89=D1=83=D1=8E=20=D0=BF=D0=B0=D0=BF?= =?UTF-8?q?=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Requests/__init__.py | 26 +++--------------------- App/Requests/templates/error.html | 13 ------------ App/{Requests => }/templates/output.html | 4 ++-- App/templates/pages_menu.html | 22 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 38 deletions(-) delete mode 100644 App/Requests/templates/error.html rename App/{Requests => }/templates/output.html (87%) create mode 100644 App/templates/pages_menu.html diff --git a/App/Requests/__init__.py b/App/Requests/__init__.py index a639f30..c162543 100644 --- a/App/Requests/__init__.py +++ b/App/Requests/__init__.py @@ -1,8 +1,7 @@ -from flask import request, Blueprint, render_template +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 datetime import date import json with open(path.join(path.dirname(__file__), 'zapros_menu.json')) as f: @@ -14,7 +13,7 @@ requests_bp = Blueprint('requests_bp', __name__, template_folder='templates') @check_auth def requests(): if request.method == 'GET': - return render_template('zapros_menu.html', options=requests_list) + return render_template('pages_menu.html', options=requests_list, header='Запросы') @requests_bp.route('/sklad', methods=['GET', 'POST']) @check_auth @@ -30,25 +29,6 @@ def sklad_zapros(): return render_template('output.html', items=zagotovki.result, header=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 @@ -61,6 +41,6 @@ def sellers_ship(): zagotovki = materials_per_seller(seller) if zagotovki.status: header = f'Поставки от поставщика \"{seller["seller"]}\"' - return render_template('output.html', items=zagotovki.result, header=header) + return render_template('output.html', items=zagotovki.result, header=header, link=url_for('requests_bp.requests')) else: return render_template('error.html', error_message=zagotovki.error_message) \ No newline at end of file diff --git a/App/Requests/templates/error.html b/App/Requests/templates/error.html deleted file mode 100644 index bd6bb48..0000000 --- a/App/Requests/templates/error.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - Ошибка - - - -

Произошла ошибка

-

{{ error_message }}.

- - - diff --git a/App/Requests/templates/output.html b/App/templates/output.html similarity index 87% rename from App/Requests/templates/output.html rename to App/templates/output.html index b485fbb..269fc09 100644 --- a/App/Requests/templates/output.html +++ b/App/templates/output.html @@ -1,5 +1,5 @@ - + {{ header }} @@ -31,6 +31,6 @@

Информации не найдено

{% endif %} \ No newline at end of file diff --git a/App/templates/pages_menu.html b/App/templates/pages_menu.html new file mode 100644 index 0000000..bf6010f --- /dev/null +++ b/App/templates/pages_menu.html @@ -0,0 +1,22 @@ + + + + + {{ header }} + + + + +

Выберите один из предложенных вариантов

+ + + + \ No newline at end of file From f65d76757abf49d140363b841e9501955f6e018b Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Thu, 14 Nov 2024 15:13:57 +0300 Subject: [PATCH 5/6] db module for requests --- App/Requests/db/DBconnect.py | 34 +++++++++++++++++++++++++++++++++ App/Requests/db/__init__.py | 0 App/Requests/db/select.py | 12 ++++++++++++ App/Requests/db/sql_provider.py | 14 ++++++++++++++ App/Requests/requests_model.py | 4 ++-- 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 App/Requests/db/DBconnect.py create mode 100644 App/Requests/db/__init__.py create mode 100644 App/Requests/db/select.py create mode 100644 App/Requests/db/sql_provider.py diff --git a/App/Requests/db/DBconnect.py b/App/Requests/db/DBconnect.py new file mode 100644 index 0000000..b335654 --- /dev/null +++ b/App/Requests/db/DBconnect.py @@ -0,0 +1,34 @@ +import pymysql +from pymysql.err import * +class DBContextManager: + def __init__(self, db_config : dict): + self.db_config = db_config + self.connection = None + self.cursor = None + + def __enter__(self): + try: + self.connection = pymysql.connect( + host=self.db_config['host'], + port=self.db_config['port'], + user=self.db_config['user'], + password=self.db_config['password'], + db=self.db_config['db'] + ) + self.cursor = self.connection.cursor() + return self.cursor + except (OperationalError, KeyError) as err: + print(err.args) + return None + + def __exit__(self, exc_type, exc_val, exc_tb): + if self.connection and self.cursor: + if exc_type: + print(exc_type, '\n', exc_val) + self.connection.rollback() + else: + self.connection.commit() + self.cursor.close() + self.connection.close() + return True + \ No newline at end of file diff --git a/App/Requests/db/__init__.py b/App/Requests/db/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/App/Requests/db/select.py b/App/Requests/db/select.py new file mode 100644 index 0000000..22cc3e7 --- /dev/null +++ b/App/Requests/db/select.py @@ -0,0 +1,12 @@ +from .DBconnect import DBContextManager + +def select_list(db_config, sql) -> list: + 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 lst \ No newline at end of file diff --git a/App/Requests/db/sql_provider.py b/App/Requests/db/sql_provider.py new file mode 100644 index 0000000..a3a1855 --- /dev/null +++ b/App/Requests/db/sql_provider.py @@ -0,0 +1,14 @@ +import os +from string import Template + +class SQLProvider: + def __init__(self, file_path): + self.scripts = {} + for file in os.listdir(file_path): + _sql = open(f'{file_path}/{file}').read() + self.scripts[file] = Template(_sql) + + def get(self, name, params) -> dict: + if name not in self.scripts: + raise ValueError(f'SQL template {name} not found') + return self.scripts[name].substitute(**params) \ No newline at end of file diff --git a/App/Requests/requests_model.py b/App/Requests/requests_model.py index 69fc110..813be3d 100644 --- a/App/Requests/requests_model.py +++ b/App/Requests/requests_model.py @@ -1,6 +1,6 @@ from dataclasses import dataclass -from Database.select import select_list -from Database.sql_provider import SQLProvider +from db.select import select_list +from db.sql_provider import SQLProvider from flask import current_app from os import path From 751fb0c20dfb244221cd28f78f1d923dafd7e87f Mon Sep 17 00:00:00 2001 From: Anton Kamalov Date: Thu, 14 Nov 2024 15:16:39 +0300 Subject: [PATCH 6/6] db module for Auth --- App/Auth/auth_model.py | 4 ++-- App/{Database => Auth/db}/DBconnect.py | 0 App/{Database => Auth/db}/__init__.py | 0 App/{Database => Auth/db}/select.py | 0 App/{Database => Auth/db}/sql_provider.py | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename App/{Database => Auth/db}/DBconnect.py (100%) rename App/{Database => Auth/db}/__init__.py (100%) rename App/{Database => Auth/db}/select.py (100%) rename App/{Database => Auth/db}/sql_provider.py (100%) diff --git a/App/Auth/auth_model.py b/App/Auth/auth_model.py index 856f73c..4c36953 100644 --- a/App/Auth/auth_model.py +++ b/App/Auth/auth_model.py @@ -1,6 +1,6 @@ from dataclasses import dataclass -from Database.select import select_list -from Database.sql_provider import SQLProvider +from db.select import select_list +from db.sql_provider import SQLProvider from flask import current_app import os diff --git a/App/Database/DBconnect.py b/App/Auth/db/DBconnect.py similarity index 100% rename from App/Database/DBconnect.py rename to App/Auth/db/DBconnect.py diff --git a/App/Database/__init__.py b/App/Auth/db/__init__.py similarity index 100% rename from App/Database/__init__.py rename to App/Auth/db/__init__.py diff --git a/App/Database/select.py b/App/Auth/db/select.py similarity index 100% rename from App/Database/select.py rename to App/Auth/db/select.py diff --git a/App/Database/sql_provider.py b/App/Auth/db/sql_provider.py similarity index 100% rename from App/Database/sql_provider.py rename to App/Auth/db/sql_provider.py