Ejemplo n.º 1
0
def page_lcd():
    """ Display LCD output settings """
    if not logged_in():
        return redirect(url_for('general_routes.home'))

    lcd = db_retrieve_table(
        current_app.config['MYCODO_DB_PATH'], LCD, entry='all')
    pid = 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').lcd
    if display_order_unsplit:
        display_order = display_order_unsplit.split(",")
    else:
        display_order = []

    form_activate_lcd = flaskforms.ActivateLCD()
    form_add_lcd = flaskforms.AddLCD()
    form_deactivate_lcd = flaskforms.DeactivateLCD()
    form_del_lcd = flaskforms.DelLCD()
    form_mod_lcd = flaskforms.ModLCD()
    form_order_lcd = flaskforms.OrderLCD()
    form_reset_flashing_lcd = flaskforms.ResetFlashingLCD()

    if request.method == 'POST':
        form_name = request.form['form-name']
        if form_name == 'orderLCD':
            flaskutils.lcd_reorder(form_order_lcd, display_order)
        elif form_name == 'addLCD':
            flaskutils.lcd_add(form_add_lcd, display_order)
        elif form_name == 'modLCD':
            flaskutils.lcd_mod(form_mod_lcd)
        elif form_name == 'delLCD':
            flaskutils.lcd_del(form_del_lcd, display_order)
        elif form_name == 'activateLCD':
            flaskutils.lcd_activate(form_activate_lcd)
        elif form_name == 'deactivateLCD':
            flaskutils.lcd_deactivate(form_deactivate_lcd)
        elif form_name == 'resetFlashingLCD':
            flaskutils.lcd_reset_flashing(form_reset_flashing_lcd)
        return redirect('/lcd')

    return render_template('pages/lcd.html',
                           lcd=lcd,
                           pid=pid,
                           relay=relay,
                           sensor=sensor,
                           displayOrder=display_order,
                           form_order_lcd=form_order_lcd,
                           form_add_lcd=form_add_lcd,
                           form_mod_lcd=form_mod_lcd,
                           form_del_lcd=form_del_lcd,
                           form_activate_lcd=form_activate_lcd,
                           form_deactivate_lcd=form_deactivate_lcd,
                           form_reset_flashing_lcd=form_reset_flashing_lcd)
Ejemplo n.º 2
0
def page_lcd():
    """ Display LCD output settings """
    lcd = LCD.query.all()
    pid = PID.query.all()
    relay = Relay.query.all()
    sensor = Sensor.query.all()

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

    form_add_lcd = flaskforms.LCDAdd()
    form_mod_lcd = flaskforms.LCDMod()

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

        if form_add_lcd.add.data:
            flaskutils.lcd_add(form_add_lcd.quantity.data)
        elif form_mod_lcd.save.data:
            flaskutils.lcd_mod(form_mod_lcd)
        elif form_mod_lcd.delete.data:
            flaskutils.lcd_del(form_mod_lcd.lcd_id.data)
        elif form_mod_lcd.reorder_up.data:
            flaskutils.lcd_reorder(form_mod_lcd.lcd_id.data, display_order,
                                   'up')
        elif form_mod_lcd.reorder_down.data:
            flaskutils.lcd_reorder(form_mod_lcd.lcd_id.data, display_order,
                                   'down')
        elif form_mod_lcd.activate.data:
            flaskutils.lcd_activate(form_mod_lcd.lcd_id.data)
        elif form_mod_lcd.deactivate.data:
            flaskutils.lcd_deactivate(form_mod_lcd.lcd_id.data)
        elif form_mod_lcd.reset_flashing.data:
            flaskutils.lcd_reset_flashing(form_mod_lcd.lcd_id.data)
        return redirect('/lcd')

    return render_template('pages/lcd.html',
                           lcd=lcd,
                           measurements=MEASUREMENTS,
                           pid=pid,
                           relay=relay,
                           sensor=sensor,
                           displayOrder=display_order,
                           form_add_lcd=form_add_lcd,
                           form_mod_lcd=form_mod_lcd)