from os import path
from json import dumps

from flask import Flask, redirect, request
from flask.ext.selfdoc import Autodoc


app = Flask(__name__)
app.debug = True
auto = Autodoc(app)

users = []
posts = []


class User(object):

    def __init__(self, username):
        self.username = username
        users.append(self)
        self.id = users.index(self)

    def __repr__(self):
        return dumps(self.__dict__)


class Post(object):

    def __init__(self, title, content, author):
        self.title = title
        self.content = content
        posts.append(self)
        self.id = posts.index(self)

    def __repr__(self):
        return dumps(self.__dict__)


u = User('acoomans')
Post('First post', 'This is the first awesome post', u)
Post('Second post', 'This is another even more awesome post', u)


@app.route('/')
@app.route('/posts')
@auto.doc(groups=['posts', 'public', 'private'])
def get_posts():
    """Return all posts."""
    return '%s' % posts


@app.route('/post/<int:id>')
@auto.doc(groups=['posts', 'public', 'private'])
def get_post(id):
    """Return the post for the given id."""
    return '%s' % posts[id]


@app.route('/post', methods=["POST"])
@auto.doc(groups=['posts', 'private'],
    form_data=['title', 'content', 'authorid'])
def post_post():
    """Create a new post."""
    authorid = request.form.get('authorid', None)
    Post(request.form['title'],
         request.form['content'],
         users[authorid])
    return redirect("/posts")


@app.route('/users')
@auto.doc(groups=['users', 'public', 'private'])
def get_users():
    """Return all users."""
    return '%s' % users


@app.route('/user/<int:id>')
@auto.doc(groups=['users', 'public', 'private'])
def get_user(id):
    """Return the user for the given id."""
    return '%s' % users[id]


@app.route('/users', methods=['POST'])
@auto.doc(groups=['users', 'private'],
    form_data=['username'])
def post_user(id):
    """Creates a new user."""
    User(request.form['username'])
    redirect('/users')


@app.route('/admin', methods=['GET'])
@auto.doc(groups=['private'])
def admin():
    """Admin interface."""
    return 'Admin interface'


@app.route('/doc/')
@app.route('/doc/public')
def public_doc():
    return auto.html(groups=['public'], title='Blog Documentation with Custom template', template="autodoc_custom.html")


@app.route('/doc/private')
def private_doc():
    return auto.html(groups=['private'], title='Private Documentation with Custom template', template="autodoc_custom.html")


if __name__ == '__main__':
    app.run()

@@ -94,13 +94,9 @@
 lask
-.ext.
+_
 self

Change another import.