Add more server APIs

This commit is contained in:
Arne Schlüter 2015-02-07 17:37:27 +01:00
commit 705472c9dc
2 changed files with 26 additions and 4 deletions

View file

@ -1,8 +1,7 @@
import bottle
from json import dumps
from models import *
@bottle.get('/locations/<article_id:int>')
@bottle.get("/locations/<article_id:int>")
def location(article_id):
return (Location
.select()
@ -11,5 +10,26 @@ def location(article_id):
.dicts()
.get())
if __name__ == '__main__':
bottle.run(host='localhost', port=12345, reloader=True, debug=True)
@bottle.get("/categories/<article_id:int>")
def category(article_id):
categories = (Category
.select()
.where(Category.article == article_id))
return {
"article": article_id,
"categories": [c.name for c in categories]
}
@bottle.get("/articles/<article_id:int>")
def article(article_id):
# articles have a datetime field and need special serialization
# return json_util.dumps(Article
# .select()
# .where(Article.id == article_id)
# .dicts()
# .get())
pass
if __name__ == "__main__":
bottle.run(host="localhost", port=12345, reloader=True, debug=True)