From 35a99ac76a73e40a8dace666de7463b7e924f756 Mon Sep 17 00:00:00 2001 From: Goutte Date: Sat, 19 Oct 2019 12:48:09 +0200 Subject: [PATCH] Move more text content to the YAML file. --- flaskr/__init__.py | 11 +++-------- flaskr/content.py | 4 ++++ flaskr/forms.py | 56 ++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 flaskr/content.py diff --git a/flaskr/__init__.py b/flaskr/__init__.py index 96af7cf..36188aa 100755 --- a/flaskr/__init__.py +++ b/flaskr/__init__.py @@ -5,7 +5,7 @@ from webassets.loaders import PythonLoader as PythonAssetsLoader from flaskr import assets from flaskr.models import db -from flaskr.controllers.main import main +from flaskr.controllers.main_controller import main from flaskr.extensions import ( cache, @@ -14,7 +14,7 @@ from flaskr.extensions import ( login_manager ) -from yaml import safe_load as yaml_safe_load +from flaskr.content import content from markdown import markdown @@ -57,12 +57,7 @@ def create_app(object_name): # register our blueprints app.register_blueprint(main) - # Load content data from the YAML file - content = {} - with open('content.yml', 'r') as content_file: - content = yaml_safe_load(content_file.read()) - - # VERSION + # VERSION (move to version.py is necessary) version = "0.0.0" with open('VERSION', 'r') as version_file: version = version_file.read().strip() diff --git a/flaskr/content.py b/flaskr/content.py new file mode 100644 index 0000000..104cb33 --- /dev/null +++ b/flaskr/content.py @@ -0,0 +1,4 @@ +from yaml import safe_load as yaml_safe_load + +with open('content.yml', 'r') as content_file: + content = yaml_safe_load(content_file.read()) diff --git a/flaskr/forms.py b/flaskr/forms.py index 1aec729..81bff04 100644 --- a/flaskr/forms.py +++ b/flaskr/forms.py @@ -7,73 +7,85 @@ from wtforms import \ from wtforms import validators from .models import User +from .content import content + +form_content = content['estimate']['form'] # ESTIMATION FORM ############################################################# class EstimateForm(Form): email = StringField( - label=u"Email Address", - description=u"Make sure you provide a valid address " - u"or you won't receive the results.", + label=form_content['email']['label'], + description=form_content['email']['description'], validators=[ validators.DataRequired(), validators.Email(), ], ) first_name = StringField( - label=u"First Name", - description=u"Also known as given name, eg. `Didier`.", + label=form_content['first_name']['label'], + description=form_content['first_name']['description'], validators=[ validators.Optional(), validators.Length(max=1024), ], ) last_name = StringField( - label=u"Last Name", - description=u"Also known as family name, eg. `Barret`.", + label=form_content['last_name']['label'], + description=form_content['last_name']['description'], validators=[ validators.Optional(), validators.Length(max=1024), ], ) institution = StringField( - label=u"Institution / Enterprise", - description=u"If any.", + label=form_content['institution']['label'], + description=form_content['institution']['description'], validators=[ validators.Optional(), validators.Length(max=1024), ], ) comment = TextAreaField( - label=u"Leave a comment", - description=u"Any input is appreciated. Everyone's a critic.", + label=form_content['comment']['label'], + description=form_content['comment']['description'], validators=[ validators.Optional(), validators.Length(max=2048), ], ) origin_addresses = TextAreaField( - label=u"Origin Cities", - description=u"One address per line, in the form `City, Country`. " - u"Make sure your addresses are correctly spelled.", + label=form_content['origin_addresses']['label'], + description=form_content['origin_addresses']['description'], validators=[ validators.DataRequired(), ], + render_kw={ + "placeholder": form_content['origin_addresses']['placeholder'] + }, ) destination_addresses = TextAreaField( - label=u"Destination Cities", - description=u"One address per line, in the form `City, Country`. " - u"Make sure your addresses are correctly spelled.", + label=form_content['destination_addresses']['label'], + description=form_content['destination_addresses']['description'], validators=[ validators.DataRequired(), ], + render_kw={ + "placeholder": form_content['destination_addresses']['placeholder'] + }, + ) + compute_optimal_destination = BooleanField( + label=form_content['compute_optimal_destination']['label'], + description=form_content['compute_optimal_destination']['description'], + default=False, + validators=[ + validators.Optional(), + ], ) - should_compute_optimal_destination = BooleanField( - label=u"Compute the destination city " - u"that will minimize emissions?
" - u"(useful when setting up a meeting/conference)", - description=u"", + use_atmosfair_rfi = BooleanField( + label=form_content['use_atmosfair_rfi']['label'], + description=form_content['use_atmosfair_rfi']['description'], default=False, validators=[ validators.Optional(), -- libgit2 0.21.2