@mod.route('/<container>/edit', methods=['POST', 'GET'])
@if_logged_in()
def edit(container=None):
    """
    edit containers page and actions if form post request
    """
    host_memory = lwp.host_memory_usage()
    cfg = lwp.get_container_settings(container)

    if request.method == 'POST':
        form = request.form.copy()

        if form['bucket'] != get_bucket_token(container):
            g.db.execute("INSERT INTO machine(machine_name, bucket_token) VALUES (?, ?)", [container, form['bucket']])
            g.db.commit()
            flash(u'Bucket config for %s saved' % container, 'success')

        # convert boolean in correct value for lxc, if checkbox is inset value is not submitted inside POST
        form['flags'] = 'up' if 'flags' in form else 'down'
        form['start_auto'] = '1' if form in 'start_auto' else '0'

        # if memlimits/memswlimit is at max values unset form values
        if int(form['memlimit']) == host_memory['total']:
            form['memlimit'] = ''
        if int(form['swlimit']) == host_memory['total'] * 2:
            form['swlimit'] = ''

        for option in form.keys():
            # if the key is supported AND is different
            if option in cfg.keys() and form[option] != cfg[option]:
                # validate value with regex
                if re.match(cgroup_ext[option][1], form[option]):
                    lwp.push_config_value(cgroup_ext[option][0], form[option], container=container)
                    flash(cgroup_ext[option][2], 'success')
                else:
                    flash('Cannot validate value for option {}. Unsaved!'.format(option), 'error')

        # we should re-read container configuration now to be coherent with the newly saved values
        cfg = lwp.get_container_settings(container)

    info = lxc.info(container)
    infos = {'status': info['state'], 'pid': info['pid'], 'memusg': lwp.memory_usage(container)}

    # prepare a regex dict from cgroups_ext definition
    regex = {}
    for k, v in cgroup_ext.items():
        regex[k] = v[1]

    return render_template('edit.html', containers=lxc.ls(), container=container, infos=infos,
                           settings=cfg, host_memory=host_memory, storage_repos=storage_repos, regex=regex,
                           clonable_containers=lxc.listx()['STOPPED'])
dataset/ETHPy150Open claudyus/LXC-Web-Panel/lwp/views/main.py/edit/swapped operands of `in`