コード例 #1
0
def admin_add():
    form = AdminAddForm(request.form)
    roles = Role.query.all()
    if request.method == 'POST' and form.validate():
        with db.auto_commit():
            admin = Admin()
            admin.set_attr(form.data)
            admin.is_super = AdminTypeEnum.NO_SUPER
            db.session.add(admin)
            Oplog('添加管理员:' + admin.name)
            flash('添加管理员成功~', 'ok')
            return redirect(url_for('admin.admin_add'))
    return render_template('admin/admin_add.html', form=form, roles=roles)
コード例 #2
0
import uuid

from app import create_app
from app.libs.enum import AdminTypeEnum
from app.models.admin import Admin
from app.models.base import db
from app.models.user import User

app = create_app()
with app.app_context():
    with db.auto_commit():
        # 创建一个超级管理员
        admin_exists = Admin.query.filter_by(name='admin').first()
        if not admin_exists:
            admin = Admin()
            admin.name = 'admin'
            admin.pwd = 'admin'
            admin.is_super = AdminTypeEnum.IS_SUPER
            db.session.add(admin)
    for v in range(1, 4):
        with db.auto_commit():
            user = User()
            user.name = 'fanm' + str(v)
            user.pwd = '123456'
            user.email = 'fanm' + str(v) + '@gmail.com'
            user.phone = '1234567891' + str(v)
            user.info = 'happy'
            user.face = 'avatar/' + str(v) + '.jpg'
            user.uuid = str(uuid.uuid4().hex)
            db.session.add(user)