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

@ -84,6 +84,7 @@ from judge.views.select2 import (
TicketUserSelect2View,
UserSearchSelect2View,
UserSelect2View,
ProblemAuthorSearchSelect2View,
)
admin.autodiscover()
@ -887,6 +888,11 @@ urlpatterns = [
AssigneeSelect2View.as_view(),
name="ticket_assignee_select2_ajax",
),
url(
r"^problem_authors$",
ProblemAuthorSearchSelect2View.as_view(),
name="problem_authors_select2_ajax",
),
]
),
),

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,
}

View file

@ -739,11 +739,6 @@ math {
z-index: 1000 !important;
}
select {
visibility: hidden;
max-height: 0;
}
// @media (max-width: 500px) {
// #notification {
// margin-top: 0.6em;

View file

@ -324,10 +324,6 @@ ul.problem-list {
padding: 4px 10px;
}
#category, #types {
visibility: hidden;
}
#filter-form .form-label {
margin-top: 0.5em;
font-style: italic;

View file

@ -522,7 +522,9 @@
$('#search-handle').select2({
placeholder: '<i class="fa fa-search"></i> {{ _('Search by handle...') }}',
ajax: {
url: '{{ url('chat_user_search_select2_ajax') }}'
url: '{{ url('chat_user_search_select2_ajax') }}',
delay: 250,
cache: true,
},
minimumInputLength: 1,
escapeMarkup: function (markup) {

View file

@ -161,7 +161,9 @@
$('#search-contest').select2({
placeholder: placeholder,
ajax: {
url: '{{ url('contest_user_search_select2_ajax', contest.key) }}'
url: '{{ url('contest_user_search_select2_ajax', contest.key) }}',
cache: true,
delay: 250,
},
minimumInputLength: 1,
escapeMarkup: function (markup) {

View file

@ -128,12 +128,14 @@
{% block before_table %}
{% include "contest/contest-datetime.html" %}
<div style="margin-bottom: 0.5em">
{% if page_type == 'participation' %}
{% if contest.can_see_full_scoreboard(request.user) %}
<div style="margin-bottom: 0.5em">
<input id="search-contest" type="text" placeholder="{{ _('View user participation') }}">
</div>
{% endif %}
{% endif %}
<div style="margin-bottom: 0.5em">
<input id="show-schools-checkbox" type="checkbox" style="vertical-align: bottom">
<label for="show-schools-checkbox" style="vertical-align: bottom; margin-right: 1em;">{{ _('Show schools') }}</label>

View file

@ -90,7 +90,15 @@
.css({'visibility': 'visible'});
$('#search-org').select2({multiple: 1, placeholder: '{{ _('Groups') }}...'})
.css({'visibility': 'visible'});
$('#search-author').select2({multiple: 1, placeholder: '{{ _('Authors') }}...'})
$('#search-author').select2({
multiple: 1,
placeholder: '{{ _('Authors') }}...',
ajax: {
url: '{{ url('problem_authors_select2_ajax') }}',
delay: 250,
cache: true,
}
})
.css({'visibility': 'visible'});
// This is incredibly nasty to do but it's needed because otherwise the select2 steals the focus

View file

@ -49,9 +49,9 @@
<div class="filter-form-group">
<label class="bold-text margin-label" for="type"><i class="non-italics">{{ _('Author') }}</i></label>
<select id="search-author" name="authors" multiple>
{% for author in all_authors %}
<option value="{{ author.id }}"{% if author.id in author_query %} selected{% endif %}>
{{ author.user__username }}
{% for author in author_query %}
<option value="{{ author.id }}" selected>
{{ author.username }}
</option>
{% endfor %}
</select>

View file

@ -275,10 +275,6 @@
col.sub-info, td.sub-info {
width: 78%
}
#status, #language {
visibility: hidden;
}
</style>
{% endif %}

View file

@ -193,6 +193,8 @@
}
};
},
delay: 250,
cache: true,
},
};

View file

@ -9,7 +9,9 @@
$('#search-handle').select2({
placeholder: '{{ _('Search by handle...') }}',
ajax: {
url: '{{ url('user_search_select2_ajax') }}'
url: '{{ url('user_search_select2_ajax') }}',
delay: 250,
cache: true,
},
minimumInputLength: 1,
escapeMarkup: function (markup) {