Beispiel #1
0
    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))
Beispiel #2
0
 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)
Beispiel #3
0
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)