|
@@ -62,6 +62,16 @@ def normalize(*args, **kwargs):
|
|
|
|
|
|
return _normalize_decorator(*args)
|
|
return _normalize_decorator(*args)
|
|
|
|
|
|
|
|
+def cursor(func):
|
|
|
|
+ def wrap(*args, **kwargs):
|
|
|
|
+ try:
|
|
|
|
+ with conn.cursor() as cur:
|
|
|
|
+ return func(cur, *args, **kwargs)
|
|
|
|
+ finally:
|
|
|
|
+ conn.commit()
|
|
|
|
+ return wrap
|
|
|
|
+
|
|
|
|
+
|
|
@route('/grocery/static/<filename:path>')
|
|
@route('/grocery/static/<filename:path>')
|
|
def send_static(filename):
|
|
def send_static(filename):
|
|
return static_file(filename, root='app/rest/static')
|
|
return static_file(filename, root='app/rest/static')
|
|
@@ -88,47 +98,31 @@ def trend():
|
|
|
|
|
|
@route('/grocery/groups')
|
|
@route('/grocery/groups')
|
|
@normalize
|
|
@normalize
|
|
-def groups():
|
|
|
|
- try:
|
|
|
|
- with conn.cursor() as cur:
|
|
|
|
- page = get_groups(cur, request.query)
|
|
|
|
- finally:
|
|
|
|
- conn.commit()
|
|
|
|
|
|
+@cursor
|
|
|
|
+def groups(cur):
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
- return page
|
|
|
|
|
|
+ return get_groups(cur, request.query)
|
|
|
|
|
|
|
|
|
|
@route('/grocery/categories')
|
|
@route('/grocery/categories')
|
|
@normalize
|
|
@normalize
|
|
-def categories():
|
|
|
|
- try:
|
|
|
|
- with conn.cursor() as cur:
|
|
|
|
- page = get_categories(cur, request.query)
|
|
|
|
- finally:
|
|
|
|
- conn.commit()
|
|
|
|
|
|
+@cursor
|
|
|
|
+def categories(cur):
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
- return page
|
|
|
|
|
|
+ return get_categories(cur, request.query)
|
|
|
|
|
|
@route('/grocery/products')
|
|
@route('/grocery/products')
|
|
@normalize
|
|
@normalize
|
|
-def products():
|
|
|
|
- try:
|
|
|
|
- with conn.cursor() as cur:
|
|
|
|
- page = get_products(cur, request.query)
|
|
|
|
- finally:
|
|
|
|
- conn.commit()
|
|
|
|
|
|
+@cursor
|
|
|
|
+def products(cur):
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
- return page
|
|
|
|
|
|
+ return get_products(cur, request.query)
|
|
|
|
|
|
|
|
|
|
@route('/grocery/tags')
|
|
@route('/grocery/tags')
|
|
@normalize
|
|
@normalize
|
|
-def tags():
|
|
|
|
- try:
|
|
|
|
- with conn.cursor() as cur:
|
|
|
|
- page = get_tags(cur, request.query)
|
|
|
|
- finally:
|
|
|
|
- conn.commit()
|
|
|
|
|
|
+@cursor
|
|
|
|
+def tags(cur):
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
response.content_type = 'application/xhtml+xml; charset=utf-8'
|
|
- return page
|
|
|
|
|
|
+ return get_tags(cur, request.query)
|
|
|
|
|