|
@@ -169,7 +169,6 @@ def get_form(action, method, filter_data, data):
|
|
'category': 1,
|
|
'category': 1,
|
|
'group': 2,
|
|
'group': 2,
|
|
}[x])
|
|
}[x])
|
|
- in_chart = data['$/unit'].apply(lambda x: (x or False) and True)
|
|
|
|
return template('form', action=action, method=method,
|
|
return template('form', action=action, method=method,
|
|
**{
|
|
**{
|
|
k: {
|
|
k: {
|
|
@@ -283,7 +282,7 @@ def trend_internal(path, query):
|
|
|
|
|
|
f = StringIO()
|
|
f = StringIO()
|
|
plt.savefig(f, format='svg')
|
|
plt.savefig(f, format='svg')
|
|
- form = get_form(path, 'get', get_filter(request.query, allow=PARAMS), data)
|
|
|
|
|
|
+ form = get_form(path.split('/')[-1], 'get', get_filter(request.query, allow=PARAMS), data)
|
|
|
|
|
|
progress[-1]["status"] = "done"
|
|
progress[-1]["status"] = "done"
|
|
yield template("loading", progress=progress)
|
|
yield template("loading", progress=progress)
|
|
@@ -299,16 +298,13 @@ def trend_internal(path, query):
|
|
|
|
|
|
yield from iter(resp, lambda started=time(): time() - started > 600)
|
|
yield from iter(resp, lambda started=time(): time() - started > 600)
|
|
|
|
|
|
-@route('/grocery/xslt')
|
|
|
|
-def table():
|
|
|
|
- title = request.query['title'] if 'title' in request.query.keys() else None
|
|
|
|
- foot = request.query['foot'] == 'True' and "last()" if 'foot' in request.query.keys() else "-1"
|
|
|
|
- response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
|
|
- return template("query-to-xml-xslt", title=title, foot=foot)
|
|
|
|
|
|
|
|
@route('/grocery/groups')
|
|
@route('/grocery/groups')
|
|
def groups():
|
|
def groups():
|
|
filters = get_filter(request.query, allow=('group', 'category', 'product'))
|
|
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
|
|
|
|
+ ])
|
|
try:
|
|
try:
|
|
with conn.cursor() as cur:
|
|
with conn.cursor() as cur:
|
|
inner = get_product_rollup_statement(
|
|
inner = get_product_rollup_statement(
|
|
@@ -327,11 +323,14 @@ FROM (
|
|
finally:
|
|
finally:
|
|
conn.commit()
|
|
conn.commit()
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
- return template("query-to-xml", title="Groups", foot=True, xml=xml)
|
|
|
|
|
|
+ return template("query-to-xml", title="Groups", xml=xml, form=form)
|
|
|
|
|
|
@route('/grocery/categories')
|
|
@route('/grocery/categories')
|
|
def categories():
|
|
def categories():
|
|
filters = get_filter(request.query, allow=('group', 'category', 'product'))
|
|
filters = get_filter(request.query, allow=('group', 'category', 'product'))
|
|
|
|
+ form = template('form-nav', action='categories', method='get', params=[
|
|
|
|
+ {'name': k, 'value': request.params[k]} for k in request.params if k in PARAMS
|
|
|
|
+ ])
|
|
try:
|
|
try:
|
|
with conn.cursor() as cur:
|
|
with conn.cursor() as cur:
|
|
inner = get_product_rollup_statement(
|
|
inner = get_product_rollup_statement(
|
|
@@ -350,11 +349,14 @@ FROM (
|
|
finally:
|
|
finally:
|
|
conn.commit()
|
|
conn.commit()
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
- return template("query-to-xml", title="Categories", foot=True, xml=xml)
|
|
|
|
|
|
+ return template("query-to-xml", title="Categories", xml=xml, form=form)
|
|
|
|
|
|
@route('/grocery/products')
|
|
@route('/grocery/products')
|
|
def products():
|
|
def products():
|
|
filters = get_filter(request.query, allow=('group', 'category', 'product'))
|
|
filters = get_filter(request.query, allow=('group', 'category', 'product'))
|
|
|
|
+ form = template('form-nav', action='products', method='get', params=[
|
|
|
|
+ {'name': k, 'value': request.params[k]} for k in request.params if k in PARAMS
|
|
|
|
+ ])
|
|
try:
|
|
try:
|
|
with conn.cursor() as cur:
|
|
with conn.cursor() as cur:
|
|
inner = get_product_rollup_statement(
|
|
inner = get_product_rollup_statement(
|
|
@@ -374,19 +376,27 @@ FROM (
|
|
finally:
|
|
finally:
|
|
conn.commit()
|
|
conn.commit()
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
- return template("query-to-xml", title="Products", foot=True, xml=xml)
|
|
|
|
|
|
+ return template("query-to-xml", title="Products", xml=xml, form=form)
|
|
|
|
|
|
@route('/grocery/tags')
|
|
@route('/grocery/tags')
|
|
def tags():
|
|
def tags():
|
|
|
|
+ form = template('form-nav', action='tags', method='get', params=[
|
|
|
|
+ {'name': k, 'value': request.params[k]} for k in request.params if k in PARAMS
|
|
|
|
+ ])
|
|
try:
|
|
try:
|
|
with conn.cursor() as cur:
|
|
with conn.cursor() as cur:
|
|
inner = SQL('\n').join([SQL("""
|
|
inner = SQL('\n').join([SQL("""
|
|
-SELECT count(DISTINCT txn.id) AS "Uses", tg.name AS "Name"
|
|
|
|
|
|
+SELECT * FROM (SELECT count(DISTINCT txn.id) AS "Uses", tg.name AS "Name"
|
|
FROM tags tg
|
|
FROM tags tg
|
|
JOIN tags_map tm ON tg.id = tm.tag_id
|
|
JOIN tags_map tm ON tg.id = tm.tag_id
|
|
JOIN transactions txn ON txn.id = tm.transaction_id
|
|
JOIN transactions txn ON txn.id = tm.transaction_id
|
|
GROUP BY tg.name
|
|
GROUP BY tg.name
|
|
-ORDER BY 1 DESC, 2
|
|
|
|
|
|
+ORDER BY 1 DESC, 2) q
|
|
|
|
+UNION ALL
|
|
|
|
+SELECT count(DISTINCT txn.id) AS "Uses", count(DISTINCT tg.name)||'' AS "Name"
|
|
|
|
+FROM tags tg
|
|
|
|
+JOIN tags_map tm ON tg.id = tm.tag_id
|
|
|
|
+JOIN transactions txn ON txn.id = tm.transaction_id
|
|
""")]).as_string(cur)
|
|
""")]).as_string(cur)
|
|
xml = cur.execute(SQL("""
|
|
xml = cur.execute(SQL("""
|
|
SELECT query_to_xml_and_xmlschema({inner}, false, false, ''::text)
|
|
SELECT query_to_xml_and_xmlschema({inner}, false, false, ''::text)
|
|
@@ -394,6 +404,6 @@ SELECT query_to_xml_and_xmlschema({inner}, false, false, ''::text)
|
|
finally:
|
|
finally:
|
|
conn.commit()
|
|
conn.commit()
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
- return template("query-to-xml", title="Tags", foot="false", xml=xml)
|
|
|
|
|
|
+ return template("query-to-xml", title="Tags", xml=xml, form=form)
|
|
|
|
|
|
run(host='0.0.0.0', port=6772, server='gunicorn')
|
|
run(host='0.0.0.0', port=6772, server='gunicorn')
|