diff --git a/App/Auth/__init__.py b/App/Auth/__init__.py index 402607f..ed7e55a 100644 --- a/App/Auth/__init__.py +++ b/App/Auth/__init__.py @@ -1,4 +1,4 @@ -from flask import request, Blueprint, render_template, session, current_app, redirect, url_for +from flask import Blueprint, render_template, redirect, url_for, request, session from .auth_model import auth_model auth_bp = Blueprint('auth_bp', __name__, template_folder='templates') diff --git a/App/Auth/auth_model.py b/App/Auth/auth_model.py index 7446ac6..b3cab0b 100644 --- a/App/Auth/auth_model.py +++ b/App/Auth/auth_model.py @@ -1,6 +1,8 @@ from dataclasses import dataclass -from .db.select import select_list -from .db.sql_provider import SQLProvider + +from Database.work import select_list +from Database.sql_provider import SQLProvider + from flask import current_app import os @@ -12,8 +14,10 @@ class InfoRespronse: status: bool def auth_model(input_data) -> InfoRespronse: + db_config = current_app.config['db_config'] + _sql = sql_provider.get('auth.sql', input_data) - user = select_list(current_app.config['db_config'], _sql) + user = select_list(db_config, _sql) if user is None: return InfoRespronse((), error_message = 'Ошибка при подключении к БД', diff --git a/App/Auth/db/select.py b/App/Auth/db/select.py deleted file mode 100644 index 22cc3e7..0000000 --- a/App/Auth/db/select.py +++ /dev/null @@ -1,12 +0,0 @@ -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/Auth/description.txt b/App/Auth/description.txt deleted file mode 100644 index b8d4d0b..0000000 --- a/App/Auth/description.txt +++ /dev/null @@ -1,13 +0,0 @@ -. -├── auth_model.py - реализация модели авторизации -├── db -│   ├── DBconnect.py - коннектор к СУБД -│   ├── __init__.py - файл для инициализации db как модуль -│   ├── select.py - файл для выполнения select-запросов к СУБД -│   └── sql_provider.py - SQL-провайдер для формирования запроса к СУБД -├── __init__.py - файл для инициализации Auth как модуль -├── sql -│   └── auth.sql - sql-запрос, проверяющий наличие пользователя в СУБД -└── templates - └── auth.html - шаблон для страницы авторизации - diff --git a/App/Auth/db/DBconnect.py b/App/Database/DBconnect.py similarity index 91% rename from App/Auth/db/DBconnect.py rename to App/Database/DBconnect.py index b335654..2280c13 100644 --- a/App/Auth/db/DBconnect.py +++ b/App/Database/DBconnect.py @@ -13,7 +13,8 @@ class DBContextManager: port=self.db_config['port'], user=self.db_config['user'], password=self.db_config['password'], - db=self.db_config['db'] + db=self.db_config['db'], + charset=self.db_config['charset'] ) self.cursor = self.connection.cursor() return self.cursor diff --git a/App/Auth/db/__init__.py b/App/Database/__init__.py similarity index 100% rename from App/Auth/db/__init__.py rename to App/Database/__init__.py diff --git a/App/Auth/db/sql_provider.py b/App/Database/sql_provider.py similarity index 100% rename from App/Auth/db/sql_provider.py rename to App/Database/sql_provider.py diff --git a/App/Report/db/work.py b/App/Database/work.py similarity index 83% rename from App/Report/db/work.py rename to App/Database/work.py index 2fd1ff3..6437858 100644 --- a/App/Report/db/work.py +++ b/App/Database/work.py @@ -11,7 +11,7 @@ def select_list(db_config, sql) -> list: lst = [dict(zip(schema, row)) for row in result] return lst -def procedure(db_config, name, args: tuple): +def procedure(db_config, name, args: tuple) -> list: with DBContextManager(db_config) as cursor: if cursor is None: raise ValueError("Cursor not created") @@ -20,4 +20,8 @@ def procedure(db_config, name, args: tuple): result = cursor.fetchall()[0] schema = cursor.description[0] lst = dict(zip(schema, result)) - return lst \ No newline at end of file + return lst + +def transaction(cursor, sql): + cursor.execute(sql) + return True \ No newline at end of file diff --git a/App/Report/__init__.py b/App/Report/__init__.py index 920a71c..ee25b68 100644 --- a/App/Report/__init__.py +++ b/App/Report/__init__.py @@ -5,10 +5,10 @@ from datetime import date from .report_model import view_report_model, create_report_model import json -with open(path.join(path.dirname(__file__), 'reports.json')) as f: +with open(path.join(path.dirname(__file__), 'reports.json'), encoding='utf-8') as f: report_list = json.load(f) -report_bp = Blueprint('report_bp', __name__, template_folder='templates') +report_bp = Blueprint('report_bp', __name__, template_folder='templates', static_folder='static') @report_bp.route('/menu') @check_auth diff --git a/App/Report/db/DBconnect.py b/App/Report/db/DBconnect.py deleted file mode 100644 index b335654..0000000 --- a/App/Report/db/DBconnect.py +++ /dev/null @@ -1,34 +0,0 @@ -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/Report/db/__init__.py b/App/Report/db/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/App/Report/db/sql_provider.py b/App/Report/db/sql_provider.py deleted file mode 100644 index a3a1855..0000000 --- a/App/Report/db/sql_provider.py +++ /dev/null @@ -1,14 +0,0 @@ -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/Report/description.txt b/App/Report/description.txt deleted file mode 100644 index 6908431..0000000 --- a/App/Report/description.txt +++ /dev/null @@ -1,16 +0,0 @@ -. -├── db -│   ├── DBconnect.py - коннектор к СУБД -│   ├── __init__.py - файл для инициализации db как модуль -│   ├── sql_provider.py - SQL-провайдер для формирования запроса к СУБД -│   └── work.py - файл для выполнения select и call запросов -├── __init__.py - файл для инициализации Report как модуль -├── report_model.py - реализация модели варианта работы с отчётами -├── reports.json - файл с информацией о вариантах отчётов -├── sql  -│   ├── sellers_report.sql - sql-запрос для просмотра отчёта о поставках поставщиков -│   └── workpiece_report.sql - sql-запрос для просмотра отчёта о поставках заготовок -└── templates - ├── OK.html - шаблон для вывода информации об успешном добавлении отчета в БД - ├── report_basic.html - шаблон для ввода параметров просмотра/создания отчёта - └── report_menu.html - шаблон для выбора просмотра/создания отчёта \ No newline at end of file diff --git a/App/Report/report_model.py b/App/Report/report_model.py index 8127f5e..9125413 100644 --- a/App/Report/report_model.py +++ b/App/Report/report_model.py @@ -1,6 +1,8 @@ from dataclasses import dataclass -from .db.work import select_list, procedure -from .db.sql_provider import SQLProvider + +from Database.work import select_list, procedure +from Database.sql_provider import SQLProvider + from flask import current_app, session from os import path @@ -12,7 +14,9 @@ class InfoRespronse: status: bool def check_report(input_data: dict) -> bool: - result = procedure(current_app.config['db_config'], 'check_report', tuple(input_data.values())) + db_config = current_app.config['db_config'] + + result = procedure(db_config, 'check_report', tuple(input_data.values())) if result is None or result['exist'] == 0: return False return True @@ -32,9 +36,10 @@ def view_report_model(request, report_list: dict) -> InfoRespronse: error_message = 'Отчет не найден', status=False) + db_config = current_app.config['db_config'] view_script = report_list[id]['data']['view'] _sql = sql_provider.get(f'{view_script}.sql', data) - result = select_list(current_app.config['db_config'], _sql) + result = select_list(db_config, _sql) if result is None: return InfoRespronse((), error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором', @@ -60,9 +65,10 @@ def create_report_model(request, report_list: dict) -> InfoRespronse: error_message = 'Отчет уже существует', status=False) + db_config = current_app.config['db_config'] proc_name = report_list[id]['data']['procedure'] args = tuple(data.values()) - result = procedure(current_app.config['db_config'], proc_name, args) + result = procedure(db_config, proc_name, args) if result is None: return InfoRespronse((), diff --git a/App/static/css/report.css b/App/Report/static/css/report.css similarity index 100% rename from App/static/css/report.css rename to App/Report/static/css/report.css diff --git a/App/static/js/check.js b/App/Report/static/js/check.js similarity index 100% rename from App/static/js/check.js rename to App/Report/static/js/check.js diff --git a/App/Report/templates/report_basic.html b/App/Report/templates/report_basic.html index 03e0f3a..2f79c89 100644 --- a/App/Report/templates/report_basic.html +++ b/App/Report/templates/report_basic.html @@ -4,7 +4,7 @@ {{ title }} - + - +
diff --git a/App/Report/templates/report_menu.html b/App/Report/templates/report_menu.html index d55d621..919bd42 100644 --- a/App/Report/templates/report_menu.html +++ b/App/Report/templates/report_menu.html @@ -29,7 +29,7 @@
diff --git a/App/Requests/db/DBconnect.py b/App/Requests/db/DBconnect.py deleted file mode 100644 index b335654..0000000 --- a/App/Requests/db/DBconnect.py +++ /dev/null @@ -1,34 +0,0 @@ -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 deleted file mode 100644 index e69de29..0000000 diff --git a/App/Requests/db/select.py b/App/Requests/db/select.py deleted file mode 100644 index 22cc3e7..0000000 --- a/App/Requests/db/select.py +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index a3a1855..0000000 --- a/App/Requests/db/sql_provider.py +++ /dev/null @@ -1,14 +0,0 @@ -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/description.txt b/App/Requests/description.txt deleted file mode 100644 index 1b4d300..0000000 --- a/App/Requests/description.txt +++ /dev/null @@ -1,18 +0,0 @@ -. -├── db -│   ├── DBconnect.py - коннектор к СУБД -│   ├── __init__.py - файл для инициализации db как модуль -│   ├── select.py - файл для выполнения select-запросов к СУБД -│   └── sql_provider.py - SQL-провайдер для формирования запроса к СУБД -├── __init__.py - файл для инициализации Requests как модуль -├── requests_model.py - реализация модели варианта работы с запросами -├── sql -│   ├── materials_names.sql - sql-запрос для получения списка материалоа заготовок -│   ├── sellers_names.sql - sql-запрос для получения списка поставщиков -│   ├── ship_seller.sql - sql-запрос для получения списка поставок поставщиком -│   └── sklad_material.sql - sql-запрос для получения списка заготовок на складе -├── templates -│   ├── sellers_ship.html - шаблон для формы передачи параметров для запроса всех поставок выбранного поставщика -│   ├── zagotovki.html - шаблон для формы передачи параметров для запроса количества заготовок на складе -│   └── zapros_menu.html - шаблон для выбора варианта отчёта -└── zapros_menu.json - файл с названиями запросов и их ссылками \ No newline at end of file diff --git a/App/Requests/requests_model.py b/App/Requests/requests_model.py index 3841ef7..e23513b 100644 --- a/App/Requests/requests_model.py +++ b/App/Requests/requests_model.py @@ -1,6 +1,8 @@ from dataclasses import dataclass -from .db.select import select_list -from .db.sql_provider import SQLProvider + +from Database.work import select_list +from Database.sql_provider import SQLProvider + from flask import current_app from os import path @@ -12,8 +14,10 @@ class InfoRespronse: status: bool def sellers_names() -> InfoRespronse: + db_config = current_app.config['db_config'] + _sql = sql_provider.get('sellers_names.sql', {}) - result = select_list(current_app.config['db_config'], _sql) + result = select_list(db_config, _sql) if result is None: return InfoRespronse((), error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором', @@ -21,8 +25,10 @@ def sellers_names() -> InfoRespronse: return InfoRespronse(result, error_message='', status=True) def materials_names() -> InfoRespronse: + db_config = current_app.config['db_config'] + _sql = sql_provider.get('materials_names.sql', {}) - result = select_list(current_app.config['db_config'], _sql) + result = select_list(db_config, _sql) if result is None: return InfoRespronse((), error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором', @@ -30,9 +36,11 @@ def materials_names() -> InfoRespronse: return InfoRespronse(result, error_message='', status=True) def sklad(request) -> InfoRespronse: + db_config = current_app.config['db_config'] material = dict(request.form) + _sql = sql_provider.get('sklad_material.sql', material) - result = select_list(current_app.config['db_config'], _sql) + result = select_list(db_config, _sql) if result is None: return InfoRespronse((), error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором', @@ -41,9 +49,11 @@ def sklad(request) -> InfoRespronse: def materials_per_seller(request) -> InfoRespronse: + db_config = current_app.config['db_config'] + seller = dict(request.form) _sql = sql_provider.get('ship_seller.sql', seller) - result = select_list(current_app.config['db_config'], _sql) + result = select_list(db_config, _sql) if result is None: return InfoRespronse((), error_message = 'Ошибка в подключении к базе данных. Свяжитесь с администратором', diff --git a/App/Waybill/__init__.py b/App/Waybill/__init__.py index 55276bc..2701981 100644 --- a/App/Waybill/__init__.py +++ b/App/Waybill/__init__.py @@ -1,7 +1,7 @@ -from flask import request, Blueprint, render_template, session, redirect, url_for +from flask import Blueprint, render_template, redirect, url_for, session, request from checker import check_auth from .model import index_waybill, form_waybill, clear, button_click, transaction_order_model -from datetime import date +from datetime import datetime waybill_bp = Blueprint('waybill_bp', __name__, template_folder='templates', static_folder='static') @@ -37,7 +37,7 @@ def save_order(): return redirect(url_for('waybill_bp.index')) user_id = session.get('user_id',"") - current_date = date.today().strftime("%Y-%m-%d") + ' ' + date.today().strftime("%H:%M:%S") + current_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S") result = transaction_order_model(user_id, current_date) if result.status: diff --git a/App/Waybill/db/DBconnect.py b/App/Waybill/db/DBconnect.py deleted file mode 100644 index b335654..0000000 --- a/App/Waybill/db/DBconnect.py +++ /dev/null @@ -1,34 +0,0 @@ -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/Waybill/db/__init__.py b/App/Waybill/db/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/App/Waybill/db/sql_provider.py b/App/Waybill/db/sql_provider.py deleted file mode 100644 index a3a1855..0000000 --- a/App/Waybill/db/sql_provider.py +++ /dev/null @@ -1,14 +0,0 @@ -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/Waybill/db/work.py b/App/Waybill/db/work.py deleted file mode 100644 index 5a7f039..0000000 --- a/App/Waybill/db/work.py +++ /dev/null @@ -1,16 +0,0 @@ -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 - -def transaction(cursor, sql): - cursor.execute(sql) - return True \ No newline at end of file diff --git a/App/Waybill/model.py b/App/Waybill/model.py index 01162b1..075f385 100644 --- a/App/Waybill/model.py +++ b/App/Waybill/model.py @@ -1,11 +1,11 @@ -from .db.sql_provider import SQLProvider -from .db.work import select_list, transaction -from .db.DBconnect import DBContextManager +from Database.sql_provider import SQLProvider +from Database.work import select_list +from Database.DBconnect import DBContextManager from flask import current_app, session from dataclasses import dataclass from datetime import date -from .cache.wrapper import fetch_from_cache +from cache.wrapper import fetch_from_cache import os @dataclass @@ -21,11 +21,15 @@ def clear(): session.pop('waybill') def form_waybill() -> list: + db_config = current_app.config['db_config'] + cache_config = current_app.config['cache_config'] + current_waybill = session.get('waybill',{}) waybill = [] for k,v in current_waybill.items(): _sql = sql_provider.get('one_good.sql', dict(work_id=k)) - product = select_list(current_app.config['db_config'], _sql)[0] + cache_select = fetch_from_cache(f'product_{k}', cache_config)(select_list) + product = cache_select(db_config, _sql)[0] product['amount'] = v waybill.append(product) return waybill @@ -37,6 +41,8 @@ def index_waybill() -> list: cache_select = fetch_from_cache('items_cached', cache_config)(select_list) _sql = sql_provider.get('goods.sql', {}) products = cache_select(db_config, _sql) + if products == None: + return [] return products @@ -72,13 +78,6 @@ def button_click(request): print(session['waybill']) session.modified = True - # elif request.form.get('product_display_plus'): - # # increasing count in waybill - - # amount = int(session['waybill'][str(product['work_id'])]) - # session['waybill'][str(product['work_id'])] = str(amount + 1) - # session.modified = True - elif request.form.get('product_display_minus'): # decreasing count in waybill @@ -101,23 +100,20 @@ def transaction_order_model(user_id: int, current_date: date): with DBContextManager(db_config) as cursor: data = dict(e_user_id=user_id, e_order_date=current_date, e_total=total) - - _sql = sql_provider.get('create_order.sql', data) try: + _sql = sql_provider.get('create_order.sql', data) cursor.execute(_sql) + + order_id = cursor.lastrowid + for key, value in waybill.items(): + _sql = sql_provider.get('insert_order_line.sql', + dict(e_order_id = order_id, + e_price = 0, + e_prod_id = int(key), + e_amount = int(value))) + cursor.execute(_sql) except: return InfoRespronse((), error_message="Заказ не был создан", status=False) - - order_id = cursor.lastrowid - for key, value in waybill.items(): - _sql = sql_provider.get('insert_order_line.sql', - dict(e_order_id = order_id, - e_prod_id = int(key), - e_amount = int(value))) - try: - cursor.execute(_sql) - except: - return InfoRespronse((), error_message="Заказ не был создан", status=False) result = tuple([order_id]) clear() diff --git a/App/Waybill/sql/good_price.sql b/App/Waybill/sql/good_price.sql new file mode 100644 index 0000000..d01f1ec --- /dev/null +++ b/App/Waybill/sql/good_price.sql @@ -0,0 +1 @@ +SELECT price FROM workpiece WHERE work_id = $e_prod_id \ No newline at end of file diff --git a/App/Waybill/sql/goods.sql b/App/Waybill/sql/goods.sql index 9a18e9b..ad8e437 100644 --- a/App/Waybill/sql/goods.sql +++ b/App/Waybill/sql/goods.sql @@ -1 +1 @@ -SELECT work_id, name, price, material, count FROM workpiece \ No newline at end of file +SELECT work_id, name, price, material, count, weight FROM workpiece \ No newline at end of file diff --git a/App/Waybill/sql/insert_order_line.sql b/App/Waybill/sql/insert_order_line.sql index 26091a8..4eaeb65 100644 --- a/App/Waybill/sql/insert_order_line.sql +++ b/App/Waybill/sql/insert_order_line.sql @@ -1,2 +1 @@ -INSERT INTO `waybill_lines` VALUES ($e_order_id, $e_prod_id, -(SELECT price FROM workpiece WHERE work_id = $e_prod_id), $e_amount); \ No newline at end of file +INSERT INTO `waybill_lines` VALUES ($e_order_id, $e_prod_id, $e_price, $e_amount); \ No newline at end of file diff --git a/App/Waybill/templates/card.html b/App/Waybill/templates/card.html index b6248d6..b5dd9e5 100644 --- a/App/Waybill/templates/card.html +++ b/App/Waybill/templates/card.html @@ -4,6 +4,8 @@
{{ item['name'] }}

Цена: {{ item['price'] }} ₽

+

Материал: {{ item['material'] }}

+

Вес: {{ item['weight'] }} г

{% if show_amount %} Количество: {{item['amount']}}
diff --git a/App/auth.txt b/App/auth.txt new file mode 100644 index 0000000..b51cd9d --- /dev/null +++ b/App/auth.txt @@ -0,0 +1,13 @@ +. +├── Database +│   ├── DBconnect.py - коннектор к СУБД +│   ├── __init__.py +│   ├── sql_provider.py - SQL-провайдер для формирования запроса к СУБД +│   └── work.py - файл для выполнения запросов к СУБД +└── Auth +    ├── auth_model.py - реализация модели авторизации +    ├── __init__.py +    ├── sql +    │   └── auth.sql - sql-запрос, проверяющий наличие пользователя в СУБД +    └── templates +    └── auth.html - шаблон для страницы авторизации diff --git a/App/Waybill/cache/__init__.py b/App/cache/__init__.py similarity index 100% rename from App/Waybill/cache/__init__.py rename to App/cache/__init__.py diff --git a/App/Waybill/cache/wrapper.py b/App/cache/wrapper.py similarity index 54% rename from App/Waybill/cache/wrapper.py rename to App/cache/wrapper.py index ff38803..11cd216 100644 --- a/App/Waybill/cache/wrapper.py +++ b/App/cache/wrapper.py @@ -1,17 +1,16 @@ from functools import wraps -from Waybill.cache import RedisCache +from . import RedisCache def fetch_from_cache(cache_name: str, cache_config: dict): cache_conn = RedisCache(cache_config['redis']) ttl = cache_config['ttl'] + + """ + It checks if a cached value exists for a given cache_name. + If a cached value exists, it returns the cached value. + If no cached value exists, it calls the original function f with the provided arguments, caches the result, and then returns the result. + """ def decorator(f): - # как оно работает - # лезем в кэш и смотрим, есть ли там что-то - # если есть, то возвращаем кэшированную информацию - # если нет, то запускаем декорируемую функцию - # достаём оттуда информацию - # заносим её в кэш - # возвращаем кэшированную информацию @wraps(f) def wrapper(*args, **kwargs): cached_value = cache_conn.get_value(cache_name) diff --git a/App/data/config.json b/App/data/config.json index 8b7b193..0f0565b 100644 --- a/App/data/config.json +++ b/App/data/config.json @@ -3,5 +3,6 @@ "port": 3306, "user": "manager", "password": "ilikepizza", - "db": "sklad" + "db": "sklad", + "charset": "utf8" } \ No newline at end of file diff --git a/App/description.txt b/App/description.txt deleted file mode 100644 index 4c64a2b..0000000 --- a/App/description.txt +++ /dev/null @@ -1,16 +0,0 @@ - -. -├── app.py - основное приложение -├── checker.py - декораторы -├── data -│   ├── config.json - конфигурация для подключения к СУБД -│   └── db_access.json - доступ пользователей к вариантам использования ИС -├── static -│   └── css - стили для страниц -│   ├── auth.css -│   ├── main.css -│   └── output.css -└── templates - ├── error.html - универсальный шаблон для ошибок - ├── main_menu.html - шаблон главного меню - └── output.html - универсальный шаблон для вывода результатов diff --git a/App/main.txt b/App/main.txt new file mode 100644 index 0000000..e565e32 --- /dev/null +++ b/App/main.txt @@ -0,0 +1,19 @@ +. +├── app.py - основное приложение +├── checker.py - декораторы +├── data +│   ├── config.json - конфигурация для подключения к СУБД +│   ├── db_access.json - доступ пользователей к вариантам использования ИС +│   └── redis_config.json - конфигурация для подключения к Redis +├── Database +│   ├── DBconnect.py - коннектор к СУБД +│   ├── __init__.py +│   ├── sql_provider.py - SQL-провайдер для формирования запроса к СУБД +│   └── work.py - файл для выполнения запросов к СУБД +├── static +│   └── css - стили для страниц +│   └── main.css +└── templates - стандартные шаблоны для страниц +    ├── error.html - шаблон для ошибок +    ├── main_menu.html - шаблон главного меню +    └── output.html - шаблон для вывода результатов в формате таблицы diff --git a/App/report.txt b/App/report.txt new file mode 100644 index 0000000..7ae310a --- /dev/null +++ b/App/report.txt @@ -0,0 +1,22 @@ +. +├── Database +│   ├── DBconnect.py - коннектор к СУБД +│   ├── __init__.py +│   ├── sql_provider.py - SQL-провайдер для формирования запроса к СУБД +│   └── work.py - файл для выполнения запросов к СУБД +└── Report +    ├── __init__.py +    ├── report_model.py - реализация модели работы с отчётами +    ├── reports.json - файл с информацией о вариантах отчётов +    ├── sql +    │   ├── sellers_report.sql - sql-запрос для просмотра отчёта о поставках поставщиков +    │ └── workpiece_report.sql - sql-запрос для просмотра отчёта о поставках заготовок +    ├── static +    │   ├── css - стили страниц +    │   │   └── report.css +    │   └── js +    │   └── check.js - проверка периода формирования отчёта +    └── templates +    ├── OK.html - шаблон для вывода информации об успешном добавлении отчета в БД + ├── report_basic.html - шаблон для ввода параметров просмотра/создания отчёта + └── report_menu.html - шаблон для выбора просмотра/создания отчёта \ No newline at end of file diff --git a/App/requests.txt b/App/requests.txt new file mode 100644 index 0000000..3682d42 --- /dev/null +++ b/App/requests.txt @@ -0,0 +1,19 @@ +. +├── Database +│   ├── DBconnect.py - коннектор к СУБД +│   ├── __init__.py +│   ├── sql_provider.py - SQL-провайдер для формирования запроса к СУБД +│   └── work.py - файл для выполнения запросов к СУБД +└── Requests +    ├── __init__.py +    ├── requests_model.py - реализация модели работы с запросами +    ├── sql +    │   ├── materials_names.sql - sql-запрос для получения списка материалов заготовок +   │   ├── sellers_names.sql - sql-запрос для получения списка поставщиков +   │   ├── ship_seller.sql - sql-запрос для получения списка поставок поставщиком +   │   └── sklad_material.sql - sql-запрос для получения списка заготовок на складе +   ├── templates +   │   ├── sellers_ship.html - шаблон для формы передачи параметров для запроса всех поставок выбранного поставщика + │   ├── zagotovki.html - шаблон для формы передачи параметров для запроса количества заготовок на складе + │   └── zapros_menu.html - шаблон для выбора варианта отчёта +   └── zapros_menu.json - файл с названиями запросов и их ссылками \ No newline at end of file diff --git a/App/static/css/auth.css b/App/static/css/auth.css deleted file mode 100644 index 286c3d1..0000000 --- a/App/static/css/auth.css +++ /dev/null @@ -1,5 +0,0 @@ -form[name="auth"] input[type="submit"] { - display: block; - margin: 10px auto; - background-color: #f2c464; -} \ No newline at end of file diff --git a/App/templates/main_menu.html b/App/templates/main_menu.html index 473c62e..0c4fb6c 100644 --- a/App/templates/main_menu.html +++ b/App/templates/main_menu.html @@ -33,8 +33,11 @@
+ {% if 'role' in ses and ses['access_user'] == 'internal_users'%} +

Ваша роль: {{ ses['role'] }}

+ {% endif %}
-
+
{% if 'role' not in ses %}

Для доступа к функциям системы необходимо авторизоваться

diff --git a/App/waybill.txt b/App/waybill.txt new file mode 100644 index 0000000..ca0117f --- /dev/null +++ b/App/waybill.txt @@ -0,0 +1,25 @@ +. +├── cache - модуль для кэширования данных +│ ├── __init__.py +│ └── wrapper.py - файл с функцией-обёрткой для кэширования функций +├── Database +│   ├── DBconnect.py - коннектор к СУБД +│   ├── __init__.py +│   ├── sql_provider.py - SQL-провайдер для формирования запроса к СУБД +│   └── work.py - файл для выполнения запросов к СУБД +└── Waybill + ├── __init__.py + ├── model.py - реализация модели оформления накладной + ├── sql + │ ├── create_order.sql - SQL запрос на создание накладной + │ ├── goods.sql - SQL запрос на получение списка заготовок + │ ├── insert_order_line.sql - SQL запрос на добавление позиции в накладную + │ └── one_good.sql - SQL запрос на получение информации о заготовке + ├── static + │ └── css - стили страниц + │ └── waybill.css + └── templates + ├── card.html - шаблон для отображения карточки заготовки + ├── order_finish.html - шаблон для страницы о завершении оформления накладной + └── waybill.html - шаблон для страницы формированиянакладной + diff --git a/cache_delete.sh b/cache_delete.sh new file mode 100755 index 0000000..3890bd7 --- /dev/null +++ b/cache_delete.sh @@ -0,0 +1 @@ +find . -type d -name "__pycache__" -exec rm -rf {} + \ No newline at end of file