Skip to content

Commit

Permalink
Add a table to show number of km and submissions
Browse files Browse the repository at this point in the history
The table contains the number of km and submissions per day and in
total.
  • Loading branch information
Linkid committed May 20, 2019
1 parent e90b83a commit a82a2a9
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 19 deletions.
33 changes: 30 additions & 3 deletions flaskr/borne.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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')
Expand Down
26 changes: 21 additions & 5 deletions flaskr/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -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 ""

Expand Down Expand Up @@ -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 ""
Expand Down
5 changes: 5 additions & 0 deletions flaskr/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions flaskr/templates/borne/ask.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,28 @@ <h1>Cyclo-borne</h1>

{% block content %}
{{ render_form(form) }}

<br />
<table class="table table-sm table-bordered table-smaller">
<thead class="thead-light text-center">
<tr>
<th scope="col"></th>
<th scope="col">{{ _('Today') }}</th>
<th scope="col">{{ _('Total') }}</th>
</tr>
</thead>

<tbody>
<tr>
<th scope="col" class="table-light">{{ _('Submissions') }}</th>
<td class="text-right">{{ result['nb_id_today'] }}</td>
<td class="text-right">{{ result['nb_id_total'] }}</td>
<tr>
</tr>
<th scope="col" class="thead-light">{{ _('Kilometers') }}</th>
<td class="text-right">{{ result['nb_km_today'] }}</td>
<td class="text-right">{{ result['nb_km_total'] }}</td>
</tr>
</tbody>
</table>
{% endblock %}
Binary file modified flaskr/translations/fr/LC_MESSAGES/messages.mo
Binary file not shown.
34 changes: 23 additions & 11 deletions flaskr/translations/fr/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\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: 2019-05-05 19:29+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: fr\n"
Expand All @@ -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"

Expand Down Expand Up @@ -58,6 +58,22 @@ msgstr "<strong>Type de vélo</strong>"
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"
Expand All @@ -71,9 +87,5 @@ msgid "Distance (km)"
msgstr "Distance (km)"

#: flaskr/templates/borne/show.html:20
msgid "<strong>Type of bicycle</strong>"
msgstr "<strong>Type de vélo</strong>"

#~ msgid "Time (HH:MM AM)"
#~ msgstr "Temps (HH:MM AM)"

msgid "Type of bicycle"
msgstr "Type de vélo"

0 comments on commit a82a2a9

Please sign in to comment.