本文整理汇总了Python中mycodo.mycodo_flask.utils.utils_general.flash_success_errors函数的典型用法代码示例。如果您正苦于以下问题:Python flash_success_errors函数的具体用法?Python flash_success_errors怎么用?Python flash_success_errors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flash_success_errors函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: conditional_activate
def conditional_activate(cond_id):
"""Activate a Conditional"""
error = []
action = '{action} {controller}'.format(
action=TRANSLATIONS['activate']['title'],
controller=TRANSLATIONS['conditional']['title'])
conditions = ConditionalConditions.query.filter(
ConditionalConditions.conditional_id == cond_id).all()
for each_condition in conditions:
# Check for errors in the Conditional settings
error = check_cond_measurements(each_condition, error)
conditions = ConditionalConditions.query.filter(
ConditionalConditions.conditional_id == cond_id)
if not conditions.count():
error.append("No Conditions found: Add at least one Condition before activating.")
actions = Actions.query.filter(
Actions.function_id == cond_id)
if not actions.count():
error.append("No Actions found: Add at least one Action before activating.")
for each_action in actions.all():
error = check_actions(each_action, error)
if not error:
controller_activate_deactivate('activate', 'Conditional', cond_id)
flash_success_errors(error, action, url_for('routes_page.page_function'))
示例2: lcd_mod
def lcd_mod(form_mod_lcd):
action = '{action} {controller}'.format(
action=TRANSLATIONS['modify']['title'],
controller=TRANSLATIONS['lcd']['title'])
error = []
mod_lcd = LCD.query.filter(
LCD.unique_id == form_mod_lcd.lcd_id.data).first()
if mod_lcd.is_activated:
error.append(gettext("Deactivate LCD controller before modifying"
" its settings."))
if not error:
if form_mod_lcd.validate():
try:
mod_lcd.name = form_mod_lcd.name.data
if mod_lcd.lcd_type in ['16x2_generic',
'16x4_generic']:
mod_lcd.location = form_mod_lcd.location.data
mod_lcd.i2c_bus = form_mod_lcd.i2c_bus.data
mod_lcd.period = form_mod_lcd.period.data
db.session.commit()
except Exception as except_msg:
error.append(except_msg)
else:
flash_form_errors(form_mod_lcd)
flash_success_errors(error, action, url_for('routes_page.page_lcd'))
示例3: lcd_display_del
def lcd_display_del(lcd_data_id, delete_last=False):
action = '{action} {controller}'.format(
action=TRANSLATIONS['delete']['title'],
controller=TRANSLATIONS['display']['title'])
error = []
lcd_data_this = LCDData.query.filter(
LCDData.unique_id == lcd_data_id).first()
lcd_data_all = LCDData.query.filter(
LCDData.lcd_id == lcd_data_this.lcd_id).all()
lcd = LCD.query.filter(
LCD.unique_id == lcd_data_this.lcd_id).first()
if lcd.is_activated:
error.append(gettext("Deactivate LCD controller before modifying"
" its settings"))
if not delete_last and len(lcd_data_all) < 2:
error.append(gettext("The last display cannot be deleted"))
if not error:
try:
delete_entry_with_id(LCDData,
lcd_data_id)
db.session.commit()
except Exception as except_msg:
error.append(except_msg)
flash_success_errors(error, action, url_for('routes_page.page_lcd'))
示例4: file_del
def file_del(form):
action = '{action} {controller}'.format(
action=TRANSLATIONS['delete']['title'],
controller=gettext("File"))
error = []
if not form.note_unique_id.data:
error.append("Unique id is empty")
mod_note = Notes.query.filter(
Notes.unique_id == form.note_unique_id.data).first()
files_list = mod_note.files.split(",")
if form.file_selected.data in files_list:
try:
files_list.remove(form.file_selected.data)
except:
error.append("Could not remove file from note")
if mod_note.files:
try:
full_file_path = os.path.join(PATH_NOTE_ATTACHMENTS, form.file_selected.data)
os.remove(full_file_path)
except:
error.append("Could not remove file from filesystem")
if not error:
mod_note.files = ",".join(files_list)
db.session.commit()
flash_success_errors(error, action, url_for('routes_page.page_notes'))
示例5: conditional_condition_add
def conditional_condition_add(form):
"""Add a Conditional Condition"""
error = []
action = '{action} {controller}'.format(
action=TRANSLATIONS['add']['title'],
controller='{} {}'.format(TRANSLATIONS['conditional']['title'],
gettext("Condition")))
cond = Conditional.query.filter(
Conditional.unique_id == form.function_id.data).first()
if cond.is_activated:
error.append("Deactivate the Conditional before adding a Condition")
if form.condition_type.data == '':
error.append("Must select a condition")
try:
new_condition = ConditionalConditions()
new_condition.conditional_id = form.function_id.data
new_condition.condition_type = form.condition_type.data
if new_condition.condition_type == 'measurement':
new_condition.max_age = 360
if not error:
new_condition.save()
except sqlalchemy.exc.OperationalError as except_msg:
error.append(except_msg)
except sqlalchemy.exc.IntegrityError as except_msg:
error.append(except_msg)
except Exception as except_msg:
error.append(except_msg)
flash_success_errors(error, action, url_for('routes_page.page_function'))
示例6: lcd_add
def lcd_add(form):
action = '{action} {controller}'.format(
action=TRANSLATIONS['add']['title'],
controller=TRANSLATIONS['lcd']['title'])
error = []
if current_app.config['TESTING']:
dep_unmet = False
else:
dep_unmet, _ = return_dependencies(form.lcd_type.data)
if dep_unmet:
list_unmet_deps = []
for each_dep in dep_unmet:
list_unmet_deps.append(each_dep[0])
error.append("The {dev} device you're trying to add has unmet dependencies: {dep}".format(
dev=form.lcd_type.data, dep=', '.join(list_unmet_deps)))
try:
new_lcd = LCD()
new_lcd_data = LCDData()
if GPIO.RPI_REVISION == 2 or GPIO.RPI_REVISION == 3:
new_lcd.i2c_bus = 1
else:
new_lcd.i2c_bus = 0
new_lcd.lcd_type = form.lcd_type.data
new_lcd.name = str(LCD_INFO[form.lcd_type.data]['name'])
if form.lcd_type.data == '128x32_pioled':
new_lcd.location = '0x3c'
new_lcd.x_characters = 21
new_lcd.y_lines = 4
elif form.lcd_type.data == '128x64_pioled':
new_lcd.location = '0x3c'
new_lcd.x_characters = 21
new_lcd.y_lines = 8
elif form.lcd_type.data == '16x2_generic':
new_lcd.location = '0x27'
new_lcd.x_characters = 16
new_lcd.y_lines = 2
elif form.lcd_type.data == '16x4_generic':
new_lcd.location = '0x27'
new_lcd.x_characters = 16
new_lcd.y_lines = 4
if not error:
new_lcd.save()
new_lcd_data.lcd_id = new_lcd.unique_id
new_lcd_data.save()
display_order = csv_to_list_of_str(DisplayOrder.query.first().lcd)
DisplayOrder.query.first().lcd = add_display_order(
display_order, new_lcd.unique_id)
db.session.commit()
except sqlalchemy.exc.OperationalError as except_msg:
error.append(except_msg)
except sqlalchemy.exc.IntegrityError as except_msg:
error.append(except_msg)
flash_success_errors(error, action, url_for('routes_page.page_lcd'))
if dep_unmet:
return 1
示例7: action_del
def action_del(form):
"""Delete a Conditional Action"""
error = []
action = '{action} {controller}'.format(
action=TRANSLATIONS['delete']['title'],
controller='{} {}'.format(TRANSLATIONS['conditional']['title'], TRANSLATIONS['actions']['title']))
conditional = Conditional.query.filter(
Conditional.unique_id == form.function_id.data).first()
trigger = Trigger.query.filter(
Trigger.unique_id == form.function_id.data).first()
if ((conditional and conditional.is_activated) or
(trigger and trigger.is_activated)):
error.append("Deactivate the Conditional before deleting an Action")
try:
if not error:
function_action_id = Actions.query.filter(
Actions.unique_id == form.function_action_id.data).first().unique_id
delete_entry_with_id(Actions, function_action_id)
except sqlalchemy.exc.OperationalError as except_msg:
error.append(except_msg)
except sqlalchemy.exc.IntegrityError as except_msg:
error.append(except_msg)
except Exception as except_msg:
error.append(except_msg)
flash_success_errors(error, action, url_for('routes_page.page_function'))
示例8: pid_del
def pid_del(pid_id):
action = '{action} {controller}'.format(
action=TRANSLATIONS['delete']['title'],
controller=TRANSLATIONS['pid']['title'])
error = []
try:
pid = PID.query.filter(
PID.unique_id == pid_id).first()
if pid.is_activated:
pid_deactivate(pid_id)
device_measurements = DeviceMeasurements.query.filter(
DeviceMeasurements.device_id == pid_id).all()
for each_measurement in device_measurements:
delete_entry_with_id(DeviceMeasurements, each_measurement.unique_id)
delete_entry_with_id(PID, pid_id)
try:
display_order = csv_to_list_of_str(DisplayOrder.query.first().math)
display_order.remove(pid_id)
DisplayOrder.query.first().function = list_to_csv(display_order)
except Exception: # id not in list
pass
db.session.commit()
except Exception as except_msg:
error.append(except_msg)
flash_success_errors(error, action, url_for('routes_page.page_function'))
示例9: function_del
def function_del(function_id):
"""Delete a Function"""
action = '{action} {controller}'.format(
action=TRANSLATIONS['delete']['title'],
controller=TRANSLATIONS['function']['title'])
error = []
try:
# Delete Actions
actions = Actions.query.filter(
Actions.function_id == function_id).all()
for each_action in actions:
delete_entry_with_id(Actions,
each_action.unique_id)
delete_entry_with_id(Function, function_id)
display_order = csv_to_list_of_str(DisplayOrder.query.first().function)
display_order.remove(function_id)
DisplayOrder.query.first().function = list_to_csv(display_order)
db.session.commit()
except Exception as except_msg:
error.append(except_msg)
flash_success_errors(error, action, url_for('routes_page.page_function'))
示例10: export_influxdb
def export_influxdb(form):
"""
Save the InfluxDB metastore and mycodo_db database to a zip file and serve
it to the user
"""
action = '{action} {controller}'.format(
action=TRANSLATIONS['export']['title'],
controller=TRANSLATIONS['measurement']['title'])
error = []
try:
influx_backup_dir = os.path.join(INSTALL_DIRECTORY, 'influx_backup')
# Delete influxdb directory if it exists
if os.path.isdir(influx_backup_dir):
shutil.rmtree(influx_backup_dir)
# Create new directory (make sure it's empty)
assure_path_exists(influx_backup_dir)
cmd = "/usr/bin/influxd backup -database mycodo_db {path}".format(
path=influx_backup_dir)
_, _, status = cmd_output(cmd)
influxd_version_out, _, _ = cmd_output(
'/usr/bin/influxd version')
if influxd_version_out:
influxd_version = influxd_version_out.decode('utf-8').split(' ')[1]
else:
influxd_version = None
error.append("Could not determine Influxdb version")
if not status and influxd_version:
# Zip all files in the influx_backup directory
data = io.BytesIO()
with zipfile.ZipFile(data, mode='w') as z:
for _, _, files in os.walk(influx_backup_dir):
for filename in files:
z.write(os.path.join(influx_backup_dir, filename),
filename)
data.seek(0)
# Delete influxdb directory if it exists
if os.path.isdir(influx_backup_dir):
shutil.rmtree(influx_backup_dir)
# Send zip file to user
return send_file(
data,
mimetype='application/zip',
as_attachment=True,
attachment_filename='Mycodo_{mv}_Influxdb_{iv}_{host}_{dt}.zip'.format(
mv=MYCODO_VERSION, iv=influxd_version,
host=socket.gethostname().replace(' ', ''),
dt=datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
)
except Exception as err:
error.append("Error: {}".format(err))
flash_success_errors(error, action, url_for('routes_page.page_export'))
示例11: export_measurements
def export_measurements(form):
"""
Take user input to query the InfluxDB and return a CSV file of timestamps
and measurement values
"""
action = '{action} {controller}'.format(
action=TRANSLATIONS['export']['title'],
controller=TRANSLATIONS['measurement']['title'])
error = []
if form.validate():
try:
if not error:
start_time = form.date_range.data.split(' - ')[0]
start_seconds = int(time.mktime(
time.strptime(start_time, '%m/%d/%Y %H:%M')))
end_time = form.date_range.data.split(' - ')[1]
end_seconds = int(time.mktime(
time.strptime(end_time, '%m/%d/%Y %H:%M')))
unique_id = form.measurement.data.split(',')[0]
measurement_id = form.measurement.data.split(',')[1]
url = '/export_data/{id}/{meas}/{start}/{end}'.format(
id=unique_id,
meas=measurement_id,
start=start_seconds, end=end_seconds)
return url
except Exception as err:
error.append("Error: {}".format(err))
else:
flash_form_errors(form)
return
flash_success_errors(error, action, url_for('routes_page.page_export'))
示例12: math_add
def math_add(form_add_math):
action = '{action} {controller}'.format(
action=TRANSLATIONS['add']['title'],
controller=TRANSLATIONS['math']['title'])
error = []
dep_unmet, _ = return_dependencies(form_add_math.math_type.data)
if dep_unmet:
list_unmet_deps = []
for each_dep in dep_unmet:
list_unmet_deps.append(each_dep[0])
error.append("The {dev} device you're trying to add has unmet dependencies: {dep}".format(
dev=form_add_math.math_type.data, dep=', '.join(list_unmet_deps)))
if form_add_math.validate():
new_math = Math()
new_math.name = str(MATH_INFO[form_add_math.math_type.data]['name'])
new_math.math_type = form_add_math.math_type.data
try:
new_math.save()
display_order = csv_to_list_of_str(
DisplayOrder.query.first().math)
DisplayOrder.query.first().math = add_display_order(
display_order, new_math.unique_id)
db.session.commit()
if not MATH_INFO[form_add_math.math_type.data]['measure']:
new_measurement = DeviceMeasurements()
new_measurement.device_id = new_math.unique_id
new_measurement.channel = 0
new_measurement.save()
else:
for each_channel, measure_info in MATH_INFO[form_add_math.math_type.data]['measure'].items():
new_measurement = DeviceMeasurements()
if 'name' in measure_info and measure_info['name']:
new_measurement.name = measure_info['name']
new_measurement.device_id = new_math.unique_id
new_measurement.measurement = measure_info['measurement']
new_measurement.unit = measure_info['unit']
new_measurement.channel = each_channel
new_measurement.save()
flash(gettext(
"%(type)s Math with ID %(id)s (%(uuid)s) successfully added",
type=form_add_math.math_type.data,
id=new_math.id,
uuid=new_math.unique_id),
"success")
except sqlalchemy.exc.OperationalError as except_msg:
error.append(except_msg)
except sqlalchemy.exc.IntegrityError as except_msg:
error.append(except_msg)
flash_success_errors(error, action, url_for('routes_page.page_data'))
else:
flash_form_errors(form_add_math)
if dep_unmet:
return 1
示例13: conditional_condition_del
def conditional_condition_del(form):
"""Delete a Conditional Condition"""
error = []
action = '{action} {controller}'.format(
action=TRANSLATIONS['delete']['title'],
controller='{} {}'.format(TRANSLATIONS['conditional']['title'],
gettext("Condition")))
cond = Conditional.query.filter(
Conditional.unique_id == form.conditional_id.data).first()
if cond.is_activated:
error.append("Deactivate the Conditional before deleting a Condition")
try:
if not error:
cond_condition_id = ConditionalConditions.query.filter(
ConditionalConditions.unique_id == form.conditional_condition_id.data).first().unique_id
delete_entry_with_id(ConditionalConditions, cond_condition_id)
except sqlalchemy.exc.OperationalError as except_msg:
error.append(except_msg)
except sqlalchemy.exc.IntegrityError as except_msg:
error.append(except_msg)
except Exception as except_msg:
error.append(except_msg)
flash_success_errors(error, action, url_for('routes_page.page_function'))
示例14: lcd_activate
def lcd_activate(lcd_id):
action = '{action} {controller}'.format(
action=TRANSLATIONS['activate']['title'],
controller=TRANSLATIONS['lcd']['title'])
error = []
try:
# All display lines must be filled to activate display
lcd = LCD.query.filter(
LCD.unique_id == lcd_id).first()
lcd_data = LCDData.query.filter(
LCDData.lcd_id == lcd_id).all()
blank_line_detected = False
for each_lcd_data in lcd_data:
if (
(lcd.y_lines in [2, 4] and
(not each_lcd_data.line_1_id or
not each_lcd_data.line_2_id)
) or
(lcd.y_lines == 4 and
(not each_lcd_data.line_3_id or
not each_lcd_data.line_4_id))
):
blank_line_detected = True
if blank_line_detected:
error.append(gettext(
"Cannot activate LCD if there are blank lines"))
if not error:
controller_activate_deactivate('activate', 'LCD', lcd_id)
except Exception as except_msg:
error.append(except_msg)
flash_success_errors(error, action, url_for('routes_page.page_lcd'))
示例15: export_settings
def export_settings(form):
"""
Save the Mycodo settings database (mycodo.db) to a zip file and serve it
to the user
"""
action = '{action} {controller}'.format(
action=TRANSLATIONS['export']['title'],
controller=TRANSLATIONS['settings']['title'])
error = []
try:
data = io.BytesIO()
with zipfile.ZipFile(data, mode='w') as z:
z.write(SQL_DATABASE_MYCODO,
os.path.basename(SQL_DATABASE_MYCODO))
data.seek(0)
return send_file(
data,
mimetype='application/zip',
as_attachment=True,
attachment_filename=
'Mycodo_{mver}_Settings_{aver}_{host}_{dt}.zip'.format(
mver=MYCODO_VERSION, aver=ALEMBIC_VERSION,
host=socket.gethostname().replace(' ', ''),
dt=datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
)
except Exception as err:
error.append("Error: {}".format(err))
flash_success_errors(error, action, url_for('routes_page.page_export'))