Skip to content

Commit

Permalink
Add search contests from VNOJ
Browse files Browse the repository at this point in the history
Co-authored-by: Le Duy Thuc <[email protected]>
  • Loading branch information
2 people authored and Ninjaclasher committed Jan 12, 2025
1 parent 31280bf commit 415351b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
9 changes: 8 additions & 1 deletion judge/views/contests.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ def _get_queryset(self):
)

def get_queryset(self):
return self._get_queryset().order_by(self.order, 'key').filter(end_time__lt=self._now)
self.search_query = None
queryset = self._get_queryset().order_by(self.order, 'key').filter(end_time__lt=self._now)
if 'search' in self.request.GET:
self.search_query = search_query = ' '.join(self.request.GET.getlist('search')).strip()
if search_query:
queryset = queryset.filter(Q(key__icontains=search_query) | Q(name__icontains=search_query))
return queryset

def get_paginator(self, queryset, per_page, orphans=0, allow_empty_first_page=True, **kwargs):
return super().get_paginator(queryset, per_page, orphans, allow_empty_first_page,
Expand Down Expand Up @@ -142,6 +148,7 @@ def get_context_data(self, **kwargs):
context['now'] = self._now
context['first_page_href'] = '.'
context['page_suffix'] = '#past-contests'
context['search_query'] = self.search_query
context.update(self.get_sort_context())
context.update(self.get_sort_paginate_context())
return context
Expand Down
19 changes: 15 additions & 4 deletions templates/contest/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,19 @@ <h4>{{ _('Upcoming contests') }}</h4>
{% endif %}
<br>

<h4 id="past-contests">{{ _('Past contests') }}</h4>
{% if page_obj or search_query %}
<div class="top-pagination-bar">
{% include "list-pages.html" %}
<form id="search-form" name="form" action="" method="get">
<div>
<input id="search" type="text" name="search" value="{{ search_query or '' }}"
placeholder="{{ _('Search contests...') }}">
</div>
</form>
</div>
{% endif %}
{% if past_contests %}
<h4 id="past-contests">{{ _('Past contests') }}</h4>
{% if page_obj and page_obj.has_other_pages() %}
<div class="top-pagination-bar">{% include "list-pages.html" %}</div>
{% endif %}
<table class="contest-list table striped">
<thead>
<tr>
Expand Down Expand Up @@ -301,6 +309,9 @@ <h4 id="past-contests">{{ _('Past contests') }}</h4>
{% if page_obj and page_obj.has_other_pages() %}
<div class="bottom-pagination-bar">{% include "list-pages.html" %}</div>
{% endif %}
{% else %}
<i>{{ _('There are no past contests.') }}</i>
<br>
{% endif %}
</div>
{% endblock %}

0 comments on commit 415351b

Please sign in to comment.