code now follows the PEP8 standard
This commit is contained in:
+3
-1
@@ -4,17 +4,19 @@ from flask_sqlalchemy import SQLAlchemy
|
||||
app = Flask(__name__)
|
||||
app.config.from_object('config')
|
||||
|
||||
|
||||
def on_404(e):
|
||||
return jsonify(dict(error='Not found')), 404
|
||||
|
||||
app.errorhandler(404)(on_404)
|
||||
|
||||
#SQLAlchemy
|
||||
# SQLAlchemy
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
from api.views import designers
|
||||
app.register_blueprint(designers.mod)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
data = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from api import db
|
||||
|
||||
|
||||
class Designer(db.Model):
|
||||
__tablename__ = 'designers'
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from api import db
|
||||
|
||||
|
||||
class Locale(db.Model):
|
||||
__tablename__ = 'locales'
|
||||
|
||||
|
||||
@@ -4,11 +4,13 @@ from api.models import Designer
|
||||
|
||||
mod = Blueprint('designers', __name__, url_prefix='/designers')
|
||||
|
||||
|
||||
@mod.route("/", methods=["GET"])
|
||||
def list():
|
||||
designers = Designer.query.all()
|
||||
return jsonify(designers=[d.to_json() for d in designers])
|
||||
|
||||
|
||||
@mod.route("/", methods=["POST"])
|
||||
def create():
|
||||
data = request.json
|
||||
@@ -23,6 +25,7 @@ def show(id):
|
||||
designer = Designer.query.get_or_404(id)
|
||||
return jsonify(designer.to_json())
|
||||
|
||||
|
||||
@mod.route("/<id>", methods=["PUT"])
|
||||
def update(id):
|
||||
designer = Designer.query.get_or_404(id)
|
||||
@@ -33,6 +36,7 @@ def update(id):
|
||||
db.session.commit()
|
||||
return jsonify(designer.to_json())
|
||||
|
||||
|
||||
@mod.route("/<id>", methods=["DELETE"])
|
||||
def delete(id):
|
||||
designer = Designer.query.get_or_404(id)
|
||||
|
||||
@@ -4,17 +4,20 @@ from api.models import Designer
|
||||
|
||||
manager = Manager(app)
|
||||
|
||||
|
||||
@manager.command
|
||||
def init_db():
|
||||
db.create_all()
|
||||
print("All tables created")
|
||||
|
||||
|
||||
@manager.command
|
||||
def drop_db():
|
||||
if prompt_bool("Are you sure you want to lose all your data?"):
|
||||
db.drop_all()
|
||||
print("All tables dropped")
|
||||
|
||||
|
||||
@manager.command
|
||||
def seed_db():
|
||||
print("Adding sample data")
|
||||
|
||||
Reference in New Issue
Block a user