Fixes for linux

This commit is contained in:
Vassili Minaev 2025-03-17 16:55:43 -06:00
parent 708ee610f1
commit 6c30537db1
4 changed files with 87 additions and 81 deletions

View file

@ -1,6 +1,7 @@
from aiohttp import web from aiohttp import web
import aiohttp_security import aiohttp_security
import datetime import datetime
import aiomysql
import security import security
@ -16,9 +17,10 @@ def datetime_format(postdata):
def init_app(app): def init_app(app):
async def db_query(query, params=()): async def db_query(query, params=()):
await app['cur'].execute(query, params) cursor = await app['con'].cursor(aiomysql.DictCursor)
q = app['cur'].mogrify(query, params) await cursor.execute(query, params)
r = await app['cur'].fetchall() q = cursor.mogrify(query, params)
r = await cursor.fetchall()
result = [{k: (str(v) if isinstance(v, datetime.date) or isinstance(v, datetime.timedelta) else v) for k, v in row.items()} for row in r] result = [{k: (str(v) if isinstance(v, datetime.date) or isinstance(v, datetime.timedelta) else v) for k, v in row.items()} for row in r]
return (q, result) return (q, result)

View file

@ -0,0 +1,4 @@
[database]
db = "calendar"
user = "calendaruser"
password = "Cal@dm1n"

View file

@ -16,24 +16,24 @@ async def orders_by_employee(cursor, options):
query = """\ query = """\
SELECT SELECT
CONCAT(E.firstname, ' ', E.lastname) AS name, CONCAT(E.FirstName, ' ', E.LastName) AS name,
O.orderid, O.OrderID,
O.orderdate, O.OrderDate,
C.customername, C.CustomerName,
inter.value inter.value
FROM employees AS E FROM Employees AS E
INNER JOIN orders AS O ON E.employeeid = O.employeeid INNER JOIN Orders AS O ON E.EmployeeID = O.EmployeeID
LEFT JOIN customers AS C on O.customerid = C.customerid LEFT JOIN Customers AS C on O.CustomerID = C.CustomerID
INNER JOIN ( INNER JOIN (
SELECT SELECT
OD.orderid, OD.OrderID,
SUM(OD.quantity * P.price) AS value SUM(OD.Quantity * P.Price) AS value
FROM orderdetails AS OD FROM OrderDetails AS OD
LEFT JOIN products AS P ON OD.productid = P.productid LEFT JOIN Products AS P ON OD.ProductID = P.ProductID
WHERE P.categoryid IN ({}) WHERE P.CategoryID IN ({})
GROUP BY OD.orderid GROUP BY OD.OrderID
) AS inter ON o.orderid = inter.orderid ) AS inter ON O.OrderID = inter.OrderID
WHERE O.orderdate BETWEEN %s AND %s;""".format(",".join(['%s'] * len(options["category"]))) WHERE O.OrderDate BETWEEN %s AND %s;""".format(",".join(['%s'] * len(options["category"])))
await cursor.execute(query, [*options["category"].keys(), options["date"]["from"], options["date"]["to"]]) await cursor.execute(query, [*options["category"].keys(), options["date"]["from"], options["date"]["to"]])
rows = await cursor.fetchall() rows = await cursor.fetchall()
@ -68,22 +68,22 @@ async def orders_by_location(cursor, options):
query = """\ query = """\
SELECT SELECT
{}, {},
C.customername, C.CustomerName,
O.orderid, O.OrderID,
O.orderdate, O.OrderDate,
inter.value inter.value
FROM orders AS O FROM Orders AS O
LEFT JOIN customers AS C on O.customerid = C.customerid LEFT JOIN Customers AS C ON O.CustomerID = C.CustomerID
INNER JOIN ( INNER JOIN (
SELECT SELECT
OD.orderid, OD.OrderID,
SUM(OD.quantity * P.price) AS value SUM(OD.quantity * P.Price) AS value
FROM orderdetails AS OD FROM OrderDetails AS OD
LEFT JOIN products AS P ON OD.productid = P.productid LEFT JOIN Products AS P ON OD.ProductID = P.ProductID
WHERE P.categoryid IN ({}) WHERE P.CategoryID IN ({})
GROUP BY OD.orderid GROUP BY OD.OrderID
) AS inter ON o.orderid = inter.orderid ) AS inter ON O.OrderID = inter.OrderID
WHERE O.orderdate BETWEEN %s AND %s;\ WHERE O.OrderDate BETWEEN %s AND %s;\
""".format(location_query[options["location"]], ",".join(['%s'] * len(options["category"]))) """.format(location_query[options["location"]], ",".join(['%s'] * len(options["category"])))
await cursor.execute(query, [*options["category"].keys(), options["date"]["from"], options["date"]["to"]]) await cursor.execute(query, [*options["category"].keys(), options["date"]["from"], options["date"]["to"]])
@ -111,18 +111,18 @@ async def orders_by_product(cursor, options):
query = """\ query = """\
SELECT SELECT
P.productname, P.ProductName,
C.customername, C.CustomerName,
O.orderid, O.OrderID,
O.orderdate, O.OrderDate,
OD.quantity, OD.Quantity,
OD.quantity * P.price AS value OD.Quantity * P.Price AS value
FROM orderdetails AS OD FROM OrderDetails AS OD
LEFT JOIN orders AS O ON OD.orderid = O.orderid LEFT JOIN Orders AS O ON OD.OrderID = O.OrderID
LEFT JOIN products AS P ON OD.productid = P.productid LEFT JOIN Products AS P ON OD.ProductID = P.ProductID
LEFT JOIN customers AS C ON O.customerid = C.customerid LEFT JOIN Customers AS C ON O.CustomerID = C.CustomerID
WHERE P.categoryid IN ({}) WHERE P.CategoryID IN ({})
AND O.orderdate BETWEEN %s AND %s;\ AND O.OrderDate BETWEEN %s AND %s;\
""".format(",".join(['%s'] * len(options["category"]))) """.format(",".join(['%s'] * len(options["category"])))
await cursor.execute(query, [*options["category"].keys(), options["date"]["from"], options["date"]["to"]]) await cursor.execute(query, [*options["category"].keys(), options["date"]["from"], options["date"]["to"]])
@ -151,19 +151,19 @@ async def orders_by_supplier(cursor, options):
query = """\ query = """\
SELECT SELECT
S.suppliername, S.suppliername,
P.productname, P.ProductName,
C.customername, C.CustomerName,
O.orderid, O.OrderID,
O.orderdate, O.OrderDate,
OD.quantity, OD.Quantity,
OD.quantity * P.price AS value OD.Quantity * P.Price AS value
FROM orderdetails AS OD FROM OrderDetails AS OD
LEFT JOIN orders AS O ON OD.orderid = O.orderid LEFT JOIN Orders AS O ON OD.OrderID = O.OrderID
LEFT JOIN products AS P ON OD.productid = P.productid LEFT JOIN Products AS P ON OD.ProductID = P.ProductID
LEFT JOIN customers AS C ON O.customerid = C.customerid LEFT JOIN Customers AS C ON O.CustomerID = C.CustomerID
LEFT JOIN suppliers AS S ON P.supplierid = S.supplierid LEFT JOIN Suppliers AS S ON P.SupplierID = S.SupplierID
WHERE P.categoryid IN ({}) WHERE P.CategoryID IN ({})
AND O.orderdate BETWEEN %s AND %s;\ AND O.OrderDate BETWEEN %s AND %s;\
""".format(",".join(['%s'] * len(options["category"]))) """.format(",".join(['%s'] * len(options["category"])))
await cursor.execute(query, [*options["category"].keys(), options["date"]["from"], options["date"]["to"]]) await cursor.execute(query, [*options["category"].keys(), options["date"]["from"], options["date"]["to"]])
@ -207,40 +207,40 @@ async def pivot_table(cursor, options):
# SELECT, GROUP BY, JOIN # SELECT, GROUP BY, JOIN
parts = { parts = {
'none' : ("", "", ""), 'none' : ("", "", ""),
'month' : ("CONCAT(YEAR(o.orderdate), '-', LPAD(MONTH(o.orderdate), 2, '0')) AS month", "month", ""), 'month' : ("CONCAT(YEAR(O.OrderDate), '-', LPAD(MONTH(O.OrderDate), 2, '0')) AS month", "month", ""),
'year' : ("YEAR(o.orderdate) AS year", "year", ""), 'year' : ("YEAR(O.OrderDate) AS year", "year", ""),
'employee': ("CONCAT(E.firstname, ' ', E.lastname) AS employeename", 'employee': ("CONCAT(E.FirstName, ' ', E.LastName) AS employeename",
"employeename", "employeename",
"LEFT JOIN employees AS E ON O.employeeid = E.employeeid"), "LEFT JOIN Employees AS E ON O.EmployeeID = E.EmployeeID"),
'shipper' : ("SH.shippername", 'shipper' : ("SH.ShipperName",
"SH.shippername", "SH.ShipperName",
"LEFT JOIN shippers AS SH ON O.shipperid = SH.shipperid"), "LEFT JOIN Shippers AS SH ON O.ShipperID = SH.ShipperID"),
'customer': ("C.customername", 'customer': ("C.CustomerName",
"C.customername", "C.CustomerName",
"LEFT JOIN customers AS C ON O.customerid = C.customerid"), "LEFT JOIN Customers AS C ON O.CustomerID = C.CustomerID"),
'supplier': ("S.suppliername", 'supplier': ("S.SupplierName",
"S.suppliername", "S.SupplierName",
"LEFT JOIN suppliers AS S ON P.supplierid = S.supplierid"), "LEFT JOIN Suppliers AS S ON P.SupplierID = S.SupplierID"),
'category': ("CA.categoryname", 'category': ("CA.CategoryName",
"CA.categoryname", "CA.CategoryName",
"LEFT JOIN categories AS CA ON P.categoryid = CA.categoryid"), "LEFT JOIN Categories AS CA ON P.CategoryID = CA.CategoryID"),
'product' : ("P.productname", "P.productname", "") 'product' : ("P.ProductName", "P.ProductName", "")
} }
values = { values = {
'sales' : 'SUM(OD.quantity * P.price)', 'sales' : 'SUM(OD.Quantity * P.Price)',
'qty' : 'SUM(OD.quantity)' 'qty' : 'SUM(OD.Quantity)'
} }
query = """ query = """
SELECT SELECT
{rows} {columns} {values} {rows} {columns} {values}
FROM orderdetails AS OD FROM OrderDetails AS OD
LEFT JOIN orders AS O ON OD.orderid = O.orderid LEFT JOIN Orders AS O ON OD.OrderID = O.OrderID
LEFT JOIN products AS P ON OD.productid = P.productid LEFT JOIN Products AS P ON OD.ProductID = P.ProductID
{joins} {joins}
WHERE P.categoryid IN ({categories}) WHERE P.CategoryID IN ({categories})
AND O.orderdate BETWEEN %s AND %s AND O.OrderDate BETWEEN %s AND %s
GROUP BY {grouprows}{groupcols} GROUP BY {grouprows}{groupcols}
""".format( """.format(
rows=f"{parts[options['rows']][0]},", rows=f"{parts[options['rows']][0]},",

View file

@ -146,7 +146,7 @@
</section> </section>
</main> </main>
<script src="static/bs/bootstrap.bundle.min.js"></script> <script src="static/bootstrap/bootstrap.bundle.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
window.onload = () => { window.onload = () => {
const email = document.getElementById('email'); const email = document.getElementById('email');