From 8ae021a22a1c0a8cd310fc5365876ab4259206ac Mon Sep 17 00:00:00 2001 From: Antoine Goutenoir Date: Thu, 13 Feb 2020 07:10:47 +0100 Subject: [PATCH] Merge shelved changes. --- content.yml | 4 ++++ flaskr/controllers/main_controller.py | 19 ++++++++++++++++--- flaskr/forms.py | 19 +++++++++++++++---- flaskr/models.py | 7 +++++++ flaskr/templates/estimate.html | 7 +++++++ flaskr/templates/estimation.html | 8 ++++++-- 6 files changed, 55 insertions(+), 9 deletions(-) diff --git a/content.yml b/content.yml index 5e667ae..615cf06 100644 --- a/content.yml +++ b/content.yml @@ -737,6 +737,10 @@ estimate: email: label: Email Address description: Make sure you provide a valid address or you won't receive the results! + run_name: + label: Run Name + description: Usually the name of the event. Results will look better if you fill this. + placeholder: "Global Peace Summit 2020 – Estimation N°07" first_name: label: First Name description: Also known as given name, eg. `Didier`. diff --git a/flaskr/controllers/main_controller.py b/flaskr/controllers/main_controller.py index 8158790..55ad34f 100644 --- a/flaskr/controllers/main_controller.py +++ b/flaskr/controllers/main_controller.py @@ -8,6 +8,8 @@ from flask import Blueprint, render_template, flash, request, redirect, \ url_for, abort, send_from_directory, Response from os.path import join +from os import unlink + from flaskr.extensions import cache, basic_auth from flaskr.forms import LoginForm, EstimateForm from flaskr.models import db, User, Estimation, StatusEnum, ScenarioEnum @@ -162,10 +164,9 @@ def estimate(): if form.validate_on_submit(): - id = generate_unique_id() - estimation = Estimation() # estimation.email = form.email.data + estimation.run_name = form.run_name.data estimation.first_name = form.first_name.data estimation.last_name = form.last_name.data estimation.institution = form.institution.data @@ -223,7 +224,17 @@ def invalidate(): estimation.errors = "Invalidated. Try again." db.session.commit() - return "" + return "Estimations invalidated: %d" % len(stuck_estimations) + + +@main.route("/invalidate-geocache") +@main.route("/invalidate-geocache.html") +def invalidate_geocache(): + geocache = 'geocache.db' + + unlink(geocache) + + return "Geocache invalidated." @main.route("/compute") @@ -362,6 +373,8 @@ def compute(): # process the queue of estimation requests destination.latitude, destination.longitude, ) + geocoder.close() + # GTFO IF NO ORIGINS OR NO DESTINATIONS ################################### if 0 == len(origins): diff --git a/flaskr/forms.py b/flaskr/forms.py index d621996..da98a01 100644 --- a/flaskr/forms.py +++ b/flaskr/forms.py @@ -30,12 +30,23 @@ class EstimateForm(FlaskForm): # ], # ) + run_name = StringField( + label=form_content['run_name']['label'], + description=form_content['run_name']['description'], + validators=[ + validators.Optional(), + validators.Length(max=128), + ], + render_kw={ + "placeholder": form_content['run_name']['placeholder'] + }, + ) first_name = StringField( label=form_content['first_name']['label'], description=form_content['first_name']['description'], validators=[ validators.Optional(), - validators.Length(max=1024), + validators.Length(max=128), ], render_kw={ "placeholder": form_content['first_name']['placeholder'] @@ -46,7 +57,7 @@ class EstimateForm(FlaskForm): description=form_content['last_name']['description'], validators=[ validators.Optional(), - validators.Length(max=1024), + validators.Length(max=128), ], render_kw={ "placeholder": form_content['last_name']['placeholder'] @@ -57,7 +68,7 @@ class EstimateForm(FlaskForm): description=form_content['institution']['description'], validators=[ validators.Optional(), - validators.Length(max=1024), + validators.Length(max=128), ], ) use_train_below_km = SelectField( @@ -72,7 +83,7 @@ class EstimateForm(FlaskForm): description=form_content['comment']['description'], validators=[ validators.Optional(), - validators.Length(max=2048), + validators.Length(max=4096), ], ) origin_addresses = TextAreaField( diff --git a/flaskr/models.py b/flaskr/models.py index 03e2387..d55b8f4 100755 --- a/flaskr/models.py +++ b/flaskr/models.py @@ -43,6 +43,7 @@ class Estimation(db.Model): last_name = db.Column(db.Unicode(1024)) # Goutenoir institution = db.Column(db.Unicode(1024)) # IRAP status = db.Column(db.Enum(StatusEnum), default=StatusEnum.pending) + run_name = db.Column(db.Unicode(1024)) # JPGU 2020 # City, Country # One address per line @@ -67,6 +68,11 @@ class Estimation(db.Model): def has_failed(self): return self.status == StatusEnum.failure + def get_display_name(self): + if self.run_name: + return self.run_name + return self.public_id + _output_dict = None def get_output_dict(self): @@ -102,6 +108,7 @@ class EstimationView(ModelView): # Show only name and email columns in list view column_list = ( 'public_id', + 'run_name', 'status', 'first_name', 'last_name', diff --git a/flaskr/templates/estimate.html b/flaskr/templates/estimate.html index 1269ccc..bd47b3f 100644 --- a/flaskr/templates/estimate.html +++ b/flaskr/templates/estimate.html @@ -169,6 +169,13 @@ {{ render_field(form.comment) }} +
+ +
+ {{ render_field(form.run_name) }} + {{ content.estimate.help.run_name | safe }} +
+ diff --git a/flaskr/templates/estimation.html b/flaskr/templates/estimation.html index 23be136..8763afb 100644 --- a/flaskr/templates/estimation.html +++ b/flaskr/templates/estimation.html @@ -54,7 +54,7 @@ {% block body %}

- {{ estimation.public_id }} ({{ estimation.status.name }}) + {{ estimation.get_display_name() }} ({{ estimation.status.name }})

{% if estimation.errors %} @@ -83,7 +83,9 @@ {#

Total CO2 footprint (in kilograms-equivalent) of each city

#} {#
#}
-
+
+
+
{#
#} {#

A Legend here

#} @@ -559,6 +561,8 @@ jQuery(document).ready(function($){ return false; }); + $('#cities_footprints_spinner').hide(); + }); }); -- libgit2 0.21.2