def settings_measurement(): """Display measurement settings.""" if not utils_general.user_has_permission('view_settings'): return redirect(url_for('routes_general.home')) measurement = Measurement.query.all() unit = Unit.query.all() conversion = Conversion.query.all() form_add_measurement = forms_settings.MeasurementAdd() form_mod_measurement = forms_settings.MeasurementMod() form_add_unit = forms_settings.UnitAdd() form_mod_unit = forms_settings.UnitMod() form_add_conversion = forms_settings.ConversionAdd() form_mod_conversion = forms_settings.ConversionMod() choices_units = utils_general.choices_units(unit) # Generate all measurement and units used dict_measurements = add_custom_measurements(measurement) dict_units = add_custom_units(unit) if request.method == 'POST': if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_general.home')) if form_add_measurement.add_measurement.data: utils_settings.settings_measurement_add(form_add_measurement) elif form_mod_measurement.save_measurement.data: utils_settings.settings_measurement_mod(form_mod_measurement) elif form_mod_measurement.delete_measurement.data: utils_settings.settings_measurement_del( form_mod_measurement.measurement_id.data) elif form_add_unit.add_unit.data: utils_settings.settings_unit_add(form_add_unit) elif form_mod_unit.save_unit.data: utils_settings.settings_unit_mod(form_mod_unit) elif form_mod_unit.delete_unit.data: utils_settings.settings_unit_del(form_mod_unit.unit_id.data) elif form_add_conversion.add_conversion.data: utils_settings.settings_convert_add(form_add_conversion) elif form_mod_conversion.save_conversion.data: utils_settings.settings_convert_mod(form_mod_conversion) elif form_mod_conversion.delete_conversion.data: utils_settings.settings_convert_del( form_mod_conversion.conversion_id.data) return redirect(url_for('routes_settings.settings_measurement')) return render_template('settings/measurement.html', dict_measurements=dict_measurements, dict_units=dict_units, choices_units=choices_units, measurement=measurement, unit=unit, conversion=conversion, form_add_measurement=form_add_measurement, form_mod_measurement=form_mod_measurement, form_add_unit=form_add_unit, form_mod_unit=form_mod_unit, form_add_conversion=form_add_conversion, form_mod_conversion=form_mod_conversion)
def page_input(): """ Display Data page options """ input_type = request.args.get('input_type', None) input_id = request.args.get('input_id', None) each_input = None if input_type in ['entry', 'options']: each_input = Input.query.filter(Input.unique_id == input_id).first() function = CustomController.query.all() input_dev = Input.query.all() input_channel = InputChannel.query.all() math = Math.query.all() method = Method.query.all() measurement = Measurement.query.all() output = Output.query.all() output_channel = OutputChannel.query.all() pid = PID.query.all() user = User.query.all() unit = Unit.query.all() display_order_input = csv_to_list_of_str(DisplayOrder.query.first().inputs) display_order_math = csv_to_list_of_str(DisplayOrder.query.first().math) form_add_input = forms_input.InputAdd() form_mod_input = forms_input.InputMod() form_mod_math = forms_math.MathMod() form_mod_math_measurement = forms_math.MathMeasurementMod() form_mod_average_single = forms_math.MathModAverageSingle() form_mod_sum_single = forms_math.MathModSumSingle() form_mod_redundancy = forms_math.MathModRedundancy() form_mod_difference = forms_math.MathModDifference() form_mod_equation = forms_math.MathModEquation() form_mod_humidity = forms_math.MathModHumidity() form_mod_verification = forms_math.MathModVerification() form_mod_misc = forms_math.MathModMisc() dict_inputs = parse_input_information() if request.method == 'POST': # TODO: Remove entire POST section and remove Math controllers if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_input.page_input')) # Mod Math Measurement if form_mod_math_measurement.math_measurement_mod.data: utils_math.math_measurement_mod(form_mod_math_measurement) # Mod other Math settings elif form_mod_math.math_mod.data: math_type = Math.query.filter( Math.unique_id == form_mod_math.math_id.data).first().math_type if math_type == 'humidity': utils_math.math_mod(form_mod_math, form_mod_humidity) elif math_type == 'average_single': utils_math.math_mod(form_mod_math, form_mod_average_single) elif math_type == 'sum_single': utils_math.math_mod(form_mod_math, form_mod_sum_single) elif math_type == 'redundancy': utils_math.math_mod(form_mod_math, form_mod_redundancy) elif math_type == 'difference': utils_math.math_mod(form_mod_math, form_mod_difference) elif math_type == 'equation': utils_math.math_mod(form_mod_math, form_mod_equation) elif math_type == 'verification': utils_math.math_mod(form_mod_math, form_mod_verification) elif math_type == 'vapor_pressure_deficit': utils_math.math_mod(form_mod_math, form_mod_misc) else: utils_math.math_mod(form_mod_math) elif form_mod_math.math_delete.data: utils_math.math_del(form_mod_math) elif form_mod_math.math_order_up.data: utils_math.math_reorder(form_mod_math.math_id.data, display_order_math, 'up') elif form_mod_math.math_order_down.data: utils_math.math_reorder(form_mod_math.math_id.data, display_order_math, 'down') elif form_mod_math.math_activate.data: utils_math.math_activate(form_mod_math) elif form_mod_math.math_deactivate.data: utils_math.math_deactivate(form_mod_math) return redirect(url_for('routes_input.page_input')) custom_options_values_inputs = parse_custom_option_values( input_dev, dict_controller=dict_inputs) custom_options_values_input_channels = parse_custom_option_values_input_channels_json( input_channel, dict_controller=dict_inputs, key_name='custom_channel_options') custom_actions = {} for each_input in input_dev: if 'custom_actions' in dict_inputs[each_input.device]: custom_actions[each_input.device] = True # Generate dict that incorporate user-added measurements/units dict_outputs = parse_output_information() dict_units = add_custom_units(unit) dict_measurements = add_custom_measurements(measurement) # Create list of choices to be used in dropdown menus choices_function = utils_general.choices_functions(function, dict_units, dict_measurements) choices_input = utils_general.choices_inputs(input_dev, dict_units, dict_measurements) choices_math = utils_general.choices_maths(math, dict_units, dict_measurements) choices_method = utils_general.choices_methods(method) choices_output = utils_general.choices_outputs(output, dict_units, dict_measurements) choices_output_channels = utils_general.choices_outputs_channels( output, output_channel, dict_outputs) choices_output_channels_measurements = utils_general.choices_outputs_channels_measurements( output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_pid = utils_general.choices_pids(pid, dict_units, dict_measurements) choices_pid_devices = utils_general.choices_pids_devices(pid) choices_unit = utils_general.choices_units(unit) choices_measurement = utils_general.choices_measurements(measurement) choices_measurements_units = utils_general.choices_measurements_units( measurement, unit) # Create dict of Input names names_input = {} all_elements = input_dev for each_element in all_elements: names_input[ each_element.unique_id] = '[{id:02d}] ({uid}) {name}'.format( id=each_element.id, uid=each_element.unique_id.split('-')[0], name=each_element.name) # Create dict of Math names names_math = {} all_elements = math for each_element in all_elements: names_math[ each_element.unique_id] = '[{id:02d}] ({uid}) {name}'.format( id=each_element.id, uid=each_element.unique_id.split('-')[0], name=each_element.name) # Create list of file names from the math_options directory # Used in generating the correct options for each math controller math_templates = [] math_path = os.path.join( INSTALL_DIRECTORY, 'mycodo/mycodo_flask/templates/pages/data_options/math_options') for (_, _, file_names) in os.walk(math_path): math_templates.extend(file_names) break # Create list of file names from the input_options directory # Used in generating the correct options for each input controller input_templates = [] input_path = os.path.join( INSTALL_DIRECTORY, 'mycodo/mycodo_flask/templates/pages/data_options/input_options') for (_, _, file_names) in os.walk(input_path): input_templates.extend(file_names) break # If DS18B20 inputs added, compile a list of detected inputs devices_1wire_w1thermsensor = [] if os.path.isdir(PATH_1WIRE): for each_name in os.listdir(PATH_1WIRE): if 'bus' not in each_name and '-' in each_name: devices_1wire_w1thermsensor.append({ 'name': each_name, 'value': each_name.split('-')[1] }) # Add 1-wire devices from ow-shell (if installed) devices_1wire_ow_shell = [] if current_app.config['TESTING']: logger.debug("Testing: Skipping testing for 'ow-shell'") elif not dpkg_package_exists('ow-shell'): logger.debug("Package 'ow-shell' not found") else: logger.debug("Package 'ow-shell' found") try: test_cmd = subprocess.check_output(['owdir']).splitlines() for each_ow in test_cmd: str_ow = re.sub("\ |\/|\'", "", each_ow.decode("utf-8")) # Strip / and ' if '.' in str_ow and len(str_ow) == 15: devices_1wire_ow_shell.append(str_ow) except Exception: logger.error("Error finding 1-wire devices with 'owdir'") # Find FTDI devices ftdi_devices = [] if not current_app.config['TESTING']: for each_input in input_dev: if each_input.interface == "FTDI": from mycodo.devices.atlas_scientific_ftdi import get_ftdi_device_list ftdi_devices = get_ftdi_device_list() break if not input_type: return render_template( 'pages/input.html', and_=and_, choices_function=choices_function, choices_input=choices_input, choices_math=choices_math, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_actions=custom_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels= custom_options_values_input_channels, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, display_order_math=display_order_math, form_add_input=form_add_input, form_mod_input=form_mod_input, form_mod_average_single=form_mod_average_single, form_mod_sum_single=form_mod_sum_single, form_mod_redundancy=form_mod_redundancy, form_mod_difference=form_mod_difference, form_mod_equation=form_mod_equation, form_mod_humidity=form_mod_humidity, form_mod_math=form_mod_math, form_mod_math_measurement=form_mod_math_measurement, form_mod_verification=form_mod_verification, form_mod_misc=form_mod_misc, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, math_info=MATH_INFO, math_templates=math_templates, names_input=names_input, names_math=names_math, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_math=Math, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire_w1thermsensor=devices_1wire_w1thermsensor) elif input_type == 'entry': return render_template( 'pages/data_options/input_entry.html', and_=and_, choices_function=choices_function, choices_input=choices_input, choices_math=choices_math, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_actions=custom_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels= custom_options_values_input_channels, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, display_order_math=display_order_math, each_input=each_input, form_add_input=form_add_input, form_mod_input=form_mod_input, form_mod_average_single=form_mod_average_single, form_mod_sum_single=form_mod_sum_single, form_mod_redundancy=form_mod_redundancy, form_mod_difference=form_mod_difference, form_mod_equation=form_mod_equation, form_mod_humidity=form_mod_humidity, form_mod_math=form_mod_math, form_mod_math_measurement=form_mod_math_measurement, form_mod_verification=form_mod_verification, form_mod_misc=form_mod_misc, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, math_info=MATH_INFO, math_templates=math_templates, names_input=names_input, names_math=names_math, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_math=Math, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire_w1thermsensor=devices_1wire_w1thermsensor) elif input_type == 'options': return render_template( 'pages/data_options/input_options.html', and_=and_, choices_function=choices_function, choices_input=choices_input, choices_math=choices_math, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_actions=custom_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels= custom_options_values_input_channels, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, display_order_math=display_order_math, each_input=each_input, form_add_input=form_add_input, form_mod_input=form_mod_input, form_mod_average_single=form_mod_average_single, form_mod_sum_single=form_mod_sum_single, form_mod_redundancy=form_mod_redundancy, form_mod_difference=form_mod_difference, form_mod_equation=form_mod_equation, form_mod_humidity=form_mod_humidity, form_mod_math=form_mod_math, form_mod_math_measurement=form_mod_math_measurement, form_mod_verification=form_mod_verification, form_mod_misc=form_mod_misc, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, math_info=MATH_INFO, math_templates=math_templates, names_input=names_input, names_math=names_math, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_math=Math, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire_w1thermsensor=devices_1wire_w1thermsensor)
def page_input(): """Display Data page options.""" input_type = request.args.get('input_type', None) input_id = request.args.get('input_id', None) action_id = request.args.get('action_id', None) each_input = None each_action = None if input_type in ['entry', 'options', 'actions']: each_input = Input.query.filter(Input.unique_id == input_id).first() if input_type == 'actions' and action_id: each_action = Actions.query.filter( Actions.unique_id == action_id).first() action = Actions.query.all() function = CustomController.query.all() input_dev = Input.query.all() input_channel = InputChannel.query.all() method = Method.query.all() measurement = Measurement.query.all() output = Output.query.all() output_channel = OutputChannel.query.all() pid = PID.query.all() user = User.query.all() unit = Unit.query.all() display_order_input = csv_to_list_of_str(DisplayOrder.query.first().inputs) form_add_input = forms_input.InputAdd() form_mod_input = forms_input.InputMod() form_actions = forms_action.Actions() dict_inputs = parse_input_information() dict_actions = parse_action_information() custom_options_values_inputs = parse_custom_option_values( input_dev, dict_controller=dict_inputs) custom_options_values_input_channels = parse_custom_option_values_input_channels_json( input_channel, dict_controller=dict_inputs, key_name='custom_channel_options') custom_options_values_actions = {} for each_action_dev in action: try: custom_options_values_actions[each_action_dev.unique_id] = json.loads(each_action_dev.custom_options) except: custom_options_values_actions[each_action_dev.unique_id] = {} custom_commands = {} for each_input_dev in input_dev: if each_input_dev.device in dict_inputs and 'custom_commands' in dict_inputs[each_input_dev.device]: custom_commands[each_input_dev.device] = True # Generate dict that incorporate user-added measurements/units dict_outputs = parse_output_information() dict_units = add_custom_units(unit) dict_measurements = add_custom_measurements(measurement) # Generate Action dropdown for use with Inputs choices_actions = [] list_actions_sorted = generate_form_action_list(dict_actions, application=["inputs"]) for name in list_actions_sorted: choices_actions.append((name, dict_actions[name]['name'])) # Create list of choices to be used in dropdown menus choices_function = utils_general.choices_functions( function, dict_units, dict_measurements) choices_input = utils_general.choices_inputs( input_dev, dict_units, dict_measurements) choices_method = utils_general.choices_methods(method) choices_output = utils_general.choices_outputs( output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_output_channels = utils_general.choices_outputs_channels( output, output_channel, dict_outputs) choices_output_channels_measurements = utils_general.choices_outputs_channels_measurements( output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_pid = utils_general.choices_pids( pid, dict_units, dict_measurements) choices_pid_devices = utils_general.choices_pids_devices(pid) choices_unit = utils_general.choices_units(unit) choices_measurement = utils_general.choices_measurements(measurement) choices_measurements_units = utils_general.choices_measurements_units(measurement, unit) # Create dict of Input names names_input = {} all_elements = input_dev for each_element in all_elements: names_input[each_element.unique_id] = '[{id:02d}] ({uid}) {name}'.format( id=each_element.id, uid=each_element.unique_id.split('-')[0], name=each_element.name) # Create list of file names from the input_options directory # Used in generating the correct options for each input controller input_templates = [] input_path = os.path.join( INSTALL_DIRECTORY, 'mycodo/mycodo_flask/templates/pages/data_options/input_options') for (_, _, file_names) in os.walk(input_path): input_templates.extend(file_names) break # Compile a list of 1-wire devices devices_1wire = [] if os.path.isdir(PATH_1WIRE): for each_name in os.listdir(PATH_1WIRE): if 'bus' not in each_name and '-' in each_name: devices_1wire.append( {'name': each_name, 'value': each_name.split('-')[1]} ) # Compile a list of 1-wire devices (using ow-shell) devices_1wire_ow_shell = [] if not Input.query.filter(Input.device == "DS18B20_OWS").count(): pass elif current_app.config['TESTING']: logger.debug("Testing: Skipping testing for 'ow-shell'") elif not dpkg_package_exists('ow-shell'): logger.debug("Package 'ow-shell' not found") else: logger.debug("Package 'ow-shell' found") try: test_cmd = subprocess.check_output(['owdir']).splitlines() for each_ow in test_cmd: str_ow = re.sub("\ |\/|\'", "", each_ow.decode("utf-8")) # Strip / and ' if '.' in str_ow and len(str_ow) == 15: devices_1wire_ow_shell.append(str_ow) except Exception: logger.error("Error finding 1-wire devices with 'owdir'") # Find FTDI devices ftdi_devices = [] if not current_app.config['TESTING']: for each_input_dev in input_dev: if each_input_dev.interface == "FTDI": from mycodo.devices.atlas_scientific_ftdi import get_ftdi_device_list ftdi_devices = get_ftdi_device_list() break if not input_type: return render_template('pages/input.html', and_=and_, action=action, choices_actions=choices_actions, choices_function=choices_function, choices_input=choices_input, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels=custom_options_values_input_channels, dict_actions=dict_actions, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, form_actions=form_actions, form_add_input=form_add_input, form_mod_input=form_mod_input, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, names_input=names_input, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire=devices_1wire) elif input_type == 'entry': return render_template('pages/data_options/input_entry.html', and_=and_, action=action, choices_actions=choices_actions, choices_function=choices_function, choices_input=choices_input, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels=custom_options_values_input_channels, dict_actions=dict_actions, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, each_input=each_input, form_actions=form_actions, form_add_input=form_add_input, form_mod_input=form_mod_input, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, names_input=names_input, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire=devices_1wire) elif input_type == 'options': return render_template('pages/data_options/input_options.html', and_=and_, action=action, choices_actions=choices_actions, choices_function=choices_function, choices_input=choices_input, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels=custom_options_values_input_channels, dict_actions=dict_actions, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, each_input=each_input, form_actions=form_actions, form_add_input=form_add_input, form_mod_input=form_mod_input, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, names_input=names_input, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire=devices_1wire) elif input_type == 'actions': return render_template('pages/actions.html', and_=and_, action=action, choices_actions=choices_actions, choices_function=choices_function, choices_input=choices_input, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels=custom_options_values_input_channels, dict_actions=dict_actions, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, each_action=each_action, each_input=each_input, form_actions=form_actions, form_add_input=form_add_input, form_mod_input=form_mod_input, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, names_input=names_input, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire=devices_1wire)
def settings_measurement(): """ Display measurement settings """ if not utils_general.user_has_permission('view_settings'): return redirect(url_for('routes_general.home')) measurement = Measurement.query.all() unit = Unit.query.all() conversion = Conversion.query.all() form_add_measurement = forms_settings.MeasurementAdd() form_mod_measurement = forms_settings.MeasurementMod() form_add_unit = forms_settings.UnitAdd() form_mod_unit = forms_settings.UnitMod() form_add_conversion = forms_settings.ConversionAdd() form_mod_conversion = forms_settings.ConversionMod() choices_units = utils_general.choices_units(unit) # Generate all measurement and units used dict_measurements = add_custom_measurements(measurement) dict_units = add_custom_units(unit) if request.method == 'POST': if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_general.home')) if form_add_measurement.add_measurement.data: utils_settings.settings_measurement_add(form_add_measurement) elif form_mod_measurement.save_measurement.data: utils_settings.settings_measurement_mod(form_mod_measurement) elif form_mod_measurement.delete_measurement.data: utils_settings.settings_measurement_del(form_mod_measurement.measurement_id.data) elif form_add_unit.add_unit.data: utils_settings.settings_unit_add(form_add_unit) elif form_mod_unit.save_unit.data: utils_settings.settings_unit_mod(form_mod_unit) elif form_mod_unit.delete_unit.data: utils_settings.settings_unit_del(form_mod_unit.unit_id.data) elif form_add_conversion.add_conversion.data: utils_settings.settings_convert_add(form_add_conversion) elif form_mod_conversion.save_conversion.data: utils_settings.settings_convert_mod(form_mod_conversion) elif form_mod_conversion.delete_conversion.data: utils_settings.settings_convert_del(form_mod_conversion.conversion_id.data) return redirect(url_for('routes_settings.settings_measurement')) return render_template('settings/measurement.html', dict_measurements=dict_measurements, dict_units=dict_units, choices_units=choices_units, measurement=measurement, unit=unit, conversion=conversion, form_add_measurement=form_add_measurement, form_mod_measurement=form_mod_measurement, form_add_unit=form_add_unit, form_mod_unit=form_mod_unit, form_add_conversion=form_add_conversion, form_mod_conversion=form_mod_conversion)