Parcourir la source

move templates to subdir and fix products/categories/groups endpoints

Daniel Sheffield il y a 1 an
Parent
commit
99c1f1a477

+ 0 - 11
app/rest/filter-set.tpl

@@ -1,11 +0,0 @@
-<div class="pure-g">
-  <%
-    for filter in (product, category, group):
-      include('app/rest/include-exclude', **filter)
-    end
-  %>
-  <%
-    include('app/rest/include-exclude', **tags)
-    include('app/rest/select-one', **units)
-  %>
-</div>

+ 0 - 15
app/rest/include-exclude.tpl

@@ -1,15 +0,0 @@
-<div class="pure-u-1-3 pure-u-lg-1-5">
-<div class="pure-g">
-  <div class="pure-u-1">
-    <div class="l-box">
-      <h3>{{name.title()}}</h3>
-    </div>
-  </div>
-  <% include('app/rest/select', id=f"{name}-include", name=name, options=_include["options"], hint="Include", multiple=True) %>
-  <%
-  if defined("_exclude"):
-    include('app/rest/select', id=f"{name}-exclude", name=name, options=_exclude["options"], hint="Exclude", multiple=True)
-  end
-  %>
-</div>
-</div>

+ 16 - 16
app/rest/pyapi.py

@@ -60,7 +60,7 @@ sns.set_theme(style='darkgrid', palette='pastel')
 
 def get_product_rollup_statement(filters, having=None):
     where = [ get_where_include_exclude(
-        k[0], "name", include, exclude
+        k[0], "name", list(include), list(exclude)
     ) for k, (include, exclude) in filters.items() ]
     return SQL('\n').join([
         SQL("""
@@ -121,12 +121,12 @@ def get_form(action, method, filter_data, data):
         k for k in keys
     ]]
     return template(
-        'app/rest/form',
+        'app/rest/templates/form',
         action=action,
         method=method,
         header=[
             template(
-                'app/rest/filter-heading',
+                'app/rest/templates/filter-heading',
                 fname=k,
                 first=(idx == 0),
             ) for idx, k in enumerate(keys)
@@ -200,7 +200,7 @@ def trend():
     if request.query_string != normalized:
         return redirect(f'{path}?{normalized}')
     
-    loading = template("app/rest/loading", progress=[])
+    loading = template("app/rest/templates/loading", progress=[])
     if request.query_string in CACHE:
         if LOCK.acquire(block=False):
             try:
@@ -239,37 +239,37 @@ def trend_internal(path, query):
                 raise abort(400, f"Unsupported unit {unit}")
 
             progress.append({ "name": "Loading data", "status": ""})
-            yield template("app/rest/loading", progress=progress)
+            yield template("app/rest/templates/loading", progress=progress)
             data = get_data(query_manager, **fields)
 
             progress[-1]["status"] = "done"
-            yield template("app/rest/loading", progress=progress)
+            yield template("app/rest/templates/loading", progress=progress)
 
             if data.empty:
                 raise abort(404, f"No data for {fields}")
             
             progress.append({ "name": "Loading chart", "status": ""})
-            yield template("app/rest/loading", progress=progress)
+            yield template("app/rest/templates/loading", progress=progress)
             pivot = data.pivot_table(index=['ts_raw',], columns=['product',], values=['$/unit'], aggfunc='mean')
             pivot.columns = pivot.columns.droplevel()
             plt.figure(facecolor='black', figsize=[16, 9])
             line(pivot, xlabel='Time', ylabel=f'$ / {unit}')
             
             progress[-1]["status"] = "done"
-            yield template("app/rest/loading", progress=progress)
+            yield template("app/rest/templates/loading", progress=progress)
             
             progress.append({ "name": "Rendering chart", "status": ""})
-            yield template("app/rest/loading", progress=progress)
+            yield template("app/rest/templates/loading", progress=progress)
 
             f = StringIO()
             plt.savefig(f, format='svg')
             form = get_form(path, 'get', get_filter(request.query, allow=PARAMS), data)
             
             progress[-1]["status"] = "done"
-            yield template("app/rest/loading", progress=progress)
+            yield template("app/rest/templates/loading", progress=progress)
             
-            final = template("app/rest/trend", form=form, svg=f.getvalue())
-            resp = lambda: template("app/rest/trend", form=form, svg=f.getvalue())
+            final = template("app/rest/templates/trend", form=form, svg=f.getvalue())
+            resp = lambda: template("app/rest/templates/trend", form=form, svg=f.getvalue())
 
     except HTTPError as e:
         resp = lambda exception=e: exception
@@ -284,7 +284,7 @@ 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("app/rest/query-to-xml-xslt", title=title, foot=foot)
+    return template("app/rest/templates/query-to-xml-xslt", title=title, foot=foot)
 
 @route('/grocery/groups')
 def groups():
@@ -336,7 +336,7 @@ FROM (
         conn.commit()
     response.content_type = 'application/xhtml+xml; charset=utf-8'
     return template(
-        "app/rest/query-to-xml",
+        "app/rest/templates/query-to-xml",
         title="Categories",
         foot=True,
         xml=xml
@@ -365,7 +365,7 @@ FROM (
         conn.commit()
     response.content_type = 'application/xhtml+xml; charset=utf-8'
     return template(
-        "app/rest/query-to-xml",
+        "app/rest/templates/query-to-xml",
         title="Products",
         foot=True,
         xml=xml
@@ -390,7 +390,7 @@ SELECT query_to_xml_and_xmlschema({inner}, false, false, ''::text)
         conn.commit()
     response.content_type = 'application/xhtml+xml; charset=utf-8'
     return template(
-        "app/rest/query-to-xml",
+        "app/rest/templates/query-to-xml",
         title="Tags",
         foot="false",
         xml=xml

+ 0 - 0
app/rest/data-item.tpl → app/rest/templates/data-item.tpl


+ 0 - 0
app/rest/filter-heading.tpl → app/rest/templates/filter-heading.tpl


+ 11 - 0
app/rest/templates/filter-set.tpl

@@ -0,0 +1,11 @@
+<div class="pure-g">
+  <%
+    for filter in (product, category, group):
+      include('app/rest/templates/include-exclude', **filter)
+    end
+  %>
+  <%
+    include('app/rest/templates/include-exclude', **tags)
+    include('app/rest/templates/select-one', **units)
+  %>
+</div>

+ 1 - 1
app/rest/form.tpl → app/rest/templates/form.tpl

@@ -1,6 +1,6 @@
 <form id="filter" style="display: inline-flex"  method="{{ method }}" action="{{ action }}">
     <%
-    include('app/rest/filter-set',
+    include('app/rest/templates/filter-set',
       product=product, category=category, group=group,
       tags=tags, units=units)
     %>

+ 15 - 0
app/rest/templates/include-exclude.tpl

@@ -0,0 +1,15 @@
+<div class="pure-u-1-3 pure-u-lg-1-5">
+<div class="pure-g">
+  <div class="pure-u-1">
+    <div class="l-box">
+      <h3>{{name.title()}}</h3>
+    </div>
+  </div>
+  <% include('app/rest/templates/select', id=f"{name}-include", name=name, options=_include["options"], hint="Include", multiple=True) %>
+  <%
+  if defined("_exclude"):
+    include('app/rest/templates/select', id=f"{name}-exclude", name=name, options=_exclude["options"], hint="Exclude", multiple=True)
+  end
+  %>
+</div>
+</div>

+ 0 - 0
app/rest/label.tpl → app/rest/templates/label.tpl


+ 1 - 1
app/rest/loading.tpl → app/rest/templates/loading.tpl

@@ -18,7 +18,7 @@ body {
       <span class="loader"></span>
       <%
       for indicator in progress:
-          include('app/rest/progress', **indicator)
+          include('app/rest/templates/progress', **indicator)
       end
       %>
     </div>

+ 0 - 0
app/rest/option.tpl → app/rest/templates/option.tpl


+ 0 - 0
app/rest/progress.tpl → app/rest/templates/progress.tpl


+ 0 - 0
app/rest/query-to-xml-xslt.tpl → app/rest/templates/query-to-xml-xslt.tpl


+ 0 - 0
app/rest/query-to-xml.tpl → app/rest/templates/query-to-xml.tpl


+ 1 - 1
app/rest/select-one.tpl → app/rest/templates/select-one.tpl

@@ -5,6 +5,6 @@
       <h3>{{name.title()}}</h3>
     </div>
   </div>
-  <% include('app/rest/select', id=f"{name}-select-one", name=name, options=options) %>
+  <% include('app/rest/templates/select', id=f"{name}-select-one", name=name, options=options) %>
 </div>
 </div>

+ 3 - 3
app/rest/select.tpl → app/rest/templates/select.tpl

@@ -1,7 +1,7 @@
 <div class="pure-u-1">
 <%
   if defined("label"):
-    include('app/rest/label', id=id, label=label)
+    include('app/rest/templates/label', id=id, label=label)
   end
 %>
 <select
@@ -13,10 +13,10 @@
   >
   <%
     if defined("hint"):
-      include('app/rest/option', value=hint, disabled=True)
+      include('app/rest/templates/option', value=hint, disabled=True)
     end
     for opt in options:
-      include('app/rest/option', **opt)
+      include('app/rest/templates/option', **opt)
     end
   %>
 </select>

+ 0 - 0
app/rest/trend.tpl → app/rest/templates/trend.tpl