示例#1
0
    form_ajax_refs = {
        'user': (User.username, User.email),
        'tags': (Tag.name, )
    }

    def __init__(self, session):
        # Just call parent class with predefined model.
        super(PostAdmin, self).__init__(Post, session)


class TreeView(sqla.ModelView):
    inline_models = (Tree, )


if __name__ == '__main__':
    # Create admin
    admin = admin.Admin(app, 'Simple Models')

    # Add views
    admin.add_view(UserAdmin(User, db.session))
    admin.add_view(sqla.ModelView(Tag, db.session))
    admin.add_view(PostAdmin(db.session))
    admin.add_view(TreeView(Tree, db.session))

    # Create DB
    db.create_all()

    # Start app
    app.run(debug=True)
示例#2
0
def add_cosmos_admin(flask_app, session):
    adm = admin.Admin(flask_app,
                      'Flask Admin',
                      base_template="admin_layout.html")
    for m in [Execution, Stage, Task, TaskFile]:
        adm.add_view(sqla.ModelView(m, session))
示例#3
0
def register(admin_module):
  admin_module.add_view(sqla.ModelView(auth_models.User, db.session))
示例#4
0
    date = db.Column(db.DateTime)

    user_id = db.Column(db.Integer(), db.ForeignKey(User.id))
    user = db.relationship(User, backref='posts')

    def __unicode__(self):
        return self.title


# Flask views
@app.route('/')
def index():
    return '<a href="/admin/">Click me to get to Admin!</a>'


if __name__ == '__main__':
    # Create admin
    admin = admin.Admin(app, 'Simple Models')

    #admin.locale_selector(get_locale)

    # Add views
    admin.add_view(sqla.ModelView(User, db.session))
    admin.add_view(sqla.ModelView(Post, db.session))

    # Create DB
    db.create_all()

    # Start app
    app.run(debug=True)
示例#5
0
from flask.ext.admin.contrib import sqla

from sample_app.database import db
from sample_app.extensions import admin
from .models import Post

admin.add_view(sqla.ModelView(Post, db.session, 'Post'))
示例#6
0

@app.route('/login', methods=['POST'])
def login():
    username = request.args['username']
    password = request.args['password']
    registered_user = User.query.filter_by(username=username,
                                           password=password).first()
    if registered_user is None:
        resp = jsonify(success=False)
        return resp
    login_user(registered_user, remember=True)
    resp = jsonify(success=True)
    return resp


@app.route('/logout', methods=['POST', 'GET'])
def logout():
    #logout_user()
    resp = jsonify(success=True)
    return resp


if __name__ == '__main__':
    admin = Admin(app, 'OneDir')
    admin.add_view(sqla.ModelView(User, db.session))
    admin.add_view(sqla.ModelView(SavedFile, db.session))
    # app.debug = True
    app.run()
    # app.run(host='0.0.0.0')
示例#7
0
# -*- coding: utf-8 -*-
from ngflaskcurd import admin
from .models import Project
from ngflaskcurd.core.database import dbs
from flask.ext.admin.contrib import sqla

admin.add_view(sqla.ModelView(Project, dbs.session, name=u"网址"))

示例#8
0
    return jsonify(receipts=receipts)


@app.after_request
def close_connection(response):
    db.session.close()
    return response


# Admin stuff
class IngredientAdmin(sqla.ModelView):
    column_searchable_list = ('title', Ingredient.title)


admin = admin.Admin(app, 'Recipe')
admin.add_view(sqla.ModelView(Recipe, db.session))
admin.add_view(sqla.ModelView(EAN, db.session))
admin.add_view(IngredientAdmin(Ingredient, db.session))
admin.add_view(sqla.ModelView(Step, db.session))
admin.add_view(sqla.ModelView(ShoppingList, db.session))
admin.add_view(sqla.ModelView(Inventory, db.session))


class RecipeIngredientsAdmin(sqla.ModelView):
    form_ajax_refs = {
        'ingredient_id':
        QueryAjaxModelLoader('ingredient',
                             db.session,
                             Ingredient,
                             fields=['title'],
                             page_size=10),
示例#9
0
from flask.ext.admin.contrib import sqla

from sample_app.database import db
from sample_app.extensions import admin
from .models import Client, Token

admin.add_view(sqla.ModelView(Client, db.session, 'Client'))
admin.add_view(sqla.ModelView(Token, db.session, 'Token'))
示例#10
0
from flask.ext.admin.contrib import sqla

from sample_app.database import db
from sample_app.extensions import admin
from .models import User

admin.add_view(sqla.ModelView(User, db.session, 'User'))