Source

flask-actions / examples / example / manage.py

Full commit
#!/usr/bin/env python2
# -*- encoding:utf-8 -*-

from flask import Flask
from flaskext.actions import Manager
import settings
from example import create_app,db

app = create_app(settings)
manager = Manager(app)

@manager.register('init_db')
def init_db(app):
    def action():
        """
        init database
        """
        ctx = app.test_request_context()
        ctx.push()
        db.create_all()
        ctx.pop()
    return action

@manager.register('create_user')
def create_user(app):
    def action(username=('u','testuser'),password=('p','123456')):
        """
        create user
        """
        from example.models import User
        ctx = app.test_request_context()
        ctx.push()
        user = User(username,password)
        db.session.add(user)
        db.session.commit()
        ctx.pop()
    return action


if __name__ == "__main__":
    manager.run()