Skip to content

Commit b72f822

Browse files
authored
Merge pull request #60 from HeMan/blacked
Now complies with black.
2 parents 7601d12 + 55afe46 commit b72f822

File tree

12 files changed

+146
-135
lines changed

12 files changed

+146
-135
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
env:
1414
global:
1515
- DOCKER_COMPOSE_VERSION=1.18.0
16+
- BLACK_VERSION=18.9b0
1617

1718
before_install:
1819
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then bash docker-compose.sh; fi
@@ -23,8 +24,10 @@ install:
2324

2425
before_script:
2526
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then docker-compose up --build -d; fi
27+
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then pip install black==$BLACK_VERSION; fi
2628

2729
script:
30+
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then black --line-length 79 --check --diff .; fi
2831
- flake8 .
2932
- python manage.py cov
3033
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then docker-compose run web python manage.py cov; fi

{{cookiecutter.app_slug}}/manage.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
# code coverage
1919
COV = coverage.coverage(
2020
branch=True,
21-
include='project/*',
21+
include="project/*",
2222
omit=[
23-
'project/tests/*',
24-
'project/server/config.py',
25-
'project/server/*/__init__.py'
26-
]
23+
"project/tests/*",
24+
"project/server/config.py",
25+
"project/server/*/__init__.py",
26+
],
2727
)
2828
COV.start()
2929

@@ -44,7 +44,7 @@ def drop_db():
4444
@cli.command()
4545
def create_admin():
4646
"""Creates the admin user."""
47-
db.session.add(User(email='[email protected]', password='admin', admin=True))
47+
db.session.add(User(email="[email protected]", password="admin", admin=True))
4848
db.session.commit()
4949

5050

@@ -57,7 +57,7 @@ def create_data():
5757
@cli.command()
5858
def test():
5959
"""Runs the unit tests without test coverage."""
60-
tests = unittest.TestLoader().discover('project/tests', pattern='test*.py')
60+
tests = unittest.TestLoader().discover("project/tests", pattern="test*.py")
6161
result = unittest.TextTestRunner(verbosity=2).run(tests)
6262
if result.wasSuccessful():
6363
sys.exit(0)
@@ -68,12 +68,12 @@ def test():
6868
@cli.command()
6969
def cov():
7070
"""Runs the unit tests with coverage."""
71-
tests = unittest.TestLoader().discover('project/tests')
71+
tests = unittest.TestLoader().discover("project/tests")
7272
result = unittest.TextTestRunner(verbosity=2).run(tests)
7373
if result.wasSuccessful():
7474
COV.stop()
7575
COV.save()
76-
print('Coverage Summary:')
76+
print("Coverage Summary:")
7777
COV.report()
7878
COV.html_report()
7979
COV.erase()
@@ -85,8 +85,8 @@ def cov():
8585
@cli.command()
8686
def flake():
8787
"""Runs flake8 on the project."""
88-
subprocess.run(['flake8', 'project'])
88+
subprocess.run(["flake8", "project"])
8989

9090

91-
if __name__ == '__main__':
91+
if __name__ == "__main__":
9292
cli()

{{cookiecutter.app_slug}}/project/server/__init__.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ def create_app(script_info=None):
2626
# instantiate the app
2727
app = Flask(
2828
__name__,
29-
template_folder='../client/templates',
30-
static_folder='../client/static'
29+
template_folder="../client/templates",
30+
static_folder="../client/static",
3131
)
3232

3333
# set config
3434
app_settings = os.getenv(
35-
'APP_SETTINGS', 'project.server.config.DevelopmentConfig')
35+
"APP_SETTINGS", "project.server.config.DevelopmentConfig"
36+
)
3637
app.config.from_object(app_settings)
3738

3839
# set up extensions
@@ -46,13 +47,15 @@ def create_app(script_info=None):
4647
# register blueprints
4748
from project.server.user.views import user_blueprint
4849
from project.server.main.views import main_blueprint
50+
4951
app.register_blueprint(user_blueprint)
5052
app.register_blueprint(main_blueprint)
5153

5254
# flask login
5355
from project.server.models import User
54-
login_manager.login_view = 'user.login'
55-
login_manager.login_message_category = 'danger'
56+
57+
login_manager.login_view = "user.login"
58+
login_manager.login_message_category = "danger"
5659

5760
@login_manager.user_loader
5861
def load_user(user_id):
@@ -61,23 +64,23 @@ def load_user(user_id):
6164
# error handlers
6265
@app.errorhandler(401)
6366
def unauthorized_page(error):
64-
return render_template('errors/401.html'), 401
67+
return render_template("errors/401.html"), 401
6568

6669
@app.errorhandler(403)
6770
def forbidden_page(error):
68-
return render_template('errors/403.html'), 403
71+
return render_template("errors/403.html"), 403
6972

7073
@app.errorhandler(404)
7174
def page_not_found(error):
72-
return render_template('errors/404.html'), 404
75+
return render_template("errors/404.html"), 404
7376

7477
@app.errorhandler(500)
7578
def server_error_page(error):
76-
return render_template('errors/500.html'), 500
79+
return render_template("errors/500.html"), 500
7780

7881
# shell context for flask cli
7982
@app.shell_context_processor
8083
def ctx():
81-
return {'app': app, 'db': db}
84+
return {"app": app, "db": db}
8285

8386
return app

{{cookiecutter.app_slug}}/project/server/config.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,37 @@
77

88
class BaseConfig(object):
99
"""Base configuration."""
10-
APP_NAME = os.getenv('APP_NAME', '{{cookiecutter.app_name}}')
10+
11+
APP_NAME = os.getenv("APP_NAME", "{{cookiecutter.app_name}}")
1112
BCRYPT_LOG_ROUNDS = 4
1213
DEBUG_TB_ENABLED = False
13-
SECRET_KEY = os.getenv('SECRET_KEY', 'my_precious')
14+
SECRET_KEY = os.getenv("SECRET_KEY", "my_precious")
1415
SQLALCHEMY_TRACK_MODIFICATIONS = False
1516
WTF_CSRF_ENABLED = False
1617

1718

1819
class DevelopmentConfig(BaseConfig):
1920
"""Development configuration."""
21+
2022
DEBUG_TB_ENABLED = True
2123
DEBUG_TB_INTERCEPT_REDIRECTS = False
2224
SQLALCHEMY_DATABASE_URI = os.environ.get(
23-
'DATABASE_URL',
24-
'sqlite:///{0}'.format(os.path.join(basedir, 'dev.db')))
25+
"DATABASE_URL", "sqlite:///{0}".format(os.path.join(basedir, "dev.db"))
26+
)
2527

2628

2729
class TestingConfig(BaseConfig):
2830
"""Testing configuration."""
31+
2932
PRESERVE_CONTEXT_ON_EXCEPTION = False
30-
SQLALCHEMY_DATABASE_URI = 'sqlite:///'
31-
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_TEST_URL', 'sqlite:///')
33+
SQLALCHEMY_DATABASE_URI = "sqlite:///"
34+
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_TEST_URL", "sqlite:///")
3235
TESTING = True
3336

3437

3538
class ProductionConfig(BaseConfig):
3639
"""Production configuration."""
40+
3741
BCRYPT_LOG_ROUNDS = 13
38-
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
42+
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
3943
WTF_CSRF_ENABLED = True

{{cookiecutter.app_slug}}/project/server/main/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from flask import render_template, Blueprint
55

66

7-
main_blueprint = Blueprint('main', __name__,)
7+
main_blueprint = Blueprint("main", __name__)
88

99

10-
@main_blueprint.route('/')
10+
@main_blueprint.route("/")
1111
def home():
12-
return render_template('main/home.html')
12+
return render_template("main/home.html")
1313

1414

1515
@main_blueprint.route("/about/")

{{cookiecutter.app_slug}}/project/server/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class User(db.Model):
1212

13-
__tablename__ = 'users'
13+
__tablename__ = "users"
1414

1515
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
1616
email = db.Column(db.String(255), unique=True, nullable=False)
@@ -21,8 +21,8 @@ class User(db.Model):
2121
def __init__(self, email, password, admin=False):
2222
self.email = email
2323
self.password = bcrypt.generate_password_hash(
24-
password, current_app.config.get('BCRYPT_LOG_ROUNDS')
25-
).decode('utf-8')
24+
password, current_app.config.get("BCRYPT_LOG_ROUNDS")
25+
).decode("utf-8")
2626
self.registered_on = datetime.datetime.now()
2727
self.admin = admin
2828

@@ -39,4 +39,4 @@ def get_id(self):
3939
return self.id
4040

4141
def __repr__(self):
42-
return '<User {0}>'.format(self.email)
42+
return "<User {0}>".format(self.email)

{{cookiecutter.app_slug}}/project/server/user/forms.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,26 @@
77

88

99
class LoginForm(FlaskForm):
10-
email = StringField('Email Address', [DataRequired(), Email()])
11-
password = PasswordField('Password', [DataRequired()])
10+
email = StringField("Email Address", [DataRequired(), Email()])
11+
password = PasswordField("Password", [DataRequired()])
1212

1313

1414
class RegisterForm(FlaskForm):
1515
email = StringField(
16-
'Email Address',
16+
"Email Address",
1717
validators=[
1818
DataRequired(),
1919
Email(message=None),
20-
Length(min=6, max=40)
21-
]
20+
Length(min=6, max=40),
21+
],
2222
)
2323
password = PasswordField(
24-
'Password',
25-
validators=[DataRequired(), Length(min=6, max=25)]
24+
"Password", validators=[DataRequired(), Length(min=6, max=25)]
2625
)
2726
confirm = PasswordField(
28-
'Confirm password',
27+
"Confirm password",
2928
validators=[
3029
DataRequired(),
31-
EqualTo('password', message='Passwords must match.')
32-
]
30+
EqualTo("password", message="Passwords must match."),
31+
],
3332
)
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,59 @@
11
# project/server/user/views.py
22

33

4-
from flask import render_template, Blueprint, url_for, \
5-
redirect, flash, request
4+
from flask import render_template, Blueprint, url_for, redirect, flash, request
65
from flask_login import login_user, logout_user, login_required
76

87
from project.server import bcrypt, db
98
from project.server.models import User
109
from project.server.user.forms import LoginForm, RegisterForm
1110

1211

13-
user_blueprint = Blueprint('user', __name__,)
12+
user_blueprint = Blueprint("user", __name__)
1413

1514

16-
@user_blueprint.route('/register', methods=['GET', 'POST'])
15+
@user_blueprint.route("/register", methods=["GET", "POST"])
1716
def register():
1817
form = RegisterForm(request.form)
1918
if form.validate_on_submit():
20-
user = User(
21-
email=form.email.data,
22-
password=form.password.data
23-
)
19+
user = User(email=form.email.data, password=form.password.data)
2420
db.session.add(user)
2521
db.session.commit()
2622

2723
login_user(user)
2824

29-
flash('Thank you for registering.', 'success')
25+
flash("Thank you for registering.", "success")
3026
return redirect(url_for("user.members"))
3127

32-
return render_template('user/register.html', form=form)
28+
return render_template("user/register.html", form=form)
3329

3430

35-
@user_blueprint.route('/login', methods=['GET', 'POST'])
31+
@user_blueprint.route("/login", methods=["GET", "POST"])
3632
def login():
3733
form = LoginForm(request.form)
3834
if form.validate_on_submit():
3935
user = User.query.filter_by(email=form.email.data).first()
4036
if user and bcrypt.check_password_hash(
41-
user.password, request.form['password']):
37+
user.password, request.form["password"]
38+
):
4239
login_user(user)
43-
flash('You are logged in. Welcome!', 'success')
44-
return redirect(url_for('user.members'))
40+
flash("You are logged in. Welcome!", "success")
41+
return redirect(url_for("user.members"))
4542
else:
46-
flash('Invalid email and/or password.', 'danger')
47-
return render_template('user/login.html', form=form)
48-
return render_template('user/login.html', title='Please Login', form=form)
43+
flash("Invalid email and/or password.", "danger")
44+
return render_template("user/login.html", form=form)
45+
return render_template("user/login.html", title="Please Login", form=form)
4946

5047

51-
@user_blueprint.route('/logout')
48+
@user_blueprint.route("/logout")
5249
@login_required
5350
def logout():
5451
logout_user()
55-
flash('You were logged out. Bye!', 'success')
56-
return redirect(url_for('main.home'))
52+
flash("You were logged out. Bye!", "success")
53+
return redirect(url_for("main.home"))
5754

5855

59-
@user_blueprint.route('/members')
56+
@user_blueprint.route("/members")
6057
@login_required
6158
def members():
62-
return render_template('user/members.html')
59+
return render_template("user/members.html")

{{cookiecutter.app_slug}}/project/tests/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010

1111

1212
class BaseTestCase(TestCase):
13-
1413
def create_app(self):
15-
app.config.from_object('project.server.config.TestingConfig')
14+
app.config.from_object("project.server.config.TestingConfig")
1615
return app
1716

1817
def setUp(self):

0 commit comments

Comments
 (0)