Skip to content

Commit

Permalink
modified recent_tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
KunalTiwary committed May 17, 2024
1 parent 99529a4 commit 565487e
Showing 1 changed file with 64 additions and 5 deletions.
69 changes: 64 additions & 5 deletions backend/tasks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,16 +1036,26 @@ def delete_project_tasks(self, request, pk=None):
)
@action(
detail=False,
methods=["POST"],
methods=["GET"],
url_path="annotated_and_reviewed_tasks/get_users_recent_tasks",
url_name="get_users_recent_tasks",
)
def get_users_recent_tasks(self, request):
try:
user_id = request.data.get("user_id")
task_type = request.data.get("task_type", "annotation")
try:
user_id = request.query_params.get("user_id")
user = User.objects.filter(id=user_id)[0]
except Exception as e:
user = request.user

user = User.objects.get(pk=user_id)
task_type = request.query_params.get("task_type", "annotation")
project_id = request.query_params.get("search_Project ID", "")
task_id = request.query_params.get("search_Task ID", "")
updated_at = request.query_params.get("search_Updated at", "")
annotated_at = request.query_params.get("search_Annotated at", "")
created_at = request.query_params.get("search_Created at", "")

error_list = []

annotations = Annotation.objects.filter(completed_by=user)
if task_type == "review":
Expand All @@ -1057,6 +1067,44 @@ def get_users_recent_tasks(self, request):
else:
annotations = annotations.filter(annotation_type=ANNOTATOR_ANNOTATION)

if project_id:
try:
annotations = annotations.filter(task__project_id=project_id)
except Exception as e:
error_list.append(f"Error filtering by Project ID")
pass

if task_id:
try:
annotations = annotations.filter(task__id=task_id)
except Exception as e:
error_list.append(f"Error filtering by Task ID")
pass

if updated_at:
try:
date_obj = datetime.strptime(updated_at, "%d-%m-%Y")
annotations = annotations.filter(updated_at__date=date_obj.date())
except Exception as e:
error_list.append(f"Error filtering by updated at date")
pass

if annotated_at:
try:
date_obj = datetime.strptime(annotated_at, "%d-%m-%Y")
annotations = annotations.filter(annotated_at__date=date_obj.date())
except Exception as e:
error_list.append(f"Error filtering by annotated at date")
pass

if created_at:
try:
date_obj = datetime.strptime(created_at, "%d-%m-%Y")
annotations = annotations.filter(created_at__date=date_obj.date())
except Exception as e:
error_list.append(f"Error filtering by created at date")
pass

annotations = annotations.order_by("-updated_at")
annotations = self.paginate_queryset(annotations)

Expand All @@ -1067,11 +1115,22 @@ def get_users_recent_tasks(self, request):
"Project ID": annotation.task.project_id.id,
"Task ID": annotation.task.id,
"Updated at": utc_to_ist(annotation.updated_at),
"Annotated at": utc_to_ist(annotation.annotated_at)
if annotation.annotated_at
else None,
"Created at": utc_to_ist(annotation.created_at)
if annotation.created_at
else None,
}

response.append(data)
if len(error_list) == 0:
return self.get_paginated_response({"results": response})
else:
return self.get_paginated_response(
{"results": response, "errors": error_list}
)

return self.get_paginated_response(response)
except:
return Response(
{
Expand Down

0 comments on commit 565487e

Please sign in to comment.