home · contact · privacy
Improve calorie counter formatting.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 10 Oct 2023 20:23:01 +0000 (22:23 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 10 Oct 2023 20:23:01 +0000 (22:23 +0200)
calories.py

index 5f710878460e2cd4a11599eb9850f89f60e7d117..048aaccea4fe5bd91d4789fb880c338d33a89478 100644 (file)
@@ -10,12 +10,10 @@ def build_page(eatable_rows, consumption_rows, eatables_selection, day_rows):
     return """<html>
 <meta charset="UTF-8">
 <style>
-table {
-  margin-bottom: 2em;
-}
-td, th {
-  text-align: right;
-}
+table { margin-bottom: 2em; }
+th, td { text-align: left; }
+td.number { text-align: right; }
+input[type="number"] { text-align: right; }
 </style>""" + f"""
 <body>
 <form action="/" method="POST">
@@ -29,7 +27,7 @@ td, th {
 <tr>
 <input type="hidden" name="keep_visible" value="0">
 <td><select name="eatable_key">{eatables_selection}</select></td>
-<td><input class="unit_count" name="unit_count" type="number" step="0.1" min="0" value="0" /></td>
+<td class="number"><input class="unit_count" name="unit_count" type="number" step="0.1" min="0" value="0" /></td>
 <td></td>
 </tr>
 </table>
@@ -45,9 +43,9 @@ td, th {
 </tr>
 <tr>
 <td><input name="title" type="text" value="" /></td>
-<td><input name="cals" type="number" min="0" step="0.1" value="0" /></td>
-<td><input name="sugar_g" type="number" min="0" step="0.1" value="0" /></td>
-<td><input name="standard_g" type="number" min="1" step="0.1" value="1" /></td>
+<td class="number"><input name="cals" type="number" min="0" step="0.1" value="0" /></td>
+<td class="number"><input name="sugar_g" type="number" min="0" step="0.1" value="0" /></td>
+<td class="number"><input name="standard_g" type="number" min="1" step="0.1" value="1" /></td>
 <td><input name="comments" type="text" value="" /></td>
 </tr>
 </table>
@@ -280,9 +278,9 @@ class MyServer(BaseHTTPRequestHandler):
             eatables += "<tr>"\
                     "<input name=\"eatable_uuid\" type=\"hidden\" value=\"%s\" />"\
                     "<td><input name=\"title\" value=\"%s\" /></td>"\
-                    "<td><input name=\"cals\" type=\"number\" step=\"0.1\" min=\"0\" value=\"%.1f\" /></td>"\
-                    "<td><input name=\"sugar_g\" type=\"number\" step=\"0.1\" min=\"0\" value=\"%.1f\" /></td>"\
-                    "<td><input name=\"standard_g\" type=\"number\" step=\"0.1\" min=\"1\" value=\"%1.f\" /></td>"\
+                    "<td class\"number\"><input name=\"cals\" type=\"number\" step=\"0.1\" min=\"0\" value=\"%.1f\" /></td>"\
+                    "<td class\"number\"><input name=\"sugar_g\" type=\"number\" step=\"0.1\" min=\"0\" value=\"%.1f\" /></td>"\
+                    "<td class\"number\"><input name=\"standard_g\" type=\"number\" step=\"0.1\" min=\"1\" value=\"%1.f\" /></td>"\
                     "<td><input name=\"comments\" value=\"%s\" /></td>"\
                     "<td><input name=\"delete\" type=\"checkbox\" value=\"%s\" /></td>"\
                     "</tr>" % (k, v.title, v.cals, v.sugar_g, v.standard_g, v.comments, k)
@@ -293,26 +291,26 @@ class MyServer(BaseHTTPRequestHandler):
             consumptions += "<tr />"\
                     "<input type=\"hidden\" name=\"keep_visible\" value=\"1\"><input name=\"eatable_key\" type=\"hidden\" value=\"%s\">"\
                     "<td>%s</td>"\
-                    "<td><input class=\"unit_count\" name=\"unit_count\" type=\"number\" min=\"0\" step=\"0.1\" value=\"%.1f\" /></td>"\
+                    "<td class\"number\"><input class=\"unit_count number\" name=\"unit_count\" type=\"number\" min=\"0\" step=\"0.1\" value=\"%.1f\" /></td>"\
                     "<td></td>"\
-                    "<td>%.1f</td>"\
-                    "<td>%.1f</td>"\
+                    "<td class=\"number\">%.1f</td>"\
+                    "<td class=\"number\">%.1f</td>"\
                     "</tr>" % (c.eatable_key, db.eatables[c.eatable_key].title, c.unit_count, r["cals"], r["sugar"])
         day_rows = ""
         for date in sorted(db.days.keys()):
             day = db.days[date]
             day_rows = "<tr>"\
                     "<td><input name=\"day_date\" type=\"hidden\" value=\"%s\" />%s</td>"\
-                    "<td><input name=\"day_cals\" type=\"hidden\" step=\"0.1\" min=\"0\" value=\"%.1f\" />%.1f</td>"\
-                    "<td><input name=\"day_sugar\" type=\"hidden\" step=\"0.1\" min=\"0\" value=\"%.1f\" />%.1f</td>"\
+                    "<td class=\"number\"><input name=\"day_cals\" type=\"hidden\" step=\"0.1\" min=\"0\" value=\"%.1f\" />%.1f</td>"\
+                    "<td class=\"number\"><input name=\"day_sugar\" type=\"hidden\" step=\"0.1\" min=\"0\" value=\"%.1f\" />%.1f</td>"\
                     "</tr>" % (date, date[:10], day.calories, day.calories, day.sugar_g, day.sugar_g) + day_rows
         day_rows = "<tr>"\
                 "<th>today:</th><th></th><th></th><th>archive?</th>"\
                 "</tr>"\
                 "<tr>"\
                 "<td><input name=\"new_date\" size=8 value=\"%s\" /></td>"\
-                "<td><input name=\"new_day_cals\" type=\"hidden\" value=\"%.1f\" readonly />%.1f</td>"\
-                "<td><input name=\"new_day_sugar\" type=\"hidden\" value=\"%.1f\" readonly />%.1f</td>"\
+                "<td class=\"number\"><input name=\"new_day_cals\" type=\"hidden\" value=\"%.1f\" readonly />%.1f</td>"\
+                "<td class=\"number\"><input name=\"new_day_sugar\" type=\"hidden\" value=\"%.1f\" readonly />%.1f</td>"\
                 "<td><input name=\"archive_day\" type=\"checkbox\" /></td>"\
                 "</tr>" % (db.today_date, db.today.calories, db.today.calories, db.today.sugar_g, db.today.sugar_g) + day_rows
         page = build_page(eatables, consumptions, db.eatables_selection(), day_rows)