Modify some select2 box

This commit is contained in:
cuom1999 2024-02-05 15:15:32 -06:00
parent 847e8b6660
commit 695fa85b19
13 changed files with 50 additions and 31 deletions

View file

@ -664,12 +664,6 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
if self.request.profile:
context["organizations"] = self.request.profile.organizations.all()
all_authors_ids = Problem.objects.values_list("authors", flat=True)
context["all_authors"] = (
Profile.objects.filter(id__in=all_authors_ids)
.select_related("user")
.values("id", "user__username")
)
context["category"] = self.category
context["categories"] = ProblemGroup.objects.all()
if self.show_types:
@ -677,7 +671,7 @@ class ProblemList(QueryStringSortMixin, TitleMixin, SolvedProblemMixin, ListView
context["problem_types"] = ProblemType.objects.all()
context["has_fts"] = settings.ENABLE_FTS
context["org_query"] = self.org_query
context["author_query"] = self.author_query
context["author_query"] = Profile.objects.filter(id__in=self.author_query)
context["search_query"] = self.search_query
context["completed_problem_ids"] = self.get_completed_problems()
context["attempted_problems"] = self.get_attempted_problems()

View file

@ -200,3 +200,17 @@ class ChatUserSearchSelect2View(UserSearchSelect2View):
),
"display_rank": display_rank,
}
class ProblemAuthorSearchSelect2View(UserSearchSelect2View):
def get_queryset(self):
return Profile.objects.filter(
authored_problems__isnull=False, user__username__icontains=self.term
).distinct()
def get_json_result_from_object(self, user_tuple):
pk, username, email, display_rank, profile_image = user_tuple
return {
"text": username,
"id": pk,
}