|
@@ -15,15 +15,20 @@ from bottle import (
|
|
|
template,
|
|
|
static_file,
|
|
|
)
|
|
|
+from pandas import DataFrame
|
|
|
from psycopg import connect
|
|
|
from psycopg.sql import SQL, Literal
|
|
|
from threading import Thread
|
|
|
|
|
|
+from app.data.QueryManager import QueryManager, get_data
|
|
|
+
|
|
|
from ..data.filter import(
|
|
|
get_filter,
|
|
|
get_query_param,
|
|
|
)
|
|
|
-
|
|
|
+from .form import (
|
|
|
+ get_form,
|
|
|
+)
|
|
|
from ..data.util import(
|
|
|
get_where_include_exclude
|
|
|
)
|
|
@@ -71,7 +76,6 @@ ORDER BY "Product", "Category", "Group"
|
|
|
""").format(having=having) if having else SQL('')
|
|
|
])
|
|
|
|
|
|
-
|
|
|
def normalize_query(query: FormsDict, allow: Iterable[str] = None) -> str:
|
|
|
param = get_filter(query, allow=allow)
|
|
|
return urlencode([
|
|
@@ -123,24 +127,29 @@ def trend():
|
|
|
@normalize
|
|
|
def groups():
|
|
|
filters = get_filter(request.query, allow=('group', 'category', 'product'))
|
|
|
- form = template('form-nav', action='groups', method='get', params=[
|
|
|
- {'name': k, 'value': request.params[k]} for k in request.params if k in PARAMS
|
|
|
- ])
|
|
|
+ _filter = get_filter(request.query, allow=PARAMS)
|
|
|
try:
|
|
|
with conn.cursor() as cur:
|
|
|
inner = get_product_rollup_statement(
|
|
|
filters,
|
|
|
having=SQL("c.name IS NULL")
|
|
|
)
|
|
|
- xml = cur.execute(SQL("""
|
|
|
-SELECT query_to_xml_and_xmlschema({q}, false, false, ''::text)
|
|
|
-""").format(q=Literal(SQL("""SELECT
|
|
|
+ query = SQL("""
|
|
|
+SELECT
|
|
|
"Products",
|
|
|
"Categories",
|
|
|
COALESCE("Group", "Groups"||'') "Group"
|
|
|
FROM (
|
|
|
{inner}
|
|
|
-) q""").format(inner=inner).as_string(cur)))).fetchone()[0]
|
|
|
+) q
|
|
|
+""").format(inner=inner)
|
|
|
+ data = DataFrame(list(get_data(cur, query))[:-1])
|
|
|
+ data['$/unit'] = 1
|
|
|
+ data['group'] = data['Group']
|
|
|
+ form = get_form(request.path.split('/')[-1], 'get', _filter, data)
|
|
|
+ xml = cur.execute(SQL("""
|
|
|
+SELECT query_to_xml_and_xmlschema({q}, false, false, ''::text)
|
|
|
+""").format(q=Literal(query.as_string(cur)))).fetchone()[0]
|
|
|
finally:
|
|
|
conn.commit()
|
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
@@ -150,6 +159,7 @@ FROM (
|
|
|
@normalize
|
|
|
def categories():
|
|
|
filters = get_filter(request.query, allow=('group', 'category', 'product'))
|
|
|
+ _filter = get_filter(request.query, allow=PARAMS)
|
|
|
form = template('form-nav', action='categories', method='get', params=[
|
|
|
{'name': k, 'value': request.params[k]} for k in request.params if k in PARAMS
|
|
|
])
|
|
@@ -159,15 +169,23 @@ def categories():
|
|
|
filters,
|
|
|
having=SQL("p.name IS NULL AND (c.name IS NOT NULL OR g.name IS NULL)")
|
|
|
)
|
|
|
- xml = cur.execute(SQL("""
|
|
|
-SELECT query_to_xml_and_xmlschema({q}, false, false, ''::text)
|
|
|
-""").format(q=Literal(SQL("""SELECT
|
|
|
+ query = SQL("""
|
|
|
+SELECT
|
|
|
"Products",
|
|
|
COALESCE("Category", "Categories"||'') "Category",
|
|
|
COALESCE("Group", "Groups"||'') "Group"
|
|
|
FROM (
|
|
|
{inner}
|
|
|
-) q""").format(inner=inner).as_string(cur)))).fetchone()[0]
|
|
|
+) q
|
|
|
+""").format(inner=inner)
|
|
|
+ data = DataFrame(list(get_data(cur, query))[:-1])
|
|
|
+ data['$/unit'] = 1
|
|
|
+ data['group'] = data['Group']
|
|
|
+ data['category'] = data['Category']
|
|
|
+ form = get_form(request.path.split('/')[-1], 'get', _filter, data)
|
|
|
+ xml = cur.execute(SQL("""
|
|
|
+SELECT query_to_xml_and_xmlschema({q}, false, false, ''::text)
|
|
|
+""").format(q=Literal(query.as_string(cur)))).fetchone()[0]
|
|
|
finally:
|
|
|
conn.commit()
|
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
@@ -177,6 +195,7 @@ FROM (
|
|
|
@normalize
|
|
|
def products():
|
|
|
filters = get_filter(request.query, allow=('group', 'category', 'product'))
|
|
|
+ _filter = get_filter(request.query, allow=PARAMS)
|
|
|
form = template('form-nav', action='products', method='get', params=[
|
|
|
{'name': k, 'value': request.params[k]} for k in request.params if k in PARAMS
|
|
|
])
|
|
@@ -186,16 +205,25 @@ def products():
|
|
|
filters,
|
|
|
having=SQL("p.name IS NOT NULL OR g.name IS NULL")
|
|
|
)
|
|
|
- xml = cur.execute(SQL("""
|
|
|
-SELECT query_to_xml_and_xmlschema({q}, false, false, ''::text)
|
|
|
-""").format(q=Literal(SQL("""SELECT
|
|
|
+ query = SQL("""
|
|
|
+SELECT
|
|
|
--"Transactions",
|
|
|
COALESCE("Product", "Products"||'') "Product",
|
|
|
COALESCE("Category", "Categories"||'') "Category",
|
|
|
COALESCE("Group", "Groups"||'') "Group"
|
|
|
FROM (
|
|
|
{inner}
|
|
|
-) q""").format(inner=inner).as_string(cur)))).fetchone()[0]
|
|
|
+) q
|
|
|
+""").format(inner=inner)
|
|
|
+ data = DataFrame(list(get_data(cur, query))[:-1])
|
|
|
+ data['$/unit'] = 1
|
|
|
+ data['product'] = data['Product']
|
|
|
+ data['group'] = data['Group']
|
|
|
+ data['category'] = data['Category']
|
|
|
+ form = get_form(request.path.split('/')[-1], 'get', _filter, data)
|
|
|
+ xml = cur.execute(SQL("""
|
|
|
+SELECT query_to_xml_and_xmlschema({q}, false, false, ''::text)
|
|
|
+""").format(q=Literal(query.as_string(cur)))).fetchone()[0]
|
|
|
finally:
|
|
|
conn.commit()
|
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|