Api doc base

This commit is contained in:
Ruud
2012-02-21 17:16:02 +01:00
parent adc755dbd5
commit 7df24643ac
11 changed files with 280 additions and 22 deletions
+15 -6
View File
@@ -1,21 +1,30 @@
from couchpotato.core.helpers.request import jsonified
from flask.blueprints import Blueprint
from flask.templating import render_template
api = Blueprint('api', __name__)
api_docs = {}
api_docs_missing = []
def addApiView(route, func, static = False):
api.add_url_rule(route + ('' if static else '/'), endpoint = route.replace('.', '-') if route else 'index', view_func = func)
def addApiView(route, func, static = False, docs = None):
api.add_url_rule(route + ('' if static else '/'), endpoint = route.replace('.', '::') if route else 'index', view_func = func)
if docs:
api_docs[route[4:] if route[0:4] == 'api.' else route] = docs
else:
api_docs_missing.append(route)
""" Api view """
def index():
from couchpotato import app
from couchpotato import app
routes = []
for route, x in sorted(app.view_functions.iteritems()):
if route[0:4] == 'api.':
routes += [route[4:]]
routes += [route[4:].replace('::', '.')]
return jsonified({'routes': routes})
if api_docs.get(''):
del api_docs['']
del api_docs_missing['']
return render_template('api.html', routes = sorted(routes), api_docs = api_docs, api_docs_missing = sorted(api_docs_missing))
addApiView('', index)
addApiView('default', index)