Skip to content

Commit

Permalink
Update dependencies; Makefile.
Browse files Browse the repository at this point in the history
  • Loading branch information
toddbirchard committed Apr 24, 2022
1 parent eb87d4a commit 9d114b6
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 257 deletions.
69 changes: 47 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
SRCPATH := $(CURDIR)
PROJECTNAME := $(shell basename $(CURDIR))
PROJECT_NAME := $(shell basename $CURDIR)
VIRTUAL_ENVIRONMENT := $(CURDIR)/.venv
LOCAL_PYTHON := $(VIRTUAL_ENVIRONMENT)/bin/python3

define HELP
Manage $(PROJECTNAME). Usage:

make run - Run $(PROJECTNAME).
make deploy - Install requirements and run app for the first time.
make update - Update pip dependencies via Python Poetry.
make format - Format code with Python's `Black` library.
make lint - Check code formatting with flake8
Manage $(PROJECT_NAME). Usage:

make run - Run $(PROJECT_NAME).
make install - Create virtual env, install dependencies, and run project.
make deploy - Install and run script by running `make install` and `make run` in succession.
make update - Update pip dependencies via Poetry and export output to requirements.txt.
make format - Format code with Pythons `Black` library.
make lint - Check code formatting with `flake8`.
make clean - Remove cached files and lock files.

endef
export HELP

.PHONY: run deploy update format lint clean help

.PHONY: run install deploy update format lint clean help

requirements: .requirements.txt
env: .venv/bin/activate
env: ./.venv/bin/activate


.requirements.txt: requirements.txt
Expand All @@ -30,35 +33,57 @@ all help:

.PHONY: run
run: env
$(shell . .venv/bin/activate && flask run)
flask run


.PHONY: install
install:
if [ ! -d "./.venv" ]; then python3 -m venv $(VIRTUAL_ENVIRONMENT); fi
. .venv/bin/activate
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel
$(LOCAL_PYTHON) -m pip install -r requirements.txt


.PHONY: deploy
deploy:
$(shell . ./deploy.sh)
make install
make run


.PHONY: update
update: env
.venv/bin/python3 -m pip install -U pip
update:
if [ ! -d "./.venv" ]; then python3 -m venv $(VIRTUAL_ENVIRONMENT); fi
.venv/bin/python3 -m pip install --upgrade pip setuptools wheel
poetry update
poetry export -f requirements.txt --output requirements.txt --without-hashes


.PHONY: format
format: env
$(shell . .venv/bin/activate && isort ./)
$(shell . .venv/bin/activate && black ./)
isort --multi-line=3 .
black .


.PHONY: lint
lint:
flake8 . --count \
--select=E9,F63,F7,F82 \
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs \
--show-source \
--statistics


.PHONY: clean
clean:
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
find . -name 'poetry.lock' -delete
find . -name 'Pipefile.lock' -delete
find . -name 'logs/*.json' -delete
find . -name '*.log' -delete
find . -name '*/.pytest_cache' -delete
find . -name '*/logs/*.json' -delete
rm -rf tests/.pytest_cache
find . -name '.DS_Store' -delete
find . -wholename 'logs/*.json' -delete
find . -wholename '.pytest_cache' -delete
find . -wholename '**/.pytest_cache' -delete
find . -wholename './logs/*.json' -delete
find . -wholename './logs' -delete
find . -wholename '*.html' -delete
find . -wholename '**/.webassets-cache' -delete
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Flask-WTF Tutorial

![Python](https://img.shields.io/badge/Python-v^3.8-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
![Flask](https://img.shields.io/badge/Flask-v1.1.1-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
![Flask-WTF](https://img.shields.io/badge/Flask--WTF-v0.14.2-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
![Flask](https://img.shields.io/badge/Flask-v2.1.1-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
![Flask-WTF](https://img.shields.io/badge/Flask--WTF-v1.0.1-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c&logo=GitHub)
[![GitHub Issues](https://img.shields.io/github/issues/hackersandslackers/flask-wtform-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-wtform-tutorial/issues)
[![GitHub Stars](https://img.shields.io/github/stars/hackersandslackers/flask-wtform-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-wtform-tutorial/stargazers)
[![GitHub Forks](https://img.shields.io/github/forks/hackersandslackers/flask-wtform-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-wtform-tutorial/network)

![Flask-WTF Tutorial](https://github.com/hackersandslackers/flask-wtform-tutorial/blob/master/.github/[email protected]?raw=true)

**Tutorial**: https://hackersandslackers.com/flask-wtforms-forms/

**Demo**: https://flaskwtf.hackersandslackers.app/

Handle user input in your Flask app by creating forms with the Flask-WTForm library.

* **Tutorial**: https://hackersandslackers.com/flask-wtforms-forms/
* **Demo**: https://flaskwtf.hackersandslackers.app/
=
# Getting Started

Get set up locally:
Expand Down
12 changes: 4 additions & 8 deletions flask_wtforms_tutorial/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ class ContactForm(FlaskForm):

name = StringField("Name", [DataRequired()])
email = StringField(
"Email",
[Email(message="Not a valid email address."), DataRequired()]
"Email", [Email(message="Not a valid email address."), DataRequired()]
)
body = TextAreaField(
"Message",
[DataRequired(), Length(min=4, message="Your message is too short.")]
"Message", [DataRequired(), Length(min=4, message="Your message is too short.")]
)
submit = SubmitField("Submit")

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

email = StringField(
"Email",
[Email(message="Not a valid email address."), DataRequired()]
"Email", [Email(message="Not a valid email address."), DataRequired()]
)
password = PasswordField(
"Password",
[DataRequired(message="Please enter a password.")],
)
confirmPassword = PasswordField(
"Repeat Password",
[EqualTo(password, message="Passwords must match.")]
"Repeat Password", [EqualTo(password, message="Passwords must match.")]
)
title = SelectField(
"Title",
Expand Down
19 changes: 4 additions & 15 deletions flask_wtforms_tutorial/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
def home():
"""Landing page."""
return render_template(
"index.jinja2",
template="home-template",
title="Flask-WTF tutorial"
"index.jinja2", template="home-template", title="Flask-WTF tutorial"
)


Expand All @@ -22,10 +20,7 @@ def contact():
if form.validate_on_submit():
return redirect(url_for("success"))
return render_template(
"contact.jinja2",
form=form,
template="form-template",
title="Contact Form"
"contact.jinja2", form=form, template="form-template", title="Contact Form"
)


Expand All @@ -36,17 +31,11 @@ def signup():
if form.validate_on_submit():
return redirect(url_for("success"))
return render_template(
"signup.jinja2",
form=form,
template="form-template",
title="Signup Form"
"signup.jinja2", form=form, template="form-template", title="Signup Form"
)


@app.route("/success", methods=["GET", "POST"])
def success():
"""Generic success page upon form submission."""
return render_template(
"success.jinja2",
template="success-template"
)
return render_template("success.jinja2", template="success-template")
Loading

0 comments on commit 9d114b6

Please sign in to comment.