Beispiel #1
0
 def post(self):
     '''
     添加菜单
     '''
     args = parse_base.parse_args()
     pid = args.get('pid')
     name = args.get('name')
     url = args.get('url')
     icon = args.get('icon')
     sort = args.get('sort')
     _data = Menu.query.filter_by(name = name,is_del = '0').first()
     if _data:
         abort(RET.Forbidden,msg='菜单已存在')
     model_data = Menu()
     model_data.pid = pid
     model_data.name = name
     model_data.url = url
     model_data.icon = icon
     model_data.sort = sort
     model_data.last_editor = g.admin.username
     if model_data.add():
         data = {
                 'status':RET.Created,
                 'msg':'添加成功',
                 'data':model_data
         }
         return marshal(data,sing_fields)
     abort(RET.BadRequest,msg='添加失败,请重试')
Beispiel #2
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
Beispiel #3
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')