示例#1
0
def func_add(form_add_func):
    action = '{action} {controller}'.format(
        action=gettext("Add"),
        controller=gettext("Function"))
    error = []

    if form_add_func.validate():
        try:
            if [ur for ur in PIDS if form_add_func.func_type.data == ur[0]]:
                new_func = PID().save()
                if not error:
                    display_order = csv_to_list_of_str(
                        DisplayOrder.query.first().pid)
                    DisplayOrder.query.first().pid = add_display_order(
                        display_order, new_func.unique_id)
                    db.session.commit()
            elif [ur for ur in CONDITIONALS if form_add_func.func_type.data == ur[0]]:
                new_func = Conditional()
                new_func.conditional_type = form_add_func.func_type.data
                new_func.save()
                if not error:
                    display_order = csv_to_list_of_str(
                        DisplayOrder.query.first().conditional)
                    DisplayOrder.query.first().conditional = add_display_order(
                        display_order, new_func.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_function'))
    else:
        flash_form_errors(form_add_func)
示例#2
0
def func_add(form_add_func):
    action = '{action} {controller}'.format(action=gettext("Add"),
                                            controller=gettext("Function"))
    error = []

    if form_add_func.validate():
        try:
            if form_add_func.func_type.data == 'pid':
                new_func = PID().save()
                if not error:
                    display_order = csv_to_list_of_int(
                        DisplayOrder.query.first().pid)
                    DisplayOrder.query.first().pid = add_display_order(
                        display_order, new_func.id)
                    db.session.commit()
            elif form_add_func.func_type.data in [
                    'conditional_measurement', 'conditional_output',
                    'conditional_edge', 'conditional_sunrise_sunset'
            ]:
                new_func = Conditional()
                new_func.conditional_type = form_add_func.func_type.data
                new_func.save()
                if not error:
                    display_order = csv_to_list_of_int(
                        DisplayOrder.query.first().conditional)
                    DisplayOrder.query.first().conditional = add_display_order(
                        display_order, new_func.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_function'))
    else:
        flash_form_errors(form_add_func)