Example #1
0
 def get_group_resource(self, group_id):
     '''获取角色的资源信息,编辑界面使用
     '''
     group = Group.objects.get(id=group_id)
     exist_res = {gr.id: '' for gr in group.resources.all()}
     system_list = ResourceService().get_system_list()['list']
     resource_list = []
     for sys in system_list:
         sys_resource = ResourceService().get_all_resource(sys['id'])
         if sys_resource['list']:
             for sr in sys_resource['list']:
                 sr['is_checked'] = 0
                 if sr['id'] in exist_res:
                     sr['is_checked'] = 1
             sys_res_dict = {
                 'system_name': sys['name'],
                 'list': sys_resource['list']
             }
             resource_list.append(sys_res_dict)
     group_json = {
         'statusCode': 1,
         'name': group.name,
         'resource_list': resource_list
     } 
     return group_json
Example #2
0
    def get_menu(self, menu_id):
        '''获取单个菜单
        '''
        menu = Menu.objects.get(id=menu_id)
        system_name = menu.resource.system_id.name
        system_id = menu.resource.system_id.id
        res_list = ResourceService().get_all_resource(system_id)
        for res in res_list['list']:
            res['is_checked'] = 0
            if res['id'] == menu.resource.id:
                res['is_checked'] = 1
        menu_list = self.get_all_menu(system_id)
        for ml in menu_list['list']:
            ml['is_checked'] = 0
            if ml['id'] == int(menu_id):
                ml['is_checked'] = 1

        menu_json = {
            'statusCode': 1,
            'menu': {
                'id': menu_id,
                'name': menu.name,
                'mkey': menu.mkey,
                'url': menu.url,
                'system_name': system_name,
                'resource_list': res_list['list'],
                'menu_list': menu_list,
                'order': menu.order
            }
        }
        return menu_json
Example #3
0
def save(request):
    '''新增或修改资源:
    '''
    try:
        res = ResourceService().save_or_update(request)
    except Exception,e:
        log.error('method save error, error is %s' % e, exc_info=True)
        res = {'statusCode': -1}
Example #4
0
def get_system_list(request):
    '''获取所有子系统
    '''
    try:
        res = ResourceService().get_system_list()
    except Exception,e:
        log.error('method get_system_list error, error is %s' % e, exc_info=True)
        res = {'statusCode': -1}
Example #5
0
def edit(request):
    '''编辑资源,获取单个资源信息
    '''
    try:
        resource_id = request.GET.get('id', '')
        res = ResourceService().get_resource(resource_id)
    except Exception,e:
        log.error('method edit error, error is %s' % e, exc_info=True)
        res = {'statusCode': -1}
Example #6
0
def delete(request):
    '''删除资源
    '''
    try:
        resource_id = request.GET.get('id', '')
        res = ResourceService().delete_resource(resource_id)
    except Exception,e:
        log.error('method delete error, error is %s' % e, exc_info=True)
        res = {'statusCode': -1, 'msg':'程序内部异常,请稍后再试!'}
Example #7
0
def list(request):
    '''显示资源列表
    '''
    try:
        res = ResourceService().pack_resource(request)
    except Exception,e:
        log.error('method list error, error is %s' % e, exc_info=True)
        res = DICT_MAP['COMMON_LIST_JSON'] 
        res['statusCode'] = -1
Example #8
0
def get_all_resource(request):
    '''显示全部资源
    '''
    try:
        system_id = request.GET.get('system_id', '')
        res = ResourceService().get_all_resource(system_id)
    except Exception,e:
        log.error('method get_all_resource error, error is %s' % e, exc_info=True)
        res = {'statusCode': -1}