Skip to content

Commit cf81930

Browse files
committed
make style changes to conform to pep8
1 parent 0d33c83 commit cf81930

File tree

8 files changed

+82
-75
lines changed

8 files changed

+82
-75
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013 Ryan Shea - http://ryaneshea.com/
3+
Copyright (c) 2015 Ryan Shea - http://shea.io
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

angular_flask/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@
1212
import angular_flask.core
1313
import angular_flask.models
1414
import angular_flask.controllers
15-

angular_flask/controllers.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,51 @@
66

77
from angular_flask import app
88

9-
# routing for API endpoints (generated from the models designated as API_MODELS)
9+
# routing for API endpoints, generated from the models designated as API_MODELS
1010
from angular_flask.core import api_manager
1111
from angular_flask.models import *
1212

1313
for model_name in app.config['API_MODELS']:
14-
model_class = app.config['API_MODELS'][model_name]
15-
api_manager.create_api(model_class, methods=['GET', 'POST'])
14+
model_class = app.config['API_MODELS'][model_name]
15+
api_manager.create_api(model_class, methods=['GET', 'POST'])
1616

1717
session = api_manager.session
1818

19+
1920
# routing for basic pages (pass routing onto the Angular app)
2021
@app.route('/')
2122
@app.route('/about')
2223
@app.route('/blog')
2324
def basic_pages(**kwargs):
24-
return make_response(open('angular_flask/templates/index.html').read())
25+
return make_response(open('angular_flask/templates/index.html').read())
26+
2527

2628
# routing for CRUD-style endpoints
2729
# passes routing onto the angular frontend if the requested resource exists
2830
from sqlalchemy.sql import exists
2931

3032
crud_url_models = app.config['CRUD_URL_MODELS']
3133

34+
3235
@app.route('/<model_name>/')
3336
@app.route('/<model_name>/<item_id>')
3437
def rest_pages(model_name, item_id=None):
35-
if model_name in crud_url_models:
36-
model_class = crud_url_models[model_name]
37-
if item_id is None or session.query(exists().where(
38-
model_class.id == item_id)).scalar():
39-
return make_response(open(
40-
'angular_flask/templates/index.html').read())
41-
abort(404)
38+
if model_name in crud_url_models:
39+
model_class = crud_url_models[model_name]
40+
if item_id is None or session.query(exists().where(
41+
model_class.id == item_id)).scalar():
42+
return make_response(open(
43+
'angular_flask/templates/index.html').read())
44+
abort(404)
45+
4246

4347
# special file handlers and error handlers
4448
@app.route('/favicon.ico')
4549
def favicon():
46-
return send_from_directory(os.path.join(app.root_path, 'static'),
47-
'img/favicon.ico')
50+
return send_from_directory(os.path.join(app.root_path, 'static'),
51+
'img/favicon.ico')
52+
4853

4954
@app.errorhandler(404)
5055
def page_not_found(e):
5156
return render_template('404.html'), 404
52-
53-
54-

angular_flask/core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
db = SQLAlchemy(app)
77

88
api_manager = APIManager(app, flask_sqlalchemy_db=db)
9-

angular_flask/models.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@
33
from angular_flask.core import db
44
from angular_flask import app
55

6+
67
class Post(db.Model):
7-
id = db.Column(db.Integer, primary_key=True)
8-
title = db.Column(db.String(80))
9-
body = db.Column(db.Text)
10-
pub_date = db.Column(db.DateTime)
8+
id = db.Column(db.Integer, primary_key=True)
9+
title = db.Column(db.String(80))
10+
body = db.Column(db.Text)
11+
pub_date = db.Column(db.DateTime)
1112

12-
def __init__(self, title, body, pub_date=None):
13-
self.title = title
14-
self.body = body
15-
if pub_date is None:
16-
pub_date = datetime.utcnow()
17-
self.pub_date = pub_date
13+
def __init__(self, title, body, pub_date=None):
14+
self.title = title
15+
self.body = body
16+
if pub_date is None:
17+
pub_date = datetime.utcnow()
18+
self.pub_date = pub_date
1819

19-
def __repr__(self):
20-
return '<Post %r>' % self.title
20+
def __repr__(self):
21+
return '<Post %r>' % self.title
2122

2223
# models for which we want to create API endpoints
23-
app.config['API_MODELS'] = { 'post': Post }
24+
app.config['API_MODELS'] = {'post': Post}
2425

2526
# models for which we want to create CRUD-style URL endpoints,
2627
# and pass the routing onto our AngularJS application
27-
app.config['CRUD_URL_MODELS'] = { 'post': Post }
28+
app.config['CRUD_URL_MODELS'] = {'post': Post}

angular_flask/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
DEBUG = True
3-
SECRET_KEY = 'temporary_secret_key' # make sure to change this
3+
SECRET_KEY = 'temporary_secret_key' # make sure to change this
44

55
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/angular_flask.db'
6-

manage.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,54 @@
66
from angular_flask.core import db
77
from angular_flask.models import Post
88

9+
910
def create_sample_db_entry(api_endpoint, payload):
10-
url = 'http://localhost:5000/' + api_endpoint
11-
r = requests.post(url, data=json.dumps(payload), headers={'Content-Type': 'application/json'})
12-
print r.text
13-
11+
url = 'http://localhost:5000/' + api_endpoint
12+
r = requests.post(
13+
url, data=json.dumps(payload),
14+
headers={'Content-Type': 'application/json'})
15+
print r.text
16+
17+
1418
def create_db():
15-
db.create_all()
19+
db.create_all()
20+
1621

1722
def drop_db():
18-
db.drop_all()
23+
db.drop_all()
24+
1925

2026
def main():
21-
parser = argparse.ArgumentParser(description='Manage this Flask application.')
22-
parser.add_argument('command', help='the name of the command you want to run')
23-
parser.add_argument('--seedfile', help='the file with data for seeding the database')
24-
args = parser.parse_args()
25-
26-
if args.command == 'create_db':
27-
create_db()
28-
29-
print "DB created!"
30-
elif args.command == 'delete_db':
31-
drop_db()
32-
33-
print "DB deleted!"
34-
elif args.command == 'seed_db' and args.seedfile:
35-
with open(args.seedfile, 'r') as f:
36-
seed_data = json.loads(f.read())
37-
38-
for item_class in seed_data:
39-
items = seed_data[item_class]
40-
print items
41-
for item in items:
42-
print item
43-
create_sample_db_entry('api/' + item_class, item)
44-
45-
print "\nSample data added to database!"
46-
else:
47-
raise Exception('Invalid command')
27+
parser = argparse.ArgumentParser(
28+
description='Manage this Flask application.')
29+
parser.add_argument(
30+
'command', help='the name of the command you want to run')
31+
parser.add_argument(
32+
'--seedfile', help='the file with data for seeding the database')
33+
args = parser.parse_args()
34+
35+
if args.command == 'create_db':
36+
create_db()
37+
38+
print "DB created!"
39+
elif args.command == 'delete_db':
40+
drop_db()
41+
42+
print "DB deleted!"
43+
elif args.command == 'seed_db' and args.seedfile:
44+
with open(args.seedfile, 'r') as f:
45+
seed_data = json.loads(f.read())
46+
47+
for item_class in seed_data:
48+
items = seed_data[item_class]
49+
print items
50+
for item in items:
51+
print item
52+
create_sample_db_entry('api/' + item_class, item)
53+
54+
print "\nSample data added to database!"
55+
else:
56+
raise Exception('Invalid command')
4857

4958
if __name__ == '__main__':
50-
main()
51-
52-
53-
59+
main()

runserver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
22
from angular_flask import app
33

4+
45
def runserver():
5-
port = int(os.environ.get('PORT', 5000))
6-
app.run(host='0.0.0.0', port=port)
6+
port = int(os.environ.get('PORT', 5000))
7+
app.run(host='0.0.0.0', port=port)
78

89
if __name__ == '__main__':
9-
runserver()
10+
runserver()

0 commit comments

Comments
 (0)