mirror of
https://github.com/kennethreitz-archive/fallib-service.git
synced 2026-06-05 15:20:17 +00:00
content endpoints
This commit is contained in:
+42
-4
@@ -7,6 +7,12 @@ from .models import User, Document, Content, NotFound
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def get_or_404(cls, key):
|
||||
try:
|
||||
return cls.get(key)
|
||||
except NotFound:
|
||||
abort(404)
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
return 'Hello World!'
|
||||
@@ -19,10 +25,7 @@ def page_not_found(e):
|
||||
@app.route('/<path:slug>')
|
||||
def get_document(slug):
|
||||
|
||||
try:
|
||||
doc = Document.get(slug)
|
||||
except NotFound:
|
||||
abort(404)
|
||||
doc = get_or_404(Document, slug)
|
||||
|
||||
document = {
|
||||
'slug': doc.slug,
|
||||
@@ -34,6 +37,41 @@ def get_document(slug):
|
||||
|
||||
return jsonify(document=document)
|
||||
|
||||
@app.route('/<path:slug>/text')
|
||||
def get_document_text(slug):
|
||||
|
||||
doc = get_or_404(Document, slug)
|
||||
return doc.text
|
||||
|
||||
@app.route('/<path:slug>/html')
|
||||
def get_document_html(slug):
|
||||
|
||||
doc = get_or_404(Document, slug)
|
||||
return doc.html
|
||||
|
||||
@app.route('/content/<hash>')
|
||||
def get_content(hash):
|
||||
|
||||
doc = get_or_404(Content, hash)
|
||||
|
||||
document = {
|
||||
'hash': doc.hash,
|
||||
'text': doc.text,
|
||||
}
|
||||
|
||||
return jsonify(content=document)
|
||||
|
||||
@app.route('/content/<hash>/text')
|
||||
def get_content_text(hash):
|
||||
|
||||
doc = get_or_404(Content, hash)
|
||||
return doc.text
|
||||
|
||||
@app.route('/content/<hash>/html')
|
||||
def get_content_html(hash):
|
||||
|
||||
doc = get_or_404(Content, hash)
|
||||
return doc.html
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
+5
-1
@@ -51,7 +51,7 @@ class Document(DynamoDBModel):
|
||||
|
||||
@property
|
||||
def html(self):
|
||||
return render(self.text)
|
||||
return Content.get(self.content).html
|
||||
|
||||
@property
|
||||
def owner(self):
|
||||
@@ -98,6 +98,10 @@ class Content(DynamoDBModel):
|
||||
u'text': unicode,
|
||||
}
|
||||
|
||||
@property
|
||||
def html(self):
|
||||
return render(self.text)
|
||||
|
||||
@classmethod
|
||||
def store(cls, text):
|
||||
content = cls()
|
||||
|
||||
Reference in New Issue
Block a user