Commit 8ae021a22a1c0a8cd310fc5365876ab4259206ac
1 parent
2bdcd05b
Exists in
master
Merge shelved changes.
Add a name to the run. Add a spinner to the estimation plot. Close the geocoder when we're done with it. Provide a way to invalidate the geocoder's cache.
Showing
6 changed files
with
55 additions
and
9 deletions
Show diff stats
content.yml
@@ -737,6 +737,10 @@ estimate: | @@ -737,6 +737,10 @@ estimate: | ||
737 | email: | 737 | email: |
738 | label: Email Address | 738 | label: Email Address |
739 | description: Make sure you provide a valid address or you won't receive the results! | 739 | description: Make sure you provide a valid address or you won't receive the results! |
740 | + run_name: | ||
741 | + label: Run Name | ||
742 | + description: Usually the name of the event. Results will look better if you fill this. | ||
743 | + placeholder: "Global Peace Summit 2020 – Estimation N°07" | ||
740 | first_name: | 744 | first_name: |
741 | label: First Name | 745 | label: First Name |
742 | description: Also known as given name, eg. `Didier`. | 746 | description: Also known as given name, eg. `Didier`. |
flaskr/controllers/main_controller.py
@@ -8,6 +8,8 @@ from flask import Blueprint, render_template, flash, request, redirect, \ | @@ -8,6 +8,8 @@ from flask import Blueprint, render_template, flash, request, redirect, \ | ||
8 | url_for, abort, send_from_directory, Response | 8 | url_for, abort, send_from_directory, Response |
9 | from os.path import join | 9 | from os.path import join |
10 | 10 | ||
11 | +from os import unlink | ||
12 | + | ||
11 | from flaskr.extensions import cache, basic_auth | 13 | from flaskr.extensions import cache, basic_auth |
12 | from flaskr.forms import LoginForm, EstimateForm | 14 | from flaskr.forms import LoginForm, EstimateForm |
13 | from flaskr.models import db, User, Estimation, StatusEnum, ScenarioEnum | 15 | from flaskr.models import db, User, Estimation, StatusEnum, ScenarioEnum |
@@ -162,10 +164,9 @@ def estimate(): | @@ -162,10 +164,9 @@ def estimate(): | ||
162 | 164 | ||
163 | if form.validate_on_submit(): | 165 | if form.validate_on_submit(): |
164 | 166 | ||
165 | - id = generate_unique_id() | ||
166 | - | ||
167 | estimation = Estimation() | 167 | estimation = Estimation() |
168 | # estimation.email = form.email.data | 168 | # estimation.email = form.email.data |
169 | + estimation.run_name = form.run_name.data | ||
169 | estimation.first_name = form.first_name.data | 170 | estimation.first_name = form.first_name.data |
170 | estimation.last_name = form.last_name.data | 171 | estimation.last_name = form.last_name.data |
171 | estimation.institution = form.institution.data | 172 | estimation.institution = form.institution.data |
@@ -223,7 +224,17 @@ def invalidate(): | @@ -223,7 +224,17 @@ def invalidate(): | ||
223 | estimation.errors = "Invalidated. Try again." | 224 | estimation.errors = "Invalidated. Try again." |
224 | db.session.commit() | 225 | db.session.commit() |
225 | 226 | ||
226 | - return "" | 227 | + return "Estimations invalidated: %d" % len(stuck_estimations) |
228 | + | ||
229 | + | ||
230 | +@main.route("/invalidate-geocache") | ||
231 | +@main.route("/invalidate-geocache.html") | ||
232 | +def invalidate_geocache(): | ||
233 | + geocache = 'geocache.db' | ||
234 | + | ||
235 | + unlink(geocache) | ||
236 | + | ||
237 | + return "Geocache invalidated." | ||
227 | 238 | ||
228 | 239 | ||
229 | @main.route("/compute") | 240 | @main.route("/compute") |
@@ -362,6 +373,8 @@ def compute(): # process the queue of estimation requests | @@ -362,6 +373,8 @@ def compute(): # process the queue of estimation requests | ||
362 | destination.latitude, destination.longitude, | 373 | destination.latitude, destination.longitude, |
363 | ) | 374 | ) |
364 | 375 | ||
376 | + geocoder.close() | ||
377 | + | ||
365 | # GTFO IF NO ORIGINS OR NO DESTINATIONS ################################### | 378 | # GTFO IF NO ORIGINS OR NO DESTINATIONS ################################### |
366 | 379 | ||
367 | if 0 == len(origins): | 380 | if 0 == len(origins): |
flaskr/forms.py
@@ -30,12 +30,23 @@ class EstimateForm(FlaskForm): | @@ -30,12 +30,23 @@ class EstimateForm(FlaskForm): | ||
30 | # ], | 30 | # ], |
31 | # ) | 31 | # ) |
32 | 32 | ||
33 | + run_name = StringField( | ||
34 | + label=form_content['run_name']['label'], | ||
35 | + description=form_content['run_name']['description'], | ||
36 | + validators=[ | ||
37 | + validators.Optional(), | ||
38 | + validators.Length(max=128), | ||
39 | + ], | ||
40 | + render_kw={ | ||
41 | + "placeholder": form_content['run_name']['placeholder'] | ||
42 | + }, | ||
43 | + ) | ||
33 | first_name = StringField( | 44 | first_name = StringField( |
34 | label=form_content['first_name']['label'], | 45 | label=form_content['first_name']['label'], |
35 | description=form_content['first_name']['description'], | 46 | description=form_content['first_name']['description'], |
36 | validators=[ | 47 | validators=[ |
37 | validators.Optional(), | 48 | validators.Optional(), |
38 | - validators.Length(max=1024), | 49 | + validators.Length(max=128), |
39 | ], | 50 | ], |
40 | render_kw={ | 51 | render_kw={ |
41 | "placeholder": form_content['first_name']['placeholder'] | 52 | "placeholder": form_content['first_name']['placeholder'] |
@@ -46,7 +57,7 @@ class EstimateForm(FlaskForm): | @@ -46,7 +57,7 @@ class EstimateForm(FlaskForm): | ||
46 | description=form_content['last_name']['description'], | 57 | description=form_content['last_name']['description'], |
47 | validators=[ | 58 | validators=[ |
48 | validators.Optional(), | 59 | validators.Optional(), |
49 | - validators.Length(max=1024), | 60 | + validators.Length(max=128), |
50 | ], | 61 | ], |
51 | render_kw={ | 62 | render_kw={ |
52 | "placeholder": form_content['last_name']['placeholder'] | 63 | "placeholder": form_content['last_name']['placeholder'] |
@@ -57,7 +68,7 @@ class EstimateForm(FlaskForm): | @@ -57,7 +68,7 @@ class EstimateForm(FlaskForm): | ||
57 | description=form_content['institution']['description'], | 68 | description=form_content['institution']['description'], |
58 | validators=[ | 69 | validators=[ |
59 | validators.Optional(), | 70 | validators.Optional(), |
60 | - validators.Length(max=1024), | 71 | + validators.Length(max=128), |
61 | ], | 72 | ], |
62 | ) | 73 | ) |
63 | use_train_below_km = SelectField( | 74 | use_train_below_km = SelectField( |
@@ -72,7 +83,7 @@ class EstimateForm(FlaskForm): | @@ -72,7 +83,7 @@ class EstimateForm(FlaskForm): | ||
72 | description=form_content['comment']['description'], | 83 | description=form_content['comment']['description'], |
73 | validators=[ | 84 | validators=[ |
74 | validators.Optional(), | 85 | validators.Optional(), |
75 | - validators.Length(max=2048), | 86 | + validators.Length(max=4096), |
76 | ], | 87 | ], |
77 | ) | 88 | ) |
78 | origin_addresses = TextAreaField( | 89 | origin_addresses = TextAreaField( |
flaskr/models.py
@@ -43,6 +43,7 @@ class Estimation(db.Model): | @@ -43,6 +43,7 @@ class Estimation(db.Model): | ||
43 | last_name = db.Column(db.Unicode(1024)) # Goutenoir | 43 | last_name = db.Column(db.Unicode(1024)) # Goutenoir |
44 | institution = db.Column(db.Unicode(1024)) # IRAP | 44 | institution = db.Column(db.Unicode(1024)) # IRAP |
45 | status = db.Column(db.Enum(StatusEnum), default=StatusEnum.pending) | 45 | status = db.Column(db.Enum(StatusEnum), default=StatusEnum.pending) |
46 | + run_name = db.Column(db.Unicode(1024)) # JPGU 2020 | ||
46 | 47 | ||
47 | # City, Country | 48 | # City, Country |
48 | # One address per line | 49 | # One address per line |
@@ -67,6 +68,11 @@ class Estimation(db.Model): | @@ -67,6 +68,11 @@ class Estimation(db.Model): | ||
67 | def has_failed(self): | 68 | def has_failed(self): |
68 | return self.status == StatusEnum.failure | 69 | return self.status == StatusEnum.failure |
69 | 70 | ||
71 | + def get_display_name(self): | ||
72 | + if self.run_name: | ||
73 | + return self.run_name | ||
74 | + return self.public_id | ||
75 | + | ||
70 | _output_dict = None | 76 | _output_dict = None |
71 | 77 | ||
72 | def get_output_dict(self): | 78 | def get_output_dict(self): |
@@ -102,6 +108,7 @@ class EstimationView(ModelView): | @@ -102,6 +108,7 @@ class EstimationView(ModelView): | ||
102 | # Show only name and email columns in list view | 108 | # Show only name and email columns in list view |
103 | column_list = ( | 109 | column_list = ( |
104 | 'public_id', | 110 | 'public_id', |
111 | + 'run_name', | ||
105 | 'status', | 112 | 'status', |
106 | 'first_name', | 113 | 'first_name', |
107 | 'last_name', | 114 | 'last_name', |
flaskr/templates/estimate.html
@@ -169,6 +169,13 @@ | @@ -169,6 +169,13 @@ | ||
169 | {{ render_field(form.comment) }} | 169 | {{ render_field(form.comment) }} |
170 | </div> | 170 | </div> |
171 | 171 | ||
172 | + <hr> | ||
173 | + | ||
174 | + <div class="form-group"> | ||
175 | + {{ render_field(form.run_name) }} | ||
176 | + <small class="form-text text-muted">{{ content.estimate.help.run_name | safe }}</small> | ||
177 | + </div> | ||
178 | + | ||
172 | <button type="submit" class="btn btn-primary"> | 179 | <button type="submit" class="btn btn-primary"> |
173 | Submit a Request | 180 | Submit a Request |
174 | </button> | 181 | </button> |
flaskr/templates/estimation.html
@@ -54,7 +54,7 @@ | @@ -54,7 +54,7 @@ | ||
54 | 54 | ||
55 | {% block body %} | 55 | {% block body %} |
56 | <h2> | 56 | <h2> |
57 | - {{ estimation.public_id }} ({{ estimation.status.name }}) | 57 | + {{ estimation.get_display_name() }} ({{ estimation.status.name }}) |
58 | </h2> | 58 | </h2> |
59 | 59 | ||
60 | {% if estimation.errors %} | 60 | {% if estimation.errors %} |
@@ -83,7 +83,9 @@ | @@ -83,7 +83,9 @@ | ||
83 | {# <h4>Total CO<sub>2</sub> footprint (in kilograms-equivalent) of each city</h4>#} | 83 | {# <h4>Total CO<sub>2</sub> footprint (in kilograms-equivalent) of each city</h4>#} |
84 | {# <div id="cities_footprints_d3viz" class="plot-container"></div>#} | 84 | {# <div id="cities_footprints_d3viz" class="plot-container"></div>#} |
85 | <hr> | 85 | <hr> |
86 | - <div id="cities_footprints_d3viz_lollipop" class="plot-container"></div> | 86 | + <div id="cities_footprints_d3viz_lollipop" class="plot-container"> |
87 | + <div id="cities_footprints_spinner" class="lds-ripple text-center"><div></div><div></div><div></div></div> | ||
88 | + </div> | ||
87 | {# <br>#} | 89 | {# <br>#} |
88 | {# <p>A Legend here</p>#} | 90 | {# <p>A Legend here</p>#} |
89 | </div> | 91 | </div> |
@@ -559,6 +561,8 @@ jQuery(document).ready(function($){ | @@ -559,6 +561,8 @@ jQuery(document).ready(function($){ | ||
559 | return false; | 561 | return false; |
560 | }); | 562 | }); |
561 | 563 | ||
564 | + $('#cities_footprints_spinner').hide(); | ||
565 | + | ||
562 | }); | 566 | }); |
563 | 567 | ||
564 | }); | 568 | }); |