From a82a2a9b4d44bfb76d03c6a51d3ead13bc21c675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Magimel?= Date: Mon, 20 May 2019 21:22:37 +0200 Subject: [PATCH] Add a table to show number of km and submissions The table contains the number of km and submissions per day and in total. --- flaskr/borne.py | 33 +++++++++++++++-- flaskr/messages.pot | 26 +++++++++++--- flaskr/static/style.css | 5 +++ flaskr/templates/borne/ask.html | 24 +++++++++++++ .../translations/fr/LC_MESSAGES/messages.mo | Bin 1062 -> 1253 bytes .../translations/fr/LC_MESSAGES/messages.po | 34 ++++++++++++------ 6 files changed, 103 insertions(+), 19 deletions(-) diff --git a/flaskr/borne.py b/flaskr/borne.py index a1abdc5..7b148fd 100644 --- a/flaskr/borne.py +++ b/flaskr/borne.py @@ -20,10 +20,37 @@ @bp.route('/ask', methods=('GET', 'POST')) def ask(): - form = AskForm() + db = get_db() + # result + result = dict() + ## today + sql = """ + SELECT + SUM(cycle_dist) AS nb_km, + COUNT(b.id) AS nb_id + FROM borne b + WHERE DATETIME(cycle_datetime) >= DATETIME('now') + """ + # WHERE DATETIME(cycle_datetime) >= DATETIME('2019-05-14') + result_today = db.execute(sql).fetchone() + result['nb_id_today'] = result_today['nb_id'] + result['nb_km_today'] = result_today['nb_km'] + + ## total + sql = """ + SELECT + SUM(cycle_dist) AS nb_km, + COUNT(b.id) AS nb_id + FROM borne b + """ + result_total = db.execute(sql).fetchone() + result['nb_id_total'] = result_total['nb_id'] + result['nb_km_total'] = result_total['nb_km'] + + # form + form = AskForm() if form.validate_on_submit(): - db = get_db() data = ( form.cycle_time.data, form.cycle_dist.data, @@ -38,7 +65,7 @@ def ask(): flash(_("Thank you!")) return redirect(url_for('borne.ask')) - return render_template('borne/ask.html', form=form) + return render_template('borne/ask.html', form=form, result=result) @bp.route('/show') diff --git a/flaskr/messages.pot b/flaskr/messages.pot index b21395b..bb299f8 100644 --- a/flaskr/messages.pot +++ b/flaskr/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: flaskr 1.0.0\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2019-05-08 19:45+0200\n" +"POT-Creation-Date: 2019-05-18 16:11+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,19 +17,19 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.6.0\n" -#: flaskr/borne.py:38 flaskr/borne.py:77 +#: flaskr/borne.py:64 flaskr/borne.py:103 msgid "Thank you!" msgstr "" -#: flaskr/borne.py:67 +#: flaskr/borne.py:93 msgid "Time is required" msgstr "" -#: flaskr/borne.py:69 +#: flaskr/borne.py:95 msgid "Distance is required" msgstr "" -#: flaskr/borne.py:71 +#: flaskr/borne.py:97 msgid "Type is required" msgstr "" @@ -57,6 +57,22 @@ msgstr "" msgid "Submit" msgstr "" +#: flaskr/templates/borne/ask.html:25 +msgid "Today" +msgstr "" + +#: flaskr/templates/borne/ask.html:26 +msgid "Total" +msgstr "" + +#: flaskr/templates/borne/ask.html:32 +msgid "Submissions" +msgstr "" + +#: flaskr/templates/borne/ask.html:37 +msgid "Kilometers" +msgstr "" + #: flaskr/templates/borne/show.html:17 msgid "Date" msgstr "" diff --git a/flaskr/static/style.css b/flaskr/static/style.css index fa16559..1061926 100644 --- a/flaskr/static/style.css +++ b/flaskr/static/style.css @@ -31,6 +31,11 @@ h1, h2, h3, h4, h5, h6 { margin: auto } +.table-smaller { + margin: auto; + max-width: 600px; +} + form { width: 100%; max-width: 330px; diff --git a/flaskr/templates/borne/ask.html b/flaskr/templates/borne/ask.html index 6e4e50a..789238d 100644 --- a/flaskr/templates/borne/ask.html +++ b/flaskr/templates/borne/ask.html @@ -14,4 +14,28 @@

Cyclo-borne

{% block content %} {{ render_form(form) }} + +
+ + + + + + + + + + + + + + + + + + + + + +
{{ _('Today') }}{{ _('Total') }}
{{ _('Submissions') }}{{ result['nb_id_today'] }}{{ result['nb_id_total'] }}
{{ _('Kilometers') }}{{ result['nb_km_today'] }}{{ result['nb_km_total'] }}
{% endblock %} diff --git a/flaskr/translations/fr/LC_MESSAGES/messages.mo b/flaskr/translations/fr/LC_MESSAGES/messages.mo index 86132de36ff830f5f4978b2332bd4e177583b216..f2f4c90ef850fde7c5512bf0c0b2636eb3902a52 100644 GIT binary patch delta 516 zcmYk&ze~eV5C`x}TWzaIrHTrbl0gs@hYbEe7dv#2Ru_wV+q~K*X=C#ep;N)BLkFe0 z_y>qx1b^V*q}2aF5L^UBcNY;izh^V};N|n~!o9oXH1ZK`yu?Gtgf)UaiG9t%zm?U9 zl8Dz~0$NaqO&Eq97=jmY2;RU^_y7msGaQ8PupfT<`EQ821_c5{!*~&feQ?4z>F1|l z4EcE&glX79@fzg8o{;3hzaYnP+!}=j*3GASVmfQMYzIIwCNQpQYmRyRlBLp%-UwYPC47n zTa>Hs3SBDQ5j9Ub!t5pNl3tL-deIW?d#xNXmULrb*)Xn*z@?V>ySRJiIzmyp>WFQr uaIT1|tJ-hDxy6*XV|$J{UG}8kBr9~6`v~Rs8mV3zQ|No$j%CwUDowvhwp?QX delta 330 zcmaFLxs0R!o)F7a1|Z-AVi_Rr0dbJPA0S%}i2nkyG!V-$GB79rX$v6D4x}T2Gz*YU z1k$`fIt@sR0O=AS%?6}9fixG8o&cml>ShCJ0U*5qLf12F1TvU`0*8Qf4-g*%VvvQw zKtYg$ihwkT-w&iYf%G~c4Kip4kOo<}7f6c(>C;g8$3Pn7u(v>(6-a*t(!xOcH;@(r z()>WpKqi9{$Pk;!evI9dKQL\n" "Language: fr\n" @@ -18,19 +18,19 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.6.0\n" -#: flaskr/borne.py:38 flaskr/borne.py:77 +#: flaskr/borne.py:64 flaskr/borne.py:103 msgid "Thank you!" msgstr "Merci !" -#: flaskr/borne.py:67 +#: flaskr/borne.py:93 msgid "Time is required" msgstr "Le temps est requis" -#: flaskr/borne.py:69 +#: flaskr/borne.py:95 msgid "Distance is required" msgstr "La distance est requise" -#: flaskr/borne.py:71 +#: flaskr/borne.py:97 msgid "Type is required" msgstr "Le type est requis" @@ -58,6 +58,22 @@ msgstr "Type de vélo" msgid "Submit" msgstr "Soumettre" +#: flaskr/templates/borne/ask.html:25 +msgid "Today" +msgstr "Aujourd'hui" + +#: flaskr/templates/borne/ask.html:26 +msgid "Total" +msgstr "Total" + +#: flaskr/templates/borne/ask.html:32 +msgid "Submissions" +msgstr "Enregistrements" + +#: flaskr/templates/borne/ask.html:37 +msgid "Kilometers" +msgstr "Kilomètres" + #: flaskr/templates/borne/show.html:17 msgid "Date" msgstr "Date" @@ -71,9 +87,5 @@ msgid "Distance (km)" msgstr "Distance (km)" #: flaskr/templates/borne/show.html:20 -msgid "Type of bicycle" -msgstr "Type de vélo" - -#~ msgid "Time (HH:MM AM)" -#~ msgstr "Temps (HH:MM AM)" - +msgid "Type of bicycle" +msgstr "Type de vélo"