Exemple #1
0
def backup_pre_put_single_account(instance_id=None, data=None, **kw):
    if instance_id is None: return
    account = orm.Account.query.filter_by(username=instance_id).first()
    if account is None:
        account = orm.Account(instance_id, None, None, None, 0, 0, None)
        orm.db.session.add(account)
        orm.db.session.commit()
    if data.has_key(restful.ITEM_CODE):
        terminal = orm.Terminal.query.filter_by(
            code=data[restful.ITEM_CODE]).first()
        if terminal is None:
            terminal = orm.Terminal(account.id, data.get(restful.ITEM_OS),
                                    data[restful.ITEM_CODE])
            orm.db.session.add(terminal)
        terminal.account_id = account.id
        terminal.os = data.get(restful.ITEM_OS)
        orm.db.session.commit()
    data.pop(restful.ITEM_CODE, None)
    data.pop(restful.ITEM_OS, None)
Exemple #2
0
def view_account():
    account_id = request.args.get('id')
    q = request.args.get('q')
    if q is not None:
        return redirect(url_for('view_accounts', page=1, q=q))

    form = AccountForm(request.form)

    if request.method == 'POST' and form.validate():
        if form.id.data:
            account = orm.Account.query.get(int(form.id.data))
            account.username = form.telephone.data
            account.name = form.telephone.data
            account.telephone = form.telephone.data
            account.role = 0
            account.flag_telephone = 1 if form.flag_telephone.data else 0
            account.checkcode = form.checkcode.data
            account.source = form.source.data
            account.dtcreate = form.dtcreate.data
            orm.db.session.commit()
        else:
            account = orm.Account(form.telephone.data, '1234',
                                  form.telephone.data, form.telephone.data, 0,
                                  1 if form.flag_telephone.data else 0, '1234',
                                  form.source.data, form.dtcreate.data)
            orm.db.session.add(account)
            orm.db.session.commit()
            form.id.data = account.id

        return redirect(url_for('view_account'))
    elif request.method == 'GET' and account_id:
        form = logic.GetAccountFormById(account_id)
        logic.LoadBasePageInfo('修改用户', '输入并确定', form)
    else:
        logic.LoadBasePageInfo('新建用户', '输入并确定', form)

    if form.id.data:
        account = orm.Account.query.get(int(form.id.data))
        form.account = account

    return render_template('view_account.html', form=form)