示例#1
0
def master_update(table_name, id_):
    if request.method == 'GET':
        with Connection() as cn:
            model = table_label_dict[table_name].model
            obj = cn.s.query(model).filter(model.id == id_).one()
            form = MasterForm.generate(model, cn, obj=obj)
        return render_template('master/update.html',
                               form=form,
                               button='update',
                               table_name=table_name)
    if request.method == 'POST':
        with Connection() as cn:
            model = table_label_dict[table_name].model
            obj = cn.s.query(model).filter(model.id == id_).one()
            form = MasterForm.generate(model, cn, obj=obj)
            if not form.validate_on_submit():
                return render_template('master/update.html',
                                       form=form,
                                       button='update',
                                       table_name=table_name)
            cn.upsert_from_form(table_label_dict[table_name].model, form)
        return render_template('master/update.html',
                               form=form,
                               button='update',
                               table_name=table_name)
示例#2
0
def master_show(table_name, id_):
    if request.method == 'GET':
        with Connection() as cn:
            model = table_label_dict[table_name].model
            obj = cn.s.query(model).filter(model.id == id_).one()
            form = MasterForm.generate(model, cn, obj=obj, freeze=True)
        return render_template('master/update.html',
                               form=form,
                               button='',
                               table_name=table_name)
示例#3
0
def master_create(table_name):
    if request.method == 'GET':
        with Connection() as cn:
            form = MasterForm.generate(table_label_dict[table_name].model, cn)
        return render_template('master/update.html',
                               form=form,
                               button='create',
                               table_name=table_name)
    if request.method == 'POST':
        with Connection() as cn:
            form = MasterForm.generate(table_label_dict[table_name].model, cn)
            if not form.validate_on_submit():
                return render_template('master/update.html',
                                       form=form,
                                       button='create',
                                       table_name=table_name)
            cn.upsert_from_form(table_label_dict[table_name].model, form)
        return redirect(
            url_for_ep('controller.master.master_create',
                       table_name=table_name))
示例#4
0
def master_delete(table_name, id_):
    if request.method == 'GET':
        with Connection() as cn:
            model = table_label_dict[table_name].model
            obj = cn.s.query(model).filter(model.id == id_).one()
            form = MasterForm.generate(model, cn, obj=obj, freeze=True)
        return render_template('master/update.html',
                               form=form,
                               button='delete',
                               table_name=table_name)
    if request.method == 'POST':
        with Connection() as cn:
            model = table_label_dict[table_name].model
            cn.s.query(model).filter(model.id == id_).delete(
                synchronize_session=False)
            cn.s.commit()
        return redirect(
            url_for_ep('controller.master.master_list', table_name=table_name))