Пример #1
0
def page_pid():
    """ Display PID settings """
    pids = PID.query.all()
    relay = Relay.query.all()
    sensor = Sensor.query.all()

    display_order = csv_to_list_of_int(DisplayOrder.query.first().pid)

    form_add_pid = flaskforms.PIDAdd()
    form_mod_pid = flaskforms.PIDMod()

    method = Method.query.all()

    if request.method == 'POST':
        if not flaskutils.user_has_permission('edit_controllers'):
            return redirect(url_for('general_routes.home'))

        form_name = request.form['form-name']
        if form_name == 'addPID':
            flaskutils.pid_add(form_add_pid)
        elif form_name == 'modPID':
            if form_mod_pid.delete.data:
                flaskutils.pid_del(
                    form_mod_pid.pid_id.data)
            elif form_mod_pid.reorder_up.data:
                flaskutils.pid_reorder(
                    form_mod_pid.pid_id.data, display_order, 'up')
            elif form_mod_pid.reorder_down.data:
                flaskutils.pid_reorder(
                    form_mod_pid.pid_id.data, display_order, 'down')
            elif form_mod_pid.activate.data:
                flaskutils.pid_activate(
                    form_mod_pid.pid_id.data)
            elif form_mod_pid.deactivate.data:
                flaskutils.pid_deactivate(
                    form_mod_pid.pid_id.data)
            elif form_mod_pid.hold.data:
                flaskutils.pid_manipulate(
                    form_mod_pid.pid_id.data, 'Hold')
            elif form_mod_pid.pause.data:
                flaskutils.pid_manipulate(
                    form_mod_pid.pid_id.data, 'Pause')
            elif form_mod_pid.resume.data:
                flaskutils.pid_manipulate(
                    form_mod_pid.pid_id.data, 'Resume')
            else:
                flaskutils.pid_mod(form_mod_pid)

        return redirect('/pid')

    return render_template('pages/pid.html',
                           method=method,
                           pids=pids,
                           relay=relay,
                           sensor=sensor,
                           displayOrder=display_order,
                           form_add_pid=form_add_pid,
                           form_mod_pid=form_mod_pid)
Пример #2
0
def page_pid():
    """ Display PID settings """
    pids = PID.query.all()
    relay = Relay.query.all()
    sensor = Sensor.query.all()

    display_order = csv_to_list_of_int(DisplayOrder.query.first().pid)

    form_add_pid = flaskforms.PIDAdd()
    form_mod_pid_base = flaskforms.PIDModBase()
    form_mod_pid_relay = flaskforms.PIDModRelay()
    form_mod_pid_pwm = flaskforms.PIDModPWM()

    method = Method.query.all()

    # Create list of file names from the pid_options directory
    # Used in generating the correct options for each PID
    pid_templates = []
    pid_path = os.path.join(INSTALL_DIRECTORY,
                            'mycodo/mycodo_flask/templates/pages/pid_options')
    for (_, _, file_names) in os.walk(pid_path):
        pid_templates.extend(file_names)
        break

    if request.method == 'POST':
        if not flaskutils.user_has_permission('edit_controllers'):
            return redirect(url_for('general_routes.home'))

        form_name = request.form['form-name']
        if form_name == 'addPID':
            flaskutils.pid_add(form_add_pid)
        elif form_name == 'modPID':
            if form_mod_pid_base.save.data:
                flaskutils.pid_mod(form_mod_pid_base, form_mod_pid_pwm,
                                   form_mod_pid_relay)
            elif form_mod_pid_base.delete.data:
                flaskutils.pid_del(form_mod_pid_base.pid_id.data)
            elif form_mod_pid_base.reorder_up.data:
                flaskutils.pid_reorder(form_mod_pid_base.pid_id.data,
                                       display_order, 'up')
            elif form_mod_pid_base.reorder_down.data:
                flaskutils.pid_reorder(form_mod_pid_base.pid_id.data,
                                       display_order, 'down')
            elif form_mod_pid_base.activate.data:
                flaskutils.pid_activate(form_mod_pid_base.pid_id.data)
            elif form_mod_pid_base.deactivate.data:
                flaskutils.pid_deactivate(form_mod_pid_base.pid_id.data)
            elif form_mod_pid_base.hold.data:
                flaskutils.pid_manipulate(form_mod_pid_base.pid_id.data,
                                          'Hold')
            elif form_mod_pid_base.pause.data:
                flaskutils.pid_manipulate(form_mod_pid_base.pid_id.data,
                                          'Pause')
            elif form_mod_pid_base.resume.data:
                flaskutils.pid_manipulate(form_mod_pid_base.pid_id.data,
                                          'Resume')

        return redirect('/pid')

    return render_template('pages/pid.html',
                           method=method,
                           pids=pids,
                           pid_templates=pid_templates,
                           relay=relay,
                           sensor=sensor,
                           displayOrder=display_order,
                           form_add_pid=form_add_pid,
                           form_mod_pid_base=form_mod_pid_base,
                           form_mod_pid_pwm=form_mod_pid_pwm,
                           form_mod_pid_relay=form_mod_pid_relay)
Пример #3
0
def page_pid():
    """ Display PID settings """
    if not logged_in():
        return redirect(url_for('general_routes.home'))

    pids = db_retrieve_table(
        current_app.config['MYCODO_DB_PATH'], PID, entry='all')
    relay = db_retrieve_table(
        current_app.config['MYCODO_DB_PATH'], Relay, entry='all')
    sensor = db_retrieve_table(
        current_app.config['MYCODO_DB_PATH'], Sensor, entry='all')

    display_order_unsplit = db_retrieve_table(
        current_app.config['MYCODO_DB_PATH'], DisplayOrder, entry='first').pid
    if display_order_unsplit:
        display_order = display_order_unsplit.split(",")
    else:
        display_order = []

    form_add_pid = flaskforms.AddPID()
    form_mod_pid = flaskforms.ModPID()

    method = db_retrieve_table(
        current_app.config['MYCODO_DB_PATH'], Method)
    method = method.filter(
        Method.method_order == 0).all()

    if request.method == 'POST':
        if session['user_group'] == 'guest':
            flaskutils.deny_guest_user()
            return redirect('/pid')
        form_name = request.form['form-name']
        if form_name == 'addPID':
            flaskutils.pid_add(form_add_pid, display_order)
        elif form_name == 'modPID':
            if form_mod_pid.mod_pid_del.data:
                flaskutils.pid_del(
                    form_mod_pid.modPID_id.data, display_order)
            elif form_mod_pid.mod_pid_order_up.data:
                flaskutils.pid_reorder(
                    form_mod_pid.modPID_id.data, display_order, 'up')
            elif form_mod_pid.mod_pid_order_down.data:
                flaskutils.pid_reorder(
                    form_mod_pid.modPID_id.data, display_order, 'down')
            elif form_mod_pid.mod_pid_activate.data:
                flaskutils.pid_activate(
                    form_mod_pid.modPID_id.data)
            elif form_mod_pid.mod_pid_deactivate.data:
                flaskutils.pid_deactivate(
                    form_mod_pid.modPID_id.data)
            elif form_mod_pid.mod_pid_hold.data:
                flaskutils.pid_manipulate(
                    'Hold', form_mod_pid.modPID_id.data)
            elif form_mod_pid.mod_pid_pause.data:
                flaskutils.pid_manipulate(
                    'Pause', form_mod_pid.modPID_id.data)
            elif form_mod_pid.mod_pid_resume.data:
                flaskutils.pid_manipulate(
                    'Resume', form_mod_pid.modPID_id.data)
            else:
                flaskutils.pid_mod(form_mod_pid)

        return redirect('/pid')

    return render_template('pages/pid.html',
                           method=method,
                           pids=pids,
                           relay=relay,
                           sensor=sensor,
                           displayOrder=display_order,
                           form_add_pid=form_add_pid,
                           form_mod_pid=form_mod_pid)