Skip to content

Commit

Permalink
Resolve issues
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick11514 committed Oct 7, 2024
1 parent d64616a commit bfe0090
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
path("tasks/<int:task_id>/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/<subject_abbr>", views.tasks_list_all),
path("submits/<int:task_assignment>", views.create_submit),
path("info", views.info),
path("classes", views.class_detail_list),
Expand Down
24 changes: 17 additions & 7 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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,
}
Expand Down

0 comments on commit bfe0090

Please sign in to comment.