コード例 #1
0
ファイル: views.py プロジェクト: drichner/docklr
def config(id=None):
    print id
    action='/frm/config'
    if request.method == 'GET' and not id:
        # just get the new form for adding
        form = ConfigForm()
        method='POST'
        template_name='frm-config.html'
        return render_template(template_name, form=form, action=action,method=method,id=id)
    if request.method == 'GET' and id:
        # get the config
        conf = Config.query.get(id)
        form = ConfigForm()
        form.process(obj=conf)
        action+="/%s" % id
        method='POST'
        template_name='frm-config.html'
        return render_template(template_name, form=form, action=action,method=method,id=id)
    if request.method == 'POST' and not id:
        # new record
        conf=Config()
        form = ConfigForm(request.form)
        form.populate_obj(conf)
        db.session.add(conf)
        db.session.commit()
        return json.dumps({'status': 'OK','cluster': conf.dict})

    if request.method == 'POST' and id:
        conf=Config.query.get(id)
        form = ConfigForm(request.form)
        form.populate_obj(conf)
        db.session.add(conf)
        db.session.commit()
        return json.dumps({'status': 'OK','cluster': conf.dict})
コード例 #2
0
ファイル: views.py プロジェクト: movermeyer/docklr
def config(id=None):
    print id
    action = '/frm/config'
    if request.method == 'GET' and not id:
        # just get the new form for adding
        form = ConfigForm()
        method = 'POST'
        template_name = 'frm-config.html'
        return render_template(template_name,
                               form=form,
                               action=action,
                               method=method,
                               id=id)
    if request.method == 'GET' and id:
        # get the config
        conf = Config.query.get(id)
        form = ConfigForm()
        form.process(obj=conf)
        action += "/%s" % id
        method = 'POST'
        template_name = 'frm-config.html'
        return render_template(template_name,
                               form=form,
                               action=action,
                               method=method,
                               id=id)
    if request.method == 'POST' and not id:
        # new record
        conf = Config()
        form = ConfigForm(request.form)
        form.populate_obj(conf)
        db.session.add(conf)
        db.session.commit()
        return json.dumps({'status': 'OK', 'cluster': conf.dict})

    if request.method == 'POST' and id:
        conf = Config.query.get(id)
        form = ConfigForm(request.form)
        form.populate_obj(conf)
        db.session.add(conf)
        db.session.commit()
        return json.dumps({'status': 'OK', 'cluster': conf.dict})