Skip to content

Commit e21da70

Browse files
committed
Form templates post to themselves.
1 parent 2a377e6 commit e21da70

File tree

18 files changed

+351
-382
lines changed

18 files changed

+351
-382
lines changed

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ make run - Run $(PROJECTNAME).
88
make deploy - Install requirements and run app for the first time.
99
make update - Update pip dependencies via Python Poetry.
1010
make format - Format code with Python's `Black` library.
11+
make lint - Check code formatting with flake8
1112
make clean - Remove cached files and lock files.
1213
endef
1314
export HELP
1415

15-
.PHONY: run deploy update format clean help
16+
.PHONY: run deploy update format lint clean help
1617

1718

1819
requirements: .requirements.txt
@@ -55,4 +56,9 @@ clean:
5556
find . -name '*.pyc' -delete
5657
find . -name '__pycache__' -delete
5758
find . -name 'poetry.lock' -delete
58-
find . -name 'Pipefile.lock' -delete
59+
find . -name 'Pipefile.lock' -delete
60+
find . -name 'logs/*.json' -delete
61+
find . -name '*.log' -delete
62+
find . -name '*/.pytest_cache' -delete
63+
find . -name '*/logs/*.json' -delete
64+
rm -rf tests/.pytest_cache

config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class Config:
1515
SECRET_KEY = environ.get("SECRET_KEY")
1616
FLASK_APP = environ.get("FLASK_APP")
1717
FLASK_ENV = environ.get("FLASK_ENV")
18-
SERVER_NAME = environ.get("SERVER_NAME")
1918

2019
# Static Assets
2120
STATIC_FOLDER = "static"

deploy.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
if [ -d ".venv" ]
44
then
5-
source .venv/bin/activate
5+
. .venv/bin/activate
66
pip install -r requirements.txt
7-
python3 wsgi.py
87
else
98
python3 -m venv .venv
10-
source .venv/bin/activate
9+
. .venv/bin/activate
1110
python3 -m pip install --upgrade pip
1211
pip install -r requirements.txt
13-
python3 wsgi.py
1412
fi

flask_wtforms_tutorial/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
"""Initialize app."""
2-
from ddtrace import patch_all
32
from flask import Flask
43

5-
patch_all()
6-
74

85
def create_app():
96
"""Construct the core flask_wtforms_tutorial."""

flask_wtforms_tutorial/forms.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ class ContactForm(FlaskForm):
1616

1717
name = StringField("Name", [DataRequired()])
1818
email = StringField(
19-
"Email", [Email(message="Not a valid email address."), DataRequired()]
19+
"Email",
20+
[Email(message="Not a valid email address."), DataRequired()]
2021
)
2122
body = TextAreaField(
22-
"Message", [DataRequired(), Length(min=4, message="Your message is too short.")]
23+
"Message",
24+
[DataRequired(), Length(min=4, message="Your message is too short.")]
2325
)
2426
submit = SubmitField("Submit")
2527

@@ -28,16 +30,16 @@ class SignupForm(FlaskForm):
2830
"""Sign up for a user account."""
2931

3032
email = StringField(
31-
"Email", [Email(message="Not a valid email address."), DataRequired()]
33+
"Email",
34+
[Email(message="Not a valid email address."), DataRequired()]
3235
)
3336
password = PasswordField(
3437
"Password",
35-
[
36-
DataRequired(message="Please enter a password."),
37-
],
38+
[DataRequired(message="Please enter a password.")],
3839
)
3940
confirmPassword = PasswordField(
40-
"Repeat Password", [EqualTo(password, message="Passwords must match.")]
41+
"Repeat Password",
42+
[EqualTo(password, message="Passwords must match.")]
4143
)
4244
title = SelectField(
4345
"Title",

flask_wtforms_tutorial/routes.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,36 @@ def home():
99
return render_template("index.jinja2", template="home-template")
1010

1111

12-
@app.route("/contact", methods=("GET", "POST"))
12+
@app.route("/contact", methods=["GET", "POST"])
1313
def contact():
14+
"""Standard `contact` form, typically used to send emails."""
1415
form = ContactForm()
1516
if form.validate_on_submit():
1617
return redirect(url_for("success"))
17-
return render_template("contact.jinja2", form=form, template="form-template")
18+
return render_template(
19+
"contact.jinja2",
20+
form=form,
21+
template="form-template"
22+
)
1823

1924

20-
@app.route("/signup", methods=("GET", "POST"))
25+
@app.route("/signup", methods=["GET", "POST"])
2126
def signup():
27+
"""User sign-up form for account creation."""
2228
form = SignupForm()
2329
if form.validate_on_submit():
2430
return redirect(url_for("success"))
25-
return render_template("signup.jinja2", form=form, template="form-template")
31+
return render_template(
32+
"signup.jinja2",
33+
form=form,
34+
template="form-template"
35+
)
2636

2737

28-
@app.route("/success", methods=("GET", "POST"))
38+
@app.route("/success", methods=["GET", "POST"])
2939
def success():
30-
return render_template("success.jinja2", template="success-template")
40+
"""Generic success page displayed when users submit a valid forms."""
41+
return render_template(
42+
"success.jinja2",
43+
template="success-template"
44+
)

flask_wtforms_tutorial/static/css/forms.css

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ form {
55

66
.form-field {
77
position: relative;
8+
border: 0;
9+
padding: 0;
810
}
911

1012
.container {
@@ -22,11 +24,11 @@ form {
2224
margin: 0 0 40px 0;
2325
}
2426

25-
.formwrapper {
27+
.form-wrapper {
2628
background: white;
2729
width: 350px;
2830
box-shadow: 0 0 5px rgba(65, 67, 144, 0.1);
29-
padding: 50px;
31+
padding: 40px;
3032
}
3133

3234
label {
@@ -41,6 +43,7 @@ input, textarea, select {
4143
padding: 10px 13px;
4244
margin-bottom: 15px;
4345
width: -webkit-fill-available;
46+
width: -moz-available;
4447
border-radius: 2px;
4548
border: 1px solid #d4d9e3;
4649
font-weight: 200;
@@ -86,18 +89,20 @@ textarea:focus {
8689
box-shadow: unset;
8790
}
8891

89-
input[type="submit"] {
92+
input[type="submit"],
93+
button {
9094
background: #5eb9d7;
91-
border: 0;
9295
color: white;
9396
border-radius: 2px;
9497
margin-top: 15px;
9598
font-weight: 400;
9699
border: 1px solid #5eb9d7;
100+
line-height: 1;
97101
transition: all .3s ease-out;
98102
}
99103

100-
input[type="submit"]:hover {
104+
input[type="submit"]:hover,
105+
button:hover {
101106
cursor: pointer;
102107
background: white;
103108
color: #5eb9d7;
@@ -112,7 +117,7 @@ input[type="submit"]:hover {
112117

113118
.errors {
114119
list-style: none;
115-
margin: 10px 0;
120+
margin: 10px auto;
116121
position: absolute;
117122
z-index: 10;
118123
right: -222px;
@@ -126,7 +131,6 @@ input[type="submit"]:hover {
126131
width: 182px;
127132
text-align: center;
128133
height: fit-content;
129-
margin: auto;
130134
}
131135

132136
i {
@@ -135,10 +139,10 @@ i {
135139
top: 4px;
136140
bottom: 0;
137141
right: 16px;
138-
height: fit-content;
139142
color: grey;
143+
height: 15px;
140144
}
141145

142146
.g-recaptcha div {
143147
margin: auto;
144-
}
148+
}

flask_wtforms_tutorial/static/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
body {
22
background: #e1eaf5;
3-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
3+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
44
}
55

66
h1 {

flask_wtforms_tutorial/static/css/success.css

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.success-wrapper {
22
background: white;
3-
width: 300px;
4-
padding: 30px;
3+
width: 350px;
4+
padding: 40px;
55
text-align: center;
66
margin: 50px auto 0;
77
display: block;
@@ -14,4 +14,24 @@
1414
.success-wrapper p {
1515
text-align: center;
1616
color: #363a40;
17+
line-height: 1.3;
1718
}
19+
20+
button {
21+
background: #5eb9d7;
22+
color: white;
23+
border-radius: 2px;
24+
margin-top: 15px;
25+
font-weight: 400;
26+
border: 1px solid #5eb9d7;
27+
line-height: 1;
28+
transition: all .3s ease-out;
29+
padding: 10px 15px;
30+
font-size: 1.1em;
31+
}
32+
33+
button:hover {
34+
cursor: pointer;
35+
background: white;
36+
color: #5eb9d7;
37+
}

flask_wtforms_tutorial/templates/analytics.jinja2

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)