Beispiel #1
0
def automation_edit_controller(controller_name):
    if debug: print 'automation_edit_controller'
    next = get_redirect_target()
    controller = automation.FindController(controller_name)
    if not controller:
        flash("No controller named '" + controller_name + "'")
        return redirect(url_for('automation_controllers'))
    controller_type = controller.Type()
    title = 'Edit Controller - ' + controller.Name()
    error_dict = DefaultDict()
    if request.method == 'POST':
        if 'action' in request.form:
            config_dict = StrippedCopy(request.form)
            param = DefaultDict(config_dict)
            del config_dict['action']
            controller.Validate(config_dict, error_dict)
            if ErrorFound(error_dict):
                return render_template('automation-edit-controller.html', title=title, controller_type=controller_type, next=next, param=param, error=error_dict)
            automation.EditController(controller, config_dict)
            flash('Updated Controller: ' + controller.Name())
        return redirect(url_for('automation_controllers'))
        #return redirect_back('automation_controllers')
    param = controller.GetConfigDict()
    param['action'] = 'Update'
    return render_template('automation-edit-controller.html', title=title, controller_type=controller_type, next=next, param=param, error=error_dict)
Beispiel #2
0
def automation_edit_actuator(actuator_name):
    if debug: print 'automation_edit_actuator'
    next = get_redirect_target()
    actuator = automation.FindActuator(actuator_name)
    if not actuator:
        flash("No actuator named '" + actuator_name + "'")
        return redirect(url_for('automation_actuators'))
    controller = actuator.Controller()
    title='Edit Actuator - ' + actuator.Name()
    error_dict = DefaultDict()
    if request.method == 'POST':
        if 'action' in request.form:
            config_dict = StrippedCopy(request.form)
            param = DefaultDict(config_dict)
            del config_dict['action']
            actuator.Validate(config_dict, error_dict)
            if ErrorFound(error_dict):
                return render_template('automation-edit-actuator.html', title=title, controller=controller, next=next, param=param, error=error_dict)
            automation.EditActuator(actuator, config_dict)
            flash('Updated Actuator ' + actuator.Name())
        return redirect(url_for('automation_actuators'))
    param = actuator.GetConfigDict()
    param['action'] = 'Update'
    return render_template('automation-edit-actuator.html', title=title, controller=controller, next=next, param=param, error=error_dict)
Beispiel #3
0
def automation_add_actuator(controller_name):
    if debug: print 'automation_add_actuator'
    next = get_redirect_target()
    error_dict = DefaultDict()
    config_dict = StrippedCopy(request.form)
    param = DefaultDict(config_dict)
    controller = automation.FindController(controller_name)
    if not controller:
        flash('Unable to find controller named ' + controller_name)
        return redirect_back('automation_actuators')
    title = 'Add Actuator for ' + controller.Name()
    param['action'] = 'Add'
    if request.method == 'POST':
        if 'action' in request.form:
            del config_dict['action']
            controller.ValidateNewActuator(config_dict, error_dict)
            if ErrorFound(error_dict):
                return render_template('automation-edit-actuator.html', title=title, controller=controller, next=next, error=error_dict, param=param)
            actuator = automation.AddActuator(controller, config_dict)
            flash('Added Actuator: ' + actuator.Names())
        return redirect_back('automation_actuators')
    param['Controller'] = controller.Name()
    param['Order'] = automation.NextOrder()
    return render_template('automation-edit-actuator.html', title=title, controller=controller, next=next, error=error_dict, param=param)