Example #1
0
def menu_create(options=None):
    new_menu = Menu()
    new_menu.icon = options['icon']
    new_menu.url = options['url']
    new_menu.name = options['name']
    new_menu.identifier = options['identifier']

    if options['is_hide'] == 1:
        new_menu.is_hide = True
    elif options['is_hide'] == 2:
        new_menu.is_hide = False
    else:
        print('is_hide')
        return False

    if options['is_hide_children'] == 1:
        new_menu.is_hide_children = True
    elif options['is_hide_children'] == 2:
        new_menu.is_hide_children = False
    else:
        print('is_hide_children')
        return False

    # new_menu.is_hide = False
    # new_menu.is_hide_children = False
    new_menu.important = options['important']
    if options['parent_id']:
        parent_menu = db.session.query(Menu).filter_by(id=options['parent_id']).first()
        if parent_menu:
            new_menu.parent_id = options['parent_id']
        else:
            new_menu.parent_id = 0
    else:
        new_menu.parent_id = 0
    try:
        db.session.add(new_menu)
        db.session.commit()
    except Exception, e:
        return False
Example #2
0
def menu_create(icon, url, name, identifier, is_hide, is_hide_children, important, parent_id):
    try:
        new_menu = Menu()
        new_menu.icon = icon
        new_menu.url = url
        new_menu.name = name
        new_menu.identifier = identifier

        if is_hide == 1:
            new_menu.is_hide = True
        elif is_hide == 2:
            new_menu.is_hide = False
        else:
            raise Exception('is_hide_children information is incorrect, 1 is True, 2 is False')

        if is_hide_children == 1:
            new_menu.is_hide_children = True
        elif is_hide_children == 2:
            new_menu.is_hide_children = False
        else:
            raise Exception('is_hide_children information is incorrect, 1 is True, 2 is False')

        new_menu.important = important
        if parent_id:
            parent_menu = db.session.query(Menu).filter_by(id=parent_id).first()
            if parent_menu:
                new_menu.parent_id = parent_id
            else:
                new_menu.parent_id = 0
        else:
            new_menu.parent_id = 0

        db.session.add(new_menu)
        db.session.flush()
        db.session.commit()
        return new_menu.id
    except Exception as e:
        # print(e)
        raise Exception('Database operation exception')