Initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
__pycache__/
|
||||
13
App/Queries/category_list.py
Normal file
13
App/Queries/category_list.py
Normal file
@@ -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 """
|
||||
11
App/Queries/req.py
Normal file
11
App/Queries/req.py
Normal file
@@ -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')
|
||||
17
App/Queries/templates/sklad_zapros.html
Normal file
17
App/Queries/templates/sklad_zapros.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Hello World</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello World</h1>
|
||||
<form action="" method="post">
|
||||
<select name="categories" size="10" multiple>
|
||||
{% for category in categories %}
|
||||
<option value="{{ category }}">{{ category }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
22
App/app.py
Normal file
22
App/app.py
Normal file
@@ -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)
|
||||
34
App/db/DBconnect.py
Normal file
34
App/db/DBconnect.py
Normal file
@@ -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
|
||||
|
||||
7
App/db/config.json
Normal file
7
App/db/config.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"host": "localhost",
|
||||
"port": 3306,
|
||||
"user": "manager",
|
||||
"password": "ilikepizza",
|
||||
"db": "sklad"
|
||||
}
|
||||
14
App/db/sql_provider.py
Normal file
14
App/db/sql_provider.py
Normal file
@@ -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)
|
||||
10
App/templates/index.html
Normal file
10
App/templates/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Hello World</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello World</h1>
|
||||
</body>
|
||||
</html>
|
||||
88
Docs/UML.drawio
Normal file
88
Docs/UML.drawio
Normal file
@@ -0,0 +1,88 @@
|
||||
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0" version="24.7.17">
|
||||
<diagram name="Страница — 1" id="TNe6ncNLo5hcW_pl08e7">
|
||||
<mxGraphModel dx="774" dy="521" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="1">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" parent="0" />
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-20" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.083;entryY=0.382;entryDx=0;entryDy=0;entryPerimeter=0;endArrow=none;endFill=0;" edge="1" parent="1" source="w1SBJSc8j8FciuZsk6MN-5" target="w1SBJSc8j8FciuZsk6MN-18">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-21" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.167;entryY=0.618;entryDx=0;entryDy=0;entryPerimeter=0;endArrow=none;endFill=0;" edge="1" parent="1" source="w1SBJSc8j8FciuZsk6MN-6" target="w1SBJSc8j8FciuZsk6MN-18">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-22" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.333;entryY=0.853;entryDx=0;entryDy=0;entryPerimeter=0;endArrow=none;endFill=0;" edge="1" parent="1" source="w1SBJSc8j8FciuZsk6MN-8" target="w1SBJSc8j8FciuZsk6MN-18">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-19" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.083;entryY=0.147;entryDx=0;entryDy=0;entryPerimeter=0;endArrow=none;endFill=0;" edge="1" parent="1" source="w1SBJSc8j8FciuZsk6MN-4" target="w1SBJSc8j8FciuZsk6MN-18">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-1" value="<div>Менеджер</div>" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
|
||||
<mxGeometry x="184" y="190" width="30" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-2" value="<div>Управляющий</div>" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
|
||||
<mxGeometry x="184" y="300" width="30" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-3" value="<div>Поставщик</div>" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
|
||||
<mxGeometry x="184" y="80" width="30" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-4" value="<div>Оформление</div><div>накладной<br></div>" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="344" y="80" width="120" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-5" value="Авторизация" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="344" y="160" width="120" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-6" value="Работа с запросами" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="344" y="240" width="120" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-8" value="<div>Редактирование</div>" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="344" y="320" width="120" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-10" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" target="w1SBJSc8j8FciuZsk6MN-6">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="224" y="340" as="sourcePoint" />
|
||||
<mxPoint x="324" y="250" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-11" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" target="w1SBJSc8j8FciuZsk6MN-5">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="224" y="340" as="sourcePoint" />
|
||||
<mxPoint x="344" y="270" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-12" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="224" y="340" as="sourcePoint" />
|
||||
<mxPoint x="344" y="345" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-13" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" target="w1SBJSc8j8FciuZsk6MN-5">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="224" y="230" as="sourcePoint" />
|
||||
<mxPoint x="354" y="200" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-14" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" target="w1SBJSc8j8FciuZsk6MN-6">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="224" y="230" as="sourcePoint" />
|
||||
<mxPoint x="354" y="200" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-15" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" target="w1SBJSc8j8FciuZsk6MN-4">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="214" y="120" as="sourcePoint" />
|
||||
<mxPoint x="334" y="80" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-16" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" target="w1SBJSc8j8FciuZsk6MN-5">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="214" y="120" as="sourcePoint" />
|
||||
<mxPoint x="354" y="120" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="w1SBJSc8j8FciuZsk6MN-18" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="524" y="60" width="120" height="340" as="geometry" />
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
BIN
Docs/UML.drawio.png
Normal file
BIN
Docs/UML.drawio.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
4
Docs/UML.drawio.svg
Normal file
4
Docs/UML.drawio.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 24 KiB |
BIN
Docs/РПЗ_черновик.docx
Normal file
BIN
Docs/РПЗ_черновик.docx
Normal file
Binary file not shown.
7
config.json
Normal file
7
config.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"host": "localhost",
|
||||
"port": 3306,
|
||||
"user": "manager",
|
||||
"password": "ilikepizza",
|
||||
"db": "supermarket"
|
||||
}
|
||||
Reference in New Issue
Block a user