Commit 8ae021a22a1c0a8cd310fc5365876ab4259206ac

Authored by Antoine Goutenoir
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.
content.yml
... ... @@ -737,6 +737,10 @@ estimate:
737 737 email:
738 738 label: Email Address
739 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 744 first_name:
741 745 label: First Name
742 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 8 url_for, abort, send_from_directory, Response
9 9 from os.path import join
10 10  
  11 +from os import unlink
  12 +
11 13 from flaskr.extensions import cache, basic_auth
12 14 from flaskr.forms import LoginForm, EstimateForm
13 15 from flaskr.models import db, User, Estimation, StatusEnum, ScenarioEnum
... ... @@ -162,10 +164,9 @@ def estimate():
162 164  
163 165 if form.validate_on_submit():
164 166  
165   - id = generate_unique_id()
166   -
167 167 estimation = Estimation()
168 168 # estimation.email = form.email.data
  169 + estimation.run_name = form.run_name.data
169 170 estimation.first_name = form.first_name.data
170 171 estimation.last_name = form.last_name.data
171 172 estimation.institution = form.institution.data
... ... @@ -223,7 +224,17 @@ def invalidate():
223 224 estimation.errors = "Invalidated. Try again."
224 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 240 @main.route("/compute")
... ... @@ -362,6 +373,8 @@ def compute(): # process the queue of estimation requests
362 373 destination.latitude, destination.longitude,
363 374 )
364 375  
  376 + geocoder.close()
  377 +
365 378 # GTFO IF NO ORIGINS OR NO DESTINATIONS ###################################
366 379  
367 380 if 0 == len(origins):
... ...
flaskr/forms.py
... ... @@ -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 44 first_name = StringField(
34 45 label=form_content['first_name']['label'],
35 46 description=form_content['first_name']['description'],
36 47 validators=[
37 48 validators.Optional(),
38   - validators.Length(max=1024),
  49 + validators.Length(max=128),
39 50 ],
40 51 render_kw={
41 52 "placeholder": form_content['first_name']['placeholder']
... ... @@ -46,7 +57,7 @@ class EstimateForm(FlaskForm):
46 57 description=form_content['last_name']['description'],
47 58 validators=[
48 59 validators.Optional(),
49   - validators.Length(max=1024),
  60 + validators.Length(max=128),
50 61 ],
51 62 render_kw={
52 63 "placeholder": form_content['last_name']['placeholder']
... ... @@ -57,7 +68,7 @@ class EstimateForm(FlaskForm):
57 68 description=form_content['institution']['description'],
58 69 validators=[
59 70 validators.Optional(),
60   - validators.Length(max=1024),
  71 + validators.Length(max=128),
61 72 ],
62 73 )
63 74 use_train_below_km = SelectField(
... ... @@ -72,7 +83,7 @@ class EstimateForm(FlaskForm):
72 83 description=form_content['comment']['description'],
73 84 validators=[
74 85 validators.Optional(),
75   - validators.Length(max=2048),
  86 + validators.Length(max=4096),
76 87 ],
77 88 )
78 89 origin_addresses = TextAreaField(
... ...
flaskr/models.py
... ... @@ -43,6 +43,7 @@ class Estimation(db.Model):
43 43 last_name = db.Column(db.Unicode(1024)) # Goutenoir
44 44 institution = db.Column(db.Unicode(1024)) # IRAP
45 45 status = db.Column(db.Enum(StatusEnum), default=StatusEnum.pending)
  46 + run_name = db.Column(db.Unicode(1024)) # JPGU 2020
46 47  
47 48 # City, Country
48 49 # One address per line
... ... @@ -67,6 +68,11 @@ class Estimation(db.Model):
67 68 def has_failed(self):
68 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 76 _output_dict = None
71 77  
72 78 def get_output_dict(self):
... ... @@ -102,6 +108,7 @@ class EstimationView(ModelView):
102 108 # Show only name and email columns in list view
103 109 column_list = (
104 110 'public_id',
  111 + 'run_name',
105 112 'status',
106 113 'first_name',
107 114 'last_name',
... ...
flaskr/templates/estimate.html
... ... @@ -169,6 +169,13 @@
169 169 {{ render_field(form.comment) }}
170 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 179 <button type="submit" class="btn btn-primary">
173 180 Submit a Request
174 181 </button>
... ...
flaskr/templates/estimation.html
... ... @@ -54,7 +54,7 @@
54 54  
55 55 {% block body %}
56 56 <h2>
57   - {{ estimation.public_id }} ({{ estimation.status.name }})
  57 + {{ estimation.get_display_name() }} ({{ estimation.status.name }})
58 58 </h2>
59 59  
60 60 {% if estimation.errors %}
... ... @@ -83,7 +83,9 @@
83 83 {# <h4>Total CO<sub>2</sub> footprint (in kilograms-equivalent) of each city</h4>#}
84 84 {# <div id="cities_footprints_d3viz" class="plot-container"></div>#}
85 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 89 {# <br>#}
88 90 {# <p>A Legend here</p>#}
89 91 </div>
... ... @@ -559,6 +561,8 @@ jQuery(document).ready(function($){
559 561 return false;
560 562 });
561 563  
  564 + $('#cities_footprints_spinner').hide();
  565 +
562 566 });
563 567  
564 568 });
... ...