mirror of
https://github.com/kennethreitz-archive/fallib-service.git
synced 2026-06-05 23:30:19 +00:00
g
This commit is contained in:
+21
-11
@@ -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__':
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user