-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
455 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
import os | ||
import sys | ||
|
||
from flask import Flask | ||
|
||
from .components import bp as components_bp | ||
from .utilities import bp as utilities_bp | ||
from .forms import bp as forms_bp | ||
# from .forms.routes import WTFormsHelpers | ||
from .templates import bp as templates_bp | ||
from .utilities import bp as utilities_bp | ||
|
||
|
||
sys.path.append('/home/app/') | ||
|
||
from tna_frontend_jinja.wtforms.widgets import WTFormsHelpers | ||
|
||
app = Flask(__name__, template_folder="/home/app/tna_frontend_jinja/templates") | ||
|
||
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY") | ||
|
||
@app.route("/ready/") | ||
def ready(): | ||
|
||
@app.route("/healthcheck/live/") | ||
def healthcheck(): | ||
return "ok" | ||
|
||
|
||
app.register_blueprint(components_bp, url_prefix="/components") | ||
app.register_blueprint(utilities_bp, url_prefix="/utilities") | ||
app.register_blueprint(templates_bp, url_prefix="/templates") | ||
app.register_blueprint(forms_bp, url_prefix="/forms") | ||
|
||
WTFormsHelpers(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from flask import Blueprint | ||
|
||
bp = Blueprint("forms", __name__, template_folder="test-templates") | ||
|
||
from app.forms import routes # noqa: E402,F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
from app.forms import bp | ||
from flask import redirect, render_template, url_for | ||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, SubmitField | ||
from wtforms.validators import Email, InputRequired, Length | ||
|
||
sys.path.append('/home/app/') | ||
from tna_frontend_jinja.wtforms.widgets import GovTextInput, GovSubmitInput | ||
|
||
|
||
class ExampleForm(FlaskForm): | ||
email_address = StringField( | ||
"Email address", | ||
widget=GovTextInput(), | ||
validators=[ | ||
InputRequired(message="Enter an email address"), | ||
Length( | ||
max=256, message="Email address must be 256 characters or fewer" | ||
), | ||
Email( | ||
message="Enter an email address in the correct format, like [email protected]" | ||
), | ||
], | ||
description="We’ll only use this to send you a receipt", | ||
) | ||
|
||
submit = SubmitField("Continue", widget=GovSubmitInput()) | ||
|
||
|
||
@bp.route("/", methods=["GET", "POST"]) | ||
def index(): | ||
form = ExampleForm() | ||
if form.validate_on_submit(): | ||
return redirect(url_for("forms.index")) | ||
return render_template("example-form.html", form=form) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{% extends "layouts/base.html" %} | ||
|
||
{%- from 'components/error-summary/macro.html' import tnaErrorSummary -%} | ||
|
||
{% block pageTitle %}{%- if form and form.errors %}Error: {% endif -%}Example form – GOV.UK Frontend WTForms Demo{% endblock %} | ||
|
||
{% block stylesheets %} | ||
<link rel="stylesheet" href="https://use.typekit.net/kaq6qqh.css"> | ||
<link href="https://cdn.jsdelivr.net/npm/@nationalarchives/[email protected]/nationalarchives/all.css" rel="stylesheet" integrity="sha384-GFKsKURhzcIk6FnRgNbpibhx4qgCtEI8HV1kJ/4NkO0t3FFIWKnP7UlantvRj6FP" crossorigin="anonymous"> | ||
{% endblock %} | ||
|
||
{% block cookies %} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="tna-container tna-section"> | ||
<div class="tna-column tna-column--width-2-3 tna-column--width-5-6-medium tna-column--full-small tna-column--full-tiny"> | ||
{% if form.errors %} | ||
{{ tnaErrorSummary(wtforms_errors(form)) }} | ||
{% endif %} | ||
<h1 class="tna-heading-xl">Example form</h1> | ||
<form action="" method="post" novalidate> | ||
{{ form.csrf_token }} | ||
{{ form.email_address(params={ | ||
'headingLevel': 2, | ||
'type': 'email', | ||
'autofill': 'email', | ||
'spellcheck': False | ||
}) }} | ||
<div class="tna-button-group"> | ||
{{ form.submit }} | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block bodyEnd %} | ||
<script src="https://cdn.jsdelivr.net/npm/@nationalarchives/[email protected]/nationalarchives/all.js" integrity="sha384-s768ALHSnzGU2X2ENYTrlF+CfnKaa3Us1eU78VrZ4eTKwLjWob1Wbb9tIT2xfmBq" crossorigin="anonymous"></script> | ||
<script> | ||
// Initialise all TNA components | ||
window.TNAFrontend.initAll(); | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{%- from "components/button/macro.html" import tnaButton -%} | ||
{{ tnaButton(params) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{%- from "components/text-input/macro.html" import tnaTextInput -%} | ||
{{ tnaTextInput(params) }} |
Oops, something went wrong.