def top(request, kind, quantity):
"""
Returns top {quantity} list, {kind} (total_score, level, last_month_score, current_month_score, last_year_score,
current_year_score)
---
serializer: employees.serializers.EmployeeTopListSerializer
responseMessages:
- code: 401
message: Unauthorized. Authentication credentials were not provided. Invalid token.
- code: 403
message: Forbidden, authentication credentials were not provided
- code: 404
message: Not found
- code: 500
message: Internal server error, cannot resolve keyword into field.
"""
try:
employee_list_filtered = []
if request.method == 'GET':
employee_list = Employee.objects.filter(is_active=True,
is_base_profile_complete=True).order_by('-' + kind)[:quantity]
if kind == 'total_score':
for employee in employee_list:
if employee.total_score > 0:
employee_list_filtered.append(employee)
serializer = EmployeeTopTotalScoreList(employee_list_filtered, many=True)
elif kind == 'level':
for employee in employee_list:
if employee.level > 0:
employee_list_filtered.append(employee)
serializer = EmployeeTopLevelList(employee_list_filtered, many=True)
elif kind == 'current_month_score':
for employee in employee_list:
if employee.current_month_score > 0:
employee_list_filtered.append(employee)
serializer = EmployeeTopCurrentMonthList(employee_list_filtered, many=True)
elif kind == 'current_year_score':
for employee in employee_list:
if employee.current_year_score > 0:
employee_list_filtered.append(employee)
serializer = EmployeeTopCurrentYearList(employee_list_filtered, many=True)
elif kind == 'last_month_score':
for employee in employee_list:
if employee.last_month_score > 0:
employee_list_filtered.append(employee)
serializer = EmployeeTopLastMonthList(employee_list_filtered, many=True)
elif kind == 'last_year_score':
for employee in employee_list:
if employee.last_year_score > 0:
employee_list_filtered.append(employee)
serializer = EmployeeTopLastYearList(employee_list_filtered, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
raise APIException(e)