commit 19a5869d30044aedcf51d8c6df84b1c655ed2283 Author: Anton Kamalov Date: Mon Oct 21 22:42:14 2024 +0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba0430d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ \ No newline at end of file diff --git a/App/Queries/category_list.py b/App/Queries/category_list.py new file mode 100644 index 0000000..7bb44be --- /dev/null +++ b/App/Queries/category_list.py @@ -0,0 +1,13 @@ +import db.DBconnect + +sql_provider = 1 +""" 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/App/Queries/req.py b/App/Queries/req.py new file mode 100644 index 0000000..d5f4514 --- /dev/null +++ b/App/Queries/req.py @@ -0,0 +1,11 @@ +from flask import request, Blueprint, render_template, session, redirect, url_for +from os import path +from db.sql_provider import SQLProvider + +sql_provider = SQLProvider(path.join(path.dirname(__file__), 'sql')) +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 diff --git a/App/Queries/templates/sklad_zapros.html b/App/Queries/templates/sklad_zapros.html new file mode 100644 index 0000000..ed11431 --- /dev/null +++ b/App/Queries/templates/sklad_zapros.html @@ -0,0 +1,17 @@ + + + + + Hello World + + +

Hello World

+
+ +
+ + diff --git a/App/app.py b/App/app.py new file mode 100644 index 0000000..6ae5a20 --- /dev/null +++ b/App/app.py @@ -0,0 +1,22 @@ +from flask import Flask, redirect, render_template, url_for, session, request +from os import path +from Queries.req import requests_bp +import json + + +app = Flask(__name__) +app.secret_key = 'super secret key' +with open(path.join(path.dirname(__file__), 'db/config.json')) as f: + app.config['db_config'] = json.load(f) +app.register_blueprint(requests_bp, url_prefix='/requests') + + +@app.route('/') +def index(): + return render_template('index.html') + +@app.route('/logout') +def logout(): + session.clear() + return 'OK' +app.run(port=5001, debug=True) \ No newline at end of file diff --git a/App/db/DBconnect.py b/App/db/DBconnect.py new file mode 100644 index 0000000..b335654 --- /dev/null +++ b/App/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/db/config.json b/App/db/config.json new file mode 100644 index 0000000..75428e2 --- /dev/null +++ b/App/db/config.json @@ -0,0 +1,7 @@ +{ + "host": "localhost", + "port": 3306, + "user": "manager", + "password": "ilikepizza", + "db": "sklad" +} \ No newline at end of file diff --git a/App/db/sql_provider.py b/App/db/sql_provider.py new file mode 100644 index 0000000..a3a1855 --- /dev/null +++ b/App/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/templates/index.html b/App/templates/index.html new file mode 100644 index 0000000..c8905c5 --- /dev/null +++ b/App/templates/index.html @@ -0,0 +1,10 @@ + + + + + Hello World + + +

Hello World

+ + \ No newline at end of file diff --git a/Docs/UML.drawio b/Docs/UML.drawio new file mode 100644 index 0000000..143e0f7 --- /dev/null +++ b/Docs/UML.drawio @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Docs/UML.drawio.png b/Docs/UML.drawio.png new file mode 100644 index 0000000..ce05d77 Binary files /dev/null and b/Docs/UML.drawio.png differ diff --git a/Docs/UML.drawio.svg b/Docs/UML.drawio.svg new file mode 100644 index 0000000..2587208 --- /dev/null +++ b/Docs/UML.drawio.svg @@ -0,0 +1,4 @@ + + + +
Менеджер
Менеджер
Управляющий
Управляющий
Поставщик
Поставщик
Оформление
накладной
Оформлениенакладной...
Авторизация
Авторизация
Работа с запросами
Работа с запросами
Редактирование
Редактирование
Информационная система
Информационная система
\ No newline at end of file diff --git a/Docs/РПЗ_черновик.docx b/Docs/РПЗ_черновик.docx new file mode 100644 index 0000000..ae5ed50 Binary files /dev/null and b/Docs/РПЗ_черновик.docx differ diff --git a/config.json b/config.json new file mode 100644 index 0000000..b040922 --- /dev/null +++ b/config.json @@ -0,0 +1,7 @@ +{ + "host": "localhost", + "port": 3306, + "user": "manager", + "password": "ilikepizza", + "db": "supermarket" +} \ No newline at end of file