Adding SQLAlchemy persistence
Basic structure for SQLAlchemy and models. Uses a hardcoded DB location which should be moved to a standard configuration.
This commit is contained in:
parent
315544175f
commit
aa6cb5932c
4
.gitignore
vendored
4
.gitignore
vendored
@ -36,3 +36,7 @@ nosetests.xml
|
|||||||
|
|
||||||
# Pycharm
|
# Pycharm
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
# Sqlite databases
|
||||||
|
*.sqlite3
|
||||||
|
*.db
|
||||||
|
21
barbican.py
21
barbican.py
@ -12,12 +12,16 @@
|
|||||||
:copyright: (c) 2013 by Jarret Raim
|
:copyright: (c) 2013 by Jarret Raim
|
||||||
:license: Apache 2.0, see LICENSE for details
|
:license: Apache 2.0, see LICENSE for details
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
from flask import Flask
|
from flask import Flask, render_template
|
||||||
from barbican_api import api
|
from barbican_api import api
|
||||||
|
from database import db_session, init_db
|
||||||
|
from models import User
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.register_blueprint(api)
|
app.register_blueprint(api)
|
||||||
|
app.config['DEBUG'] = True
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
@ -25,5 +29,18 @@ def hello():
|
|||||||
return "Hello world!"
|
return "Hello world!"
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/users')
|
||||||
|
def users_list():
|
||||||
|
users = User.query.all()
|
||||||
|
return render_template('users.html', users=users)
|
||||||
|
|
||||||
|
|
||||||
|
@app.teardown_request
|
||||||
|
def shutdown_session(exception=None):
|
||||||
|
db_session.remove()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
if not os.path.exists('/tmp/barbican.db'):
|
||||||
|
init_db()
|
||||||
app.run()
|
app.run()
|
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Barbican API
|
Barbican API
|
||||||
~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
The API for Barbican.
|
The API for Barbican.
|
||||||
|
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
{% block body %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user