This commit is contained in:
Kenneth Reitz
2013-09-26 17:57:46 -04:00
parent b115a83def
commit 5ba5f7dacb
2 changed files with 25 additions and 11 deletions
+21 -11
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from flask import Flask
from flask import Flask, abort, jsonify, g
from dynamodb_mapper.model import DynamoDBModel, ConnectionBorg
from .models import User, Document, Content
@@ -12,17 +12,27 @@ def hello():
return 'Hello World!'
@app.before_request
def before_request():
"""Opens the connection to DynamoDB."""
g.dynamo_conn = ConnectionBorg()
# @app.before_request
# def before_request():
# """Opens the connection to DynamoDB."""
# g.dynamo_conn = ConnectionBorg()
@app.teardown_request
def teardown_request(exception):
"""Closes the connection to DynamoDB."""
db = getattr(g, 'dynamo_conn', None)
if db is not None:
db.close()
@app.route('/<path:slug>')
def get_document(slug):
doc = Document.get(slug)
document = {
'slug': doc.slug,
'owner': doc.owner,
'text': doc.text,
'content': doc.content,
'history': doc.revisions,
}
return jsonify(document=document)
getattr
if __name__ == '__main__':
+4
View File
@@ -18,6 +18,10 @@ class User(DynamoDBModel):
self.email = email
self.set_password(password)
# profile = Document()
# profile.slug = self.username
# profile.
def __repr__(self):
return '<User %r>' % self.username