diff --git a/api/urls.py b/api/urls.py index 5686743f..a4c76faa 100644 --- a/api/urls.py +++ b/api/urls.py @@ -8,7 +8,8 @@ path("tasks//duplicate", views.duplicate_task), path("tasks/", views.task_detail), path("tasks", views.tasks_list), - path("tasks/all", views.tasks_list_all), + path("task-list", views.tasks_list_all), + path("task-list/", views.tasks_list_all), path("submits/", views.create_submit), path("info", views.info), path("classes", views.class_detail_list), diff --git a/api/views.py b/api/views.py index 53b973e0..be10721c 100644 --- a/api/views.py +++ b/api/views.py @@ -57,25 +57,34 @@ def tasks_list(request): return JsonResponse({"tasks": result}) -def tasks_list_all(request: HttpRequest): +@user_passes_test(is_teacher) +def tasks_list_all(request: HttpRequest, subject_abbr: str | None = None): result = [] filters = {} count = None start = None - order = ["-created_at", "-id"] + orderBy = "created_at" + sort = "desc" - if "subject" in request.GET: - filters["subject__abbr"] = request.GET["subject"] + if subject_abbr is not None: + filters["subject__abbr"] = subject_abbr if "count" in request.GET: count = int(request.GET["count"]) if "start" in request.GET: start = int(request.GET["start"]) + if "order_column" in request.GET: + if request.GET["order_column"] in ("created_at", "name"): + orderBy = request.GET["order_column"] if "sort" in request.GET: if request.GET["sort"] == "asc": - order = ["created_at", "id"] - else: - order = ["-created_at", "-id"] + sort = "asc" + + if sort != "desc": + order = (orderBy, "id") + else: + order = (f"-{orderBy}", "-id") + if "search" in request.GET: filters["name__icontains"] = request.GET["search"] @@ -99,6 +108,7 @@ def tasks_list_all(request: HttpRequest): { "id": task.pk, "title": task.name, + "path": task.code, "subject": task.subject.abbr, "date": task.created_at, }