コード例 #1
0
def get_user_api_view(request):
    user = request.user
    data = {'ok': False}
    if request.user.is_authenticated:

        try:
            profile = Profile.objects.get(user=user, removed=False)
            birthday = arrow.get(
                profile.birth_day).replace(tzinfo=settings.TIME_ZONE).datetime

            data = {
                'ok': True,
                'username': user.username,
                'avatar': build_absolute_url(user.profile.get_avatar_url()),
                'userId': user.id,
                'permission': profile.get_role(),
                'fullName': profile.full_name,
                'birthDay': birthday,
                'idNumber': profile.id_number,
                'address': profile.address,
                'sex': profile.get_sex_display(),
            }
        except Profile.DoesNotExist:
            pass
    return Response(data)
コード例 #2
0
def get_my_profile_info_in_department(request):
    """
    API lấy thông tin của tôi trong một phòng ban
    :param request:
    :return:
    """
    if request.user.is_authenticated:
        user = request.user
        try:
            profile = Profile.objects.get(user=user, removed=False)
            member = DepartmentMember.objects.get(department_member=profile,
                                                  removed=False)
            return Response({
                'userId':
                member.department_member.user.id,
                'profileId':
                member.department_member.id,
                'fullName':
                member.department_member.full_name,
                'sex':
                member.department_member.get_sex(),
                'birthDay':
                member.department_member.get_birth_day(),
                'idNumber':
                member.department_member.id_number,
                'email':
                member.department_member.user.email,
                'address':
                member.department_member.address,
                'avatarUrl':
                build_absolute_url(member.department_member.get_avatar_url()),
                'position':
                member.position,
                'isLeader':
                member.is_leader,
                'department':
                member.department.department_name,
            })

        except (Profile.DoesNotExist, DepartmentMember.DoesNotExist):
            return Response({})
    return Response({})
コード例 #3
0
def get_one_task_detail_of_me_api_view(request):
    """
    API lấy thông tin chi tiết một task của tôi
    :param request: task_id
    :return:
    """
    if request.user.is_authenticated:
        user_id = request.user.id
        task_id = request.GET.get('task_id')
        if task_id:
            if not can_be_integer(task_id):
                return Response({})

            try:
                profile = Profile.objects.get(user__id=user_id, removed=False)
                member = DepartmentMember.objects.get(
                    department_member=profile, removed=False)
                task = Task.objects.get(id=task_id, user=member, removed=False)
                # taskDesc = markdown2.markdown(task.task_description,
                #                               extras=["tables",
                #                                       "fenced-code-blocks",
                #                                       'code-friendly']) if task.task_description else None
                return Response({
                    'userId':
                    task.user.department_member.user.id,
                    'fullName':
                    task.user.department_member.full_name,
                    'avatarUrl':
                    build_absolute_url(
                        task.user.department_member.get_avatar_url()),
                    'sex':
                    task.user.department_member.get_sex(),
                    'position':
                    task.user.position,
                    'department':
                    task.user.department.department_name,
                    'tagId':
                    task.tag.id,
                    'taskId':
                    task.pk,
                    'taskName':
                    task.task_name,
                    'taskDescription':
                    task.task_description,
                    # 'taskDescEdit': task.task_description,
                    'periodStart':
                    task.period_start,
                    'periodEnd':
                    task.period_end,
                    'unitOfMeasure':
                    task.unit_of_measure,
                    'targetValue':
                    task.target_value,
                    'resultValue':
                    task.result_value,
                    'progress':
                    task.progress,
                    'weight':
                    task.weight,
                    'taskState':
                    task.get_state(),
                    'isFinished':
                    task.is_finished,
                    'createdAt':
                    task.created_at,
                    'updatedAt':
                    task.updated_at,
                })

            except (Profile.DoesNotExist, DepartmentMember.DoesNotExist,
                    Task.DoesNotExist):
                return Response({})

        return Response({})
コード例 #4
0
 def get_avatarUrl(obj):
     return build_absolute_url(obj.department_member.get_avatar_url()
                               ) if obj.department_member else None
コード例 #5
0
 def get_avatarUrl(obj):
     member = DepartmentMember.objects.get(department=obj,
                                           is_leader=True,
                                           removed=False)
     return build_absolute_url(member.department_member.get_avatar_url()
                               ) if member.department_member else None
コード例 #6
0
 def get_avatarUrl(obj):
     return build_absolute_url(
         obj.user.get_avatar_url()) if obj.user else None
コード例 #7
0
 def get_createdAvatarUrl(obj):
     return build_absolute_url(
         obj.created_by.get_avatar_url()) if obj.created_by else None
コード例 #8
0
def get_profile_info_specific_in_department(request):
    """
    API lấy thông tin cơ bản của một nhân viên
    :param request:
    :return:
    """
    if request.user.is_authenticated:
        pern = request.user.profile.get_role()
        user_id = request.GET.get('user_id')
        if not user_id:
            return Response({})
        if not can_be_integer(user_id):
            return Response({})
        try:
            if pern == 'Director':
                profile = Profile.objects.get(user__id=user_id, removed=False)
                member = DepartmentMember.objects.get(
                    department_member=profile, removed=False)
                return Response({
                    'userId':
                    member.department_member.user.id,
                    'profileId':
                    member.department_member.id,
                    'fullName':
                    member.department_member.full_name,
                    'sex':
                    member.department_member.get_sex(),
                    'avatarUrl':
                    build_absolute_url(
                        member.department_member.get_avatar_url()),
                    'position':
                    member.position,
                    'departmentId':
                    member.department.id,
                    'department':
                    member.department.department_name,
                })
            elif pern == 'Manager':
                profile = Profile.objects.get(user__id=user_id, removed=False)
                my_profile = Profile.objects.get(user__id=request.user.id,
                                                 removed=False)

                me = DepartmentMember.objects.get(department_member=my_profile,
                                                  removed=False)
                member = DepartmentMember.objects.get(
                    department_member=profile, removed=False)
                if int(me.department.id) == int(member.department.id):
                    return Response({
                        'userId':
                        member.department_member.user.id,
                        'profileId':
                        member.department_member.id,
                        'fullName':
                        member.department_member.full_name,
                        'sex':
                        member.department_member.get_sex(),
                        'avatarUrl':
                        build_absolute_url(
                            member.department_member.get_avatar_url()),
                        'position':
                        member.position,
                        'departmentId':
                        member.department.id,
                        'department':
                        member.department.department_name,
                    })
                else:
                    return Response({})
            else:
                return Response({})

        except (Profile.DoesNotExist, DepartmentMember.DoesNotExist):
            return Response({})
    return Response({})