def common_edit(DynamicModel, form, view):
    id = request.args.get('id', '')
    if id:
        # 查询
        model = DynamicModel.get(DynamicModel.id == id)
        if request.method == 'GET':
            utils.model_to_form(model, form)
        # 修改
        if request.method == 'POST':
            if form.validate_on_submit():
                utils.form_to_model(form, model)
                model.save()
                flash('修改成功')
            else:
                utils.flash_errors(form)
    else:
        # 新增
        if form.validate_on_submit():
            model = DynamicModel()
            utils.form_to_model(form, model)
            model.save()
            flash('保存成功')
        else:
            utils.flash_errors(form)
    return render_template(view, form=form, current_user=current_user)
Exemple #2
0
def common_edit(DynamicModel, form, view):
    id = request.args.get('id', '')
    if id:
        # 查询
        model = DynamicModel.get(DynamicModel.id == id)
        if request.method == 'GET':
            utils.model_to_form(model, form)
        # 修改
        if request.method == 'POST':
            # if form.validate_on_submit():
            utils.form_to_model(form, model)
            model.password = generate_password_hash(model.password)
            model.save()
            # flash('修改成功')
            return render_template('auth/respond.json', state='success')
        # else:
        #utils.flash_errors(form)

    else:
        # 新增
        # if form.validate_on_submit():
        if request.method == 'POST':
            model = DynamicModel()
            utils.form_to_model(form, model)
            model.password = generate_password_hash(model.password)
            model.save()
            return render_template('auth/respond.json', state='success')
            # flash('保存成功')
        # else:
        #     utils.flash_errors(form)
    return render_template(view, form=form, current_user=current_user, id=id)
Exemple #3
0
def common_edit(DynamicModel, form, view):
    id = request.args.get('id', '')
    if id:
        # Inquire
        model = DynamicModel.get(DynamicModel.id == id)
        if request.method == 'GET':
            utils.model_to_form(model, form)
        # Modify
        if request.method == 'POST':
            if form.validate_on_submit():
                utils.form_to_model(form, model)
                model.save()
                flash('Successfully Modified', 'success')
            else:
                utils.flash_errors(form)
    else:
        # Add
        if form.validate_on_submit():
            model = DynamicModel()
            utils.form_to_model(form, model)
            model.save()
            flash('Save Successfully', 'success')
        else:
            utils.flash_errors(form)
    return render_template(view, form=form, current_user=current_user)
def common_edit(DynamicModel, form, view):
    id = request.args.get('id', '')
    if id:
        # 查询
        model = DynamicModel.get(DynamicModel.id == id)
        if request.method == 'GET':
            utils.model_to_form(model, form)
        # 修改
        if request.method == 'POST':
            if form.validate_on_submit():
                utils.form_to_model(form, model)
                model.save()
                flash('修改成功')
            else:
                utils.flash_errors(form)
    else:
        # 新增
        if form.validate_on_submit():
            model = DynamicModel()
            utils.form_to_model(form, model)
            model.save()
            flash('保存成功')
        else:
            utils.flash_errors(form)
    return render_template(view, form=form, current_user=current_user)
Exemple #5
0
def common_edit(DynamicModel, form, view):
    id = request.args.get('id', '')
    if id:
        # 查询
        model = DynamicModel.get(DynamicModel.id == id)
        if request.method == 'GET':
            utils.model_to_form(model, form)
        # 修改
        if request.method == 'POST':
            if form.validate_on_submit():
                utils.form_to_model(form, model)
                model.save()
                flash('修改成功')
            else:
                utils.flash_errors(form)
    else:
        # 新增
        if form.validate_on_submit():
            model = DynamicModel()

            utils.form_to_model(form, model)

            if model.account_money != "":

                model.account_USD = round(
                    float(model.account_money) * change_rate("CNY", "USD"), 3)
                model.account_BYN = round(
                    float(model.account_money) * change_rate("CNY", "BYN"), 3)

            elif model.account_USD != "":
                model.account_money = round(
                    float(model.account_USD) * change_rate("USD", "CNY"), 3)
                model.account_BYN = round(
                    float(model.account_USD) * change_rate("USD", "BYN"), 3)
            elif model.account_BYN != "":
                model.account_USD = round(
                    float(model.account_BYN) * change_rate("BYN", "USD"), 3)
                model.account_money = round(
                    float(model.account_BYN) * change_rate("BYN", "CNY"), 3)

            model.save()
            flash('保存成功')
        else:
            utils.flash_errors(form)

    return render_template(view, form=form, current_user=current_user)