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:
Jarret Raim 2013-02-16 19:10:11 -06:00
parent 315544175f
commit aa6cb5932c
5 changed files with 34 additions and 3 deletions

4
.gitignore vendored
View File

@ -36,3 +36,7 @@ nosetests.xml
# Pycharm # Pycharm
.idea .idea
# Sqlite databases
*.sqlite3
*.db

View File

@ -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()

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Barbican API Barbican API
~~~~~~ ~~~~~~~~~~~~
The API for Barbican. The API for Barbican.

View File

View File

@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
</head>
<body>
<div>
{% block body %}{% endblock %}
</div>
</body>
</html>