def post(self, request, *args, **kwargs): request_data = request.data.get('data', {}) validator = CreateDepartmentValidator(data=request_data) if not validator.is_valid(): return Response(console_response(code=1, msg=validator.errors)) name = validator.validated_data.get('name') description = validator.validated_data.get('description') parent_department_id = validator.validated_data.get( 'parent_department_id') department = DepartmentService.create(name, description, parent_department_id) ret_set = DepartmentService.to_dict(department) return Response(console_response(ret_set=ret_set))
def post(self, request, *args, **kwargs): request_data = request.data.get('data', {}) validator = DescribeDepartmentMemberValidator(data=request_data) if not validator.is_valid(): return Response(console_response(code=1, msg=validator.errors)) department_id = validator.validated_data.get('department_id') page_num = validator.validated_data.get('page_num') page_size = validator.validated_data.get('page_size') members = DepartmentService.get_members(department_id) paged_data = paging(members, page_num, page_size) page_num = paged_data['page_num'] page_size = paged_data['page_size'] total_page = paged_data['total_page'] total_item = paged_data['total_item'] member_list = [] for member in paged_data['data']: member_list.append(DepartmentMemberService.to_dict(member)) ret_set = dict(page_num=page_num, page_size=page_size, total_page=total_page, total_item=total_item, member_list=member_list) return Response(console_response(ret_set=ret_set))
def handle(self, request, gid=None, members=None): usernames, department_ids = split_username_and_department_id(members) group = PermissionGroupService.get(gid) members = list(AccountService.get_by_usernames(usernames)) for department_id in department_ids: members.extend(DepartmentService.get_members(department_id)) return PermissionGroupService.update_users(group=group, users=members)
def post(self, request, *args, **kwargs): request_data = request.data.get('data', {}) validator = RemoveDepartmentValidator(data=request_data) if not validator.is_valid(): return Response(console_response(code=1, msg=validator.errors)) department_id = validator.validated_data.get('department_id') ret_set = DepartmentService.remove(department_id) return Response(console_response(ret_set=ret_set))
def handle(self, *args, **options): result = DepartmentService.remove_all() if not result: logger.error('init failed') return for department_info in ROOT_DEPARTMENT: self.create_root_department(department_info) print 'import department: %s(%s) done !' % ( department_info['department_name'], department_info['department_id']) accounts = Account.objects.filter(type=AccountType.TENANT, deleted=False) members = [account.user for account in accounts] DepartmentMemberService.join(members, 'dep-00000002') accounts = Account.objects.filter(type=AccountType.HANKOU, deleted=False) members = [account.user for account in accounts] DepartmentMemberService.join(members, 'dep-00000001')
def create_msg(payload): title = payload.get('title') content = payload.get('content') notice_list = payload.get('notice_list') username = payload.get('author') departments = [] users = [] for name in notice_list: if DepartmentService.is_department_exist(name): departments.append(name) elif User.objects.filter(username=name).exists(): users.append(name) msg, excep = NoticeModel.objects.create(title, content, departments, users, username) if excep is None: return console_response() else: error_mag = "消息保存失败" return console_response(code=1, msg=error_mag)
def list_top_four_msg(payload): username = payload.get('username') msgs = NoticeModel.objects.all().order_by('commit_time').reverse() result = [] i = 0 # fix me for msg in msgs: if i > 3: break user = User.objects.get(username=username) if (user in msg.users.all()) or (username == msg.author): result.append(msg) i += 1 else: for department in msg.departments.all(): if user in DepartmentService.get_members( department.department_id): i += 1 result.append(msg) break data = DescribeNoticeSerializer(result, many=True).data return console_response(total_count=len(result), ret_set=data)
def handle(self, *args, **options): company_name = raw_input('Create Department:\nInput company name: ') if 'clear' == options.get('clear').lower(): result = DepartmentService.remove_all() if not result: logger.error('clear failed') return department = Department(name=company_name, description=gen_description(), department_id=FIRST_DEPARTMENT_ID, path=FIRST_DEPARTMENT_ID, level=0) department.save() department.parent_department = department department.save() else: Department.objects.filter( department_id=FIRST_DEPARTMENT_ID).update(name=company_name) accounts = Account.objects.filter(deleted=False).exclude( name='system_image') members = [account.user for account in accounts] DepartmentMemberService.join(members, FIRST_DEPARTMENT_ID)