Merge pull request #59 from zhaospei/master

update contest list filter
This commit is contained in:
Phuoc Dinh Le 2023-02-08 21:14:57 -06:00 committed by GitHub
commit 6bc8b54d94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 7 deletions

View file

@ -149,10 +149,14 @@ class ContestList(
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.contest_query = None self.contest_query = None
self.org_query = [] self.org_query = []
self.show_orgs = 0
if request.GET.get("show_orgs"):
self.show_orgs = 1
if "orgs" in self.request.GET and self.request.profile: if "orgs" in self.request.GET and self.request.profile:
try: try:
self.org_query = list(map(int, request.GET.getlist("orgs"))) self.org_query = list(map(int, request.GET.getlist("orgs")))
if not self.request.user.is_superuser:
self.org_query = [ self.org_query = [
i i
for i in self.org_query for i in self.org_query
@ -181,6 +185,8 @@ class ContestList(
) )
if not self.org_query and self.request.organization: if not self.org_query and self.request.organization:
self.org_query = [self.request.organization.id] self.org_query = [self.request.organization.id]
if self.show_orgs:
queryset = queryset.filter(organizations=None)
if self.org_query: if self.org_query:
queryset = queryset.filter(organizations__in=self.org_query) queryset = queryset.filter(organizations__in=self.org_query)
@ -227,7 +233,11 @@ class ContestList(
context["first_page_href"] = "." context["first_page_href"] = "."
context["contest_query"] = self.contest_query context["contest_query"] = self.contest_query
context["org_query"] = self.org_query context["org_query"] = self.org_query
context["show_orgs"] = int(self.show_orgs)
if self.request.profile: if self.request.profile:
if self.request.user.is_superuser:
context["organizations"] = Organization.objects.all()
else:
context["organizations"] = self.request.profile.organizations.all() context["organizations"] = self.request.profile.organizations.all()
context["page_type"] = "list" context["page_type"] = "list"
context.update(self.get_sort_context()) context.update(self.get_sort_context())

View file

@ -18,6 +18,10 @@
padding-bottom: 1em; padding-bottom: 1em;
} }
#show-btn {
margin-top: 0.5em;
}
{% if page_obj and page_obj.number > 1%} {% if page_obj and page_obj.number > 1%}
#ongoing-table { #ongoing-table {
display: none; display: none;
@ -71,6 +75,10 @@
<script src="{{ static('libs/featherlight/featherlight.min.js') }}" type="text/javascript"></script> <script src="{{ static('libs/featherlight/featherlight.min.js') }}" type="text/javascript"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function () { $(document).ready(function () {
var $form = $('form#filter-form');
$('input#show_orgs').click(function () {
$form.submit();
});
$('.time-remaining').each(function () { $('.time-remaining').each(function () {
count_down($(this)); count_down($(this));
}); });
@ -215,6 +223,10 @@
</select> </select>
{% endif %} {% endif %}
<button id="search-btn" class="btn-green small"> {{ _('Search')}} </button> <button id="search-btn" class="btn-green small"> {{ _('Search')}} </button>
{% if organizations %}
<input id="show_orgs" type="checkbox" name="show_orgs" value="1" {% if show_orgs %}checked{% endif %}>
<label for="show_orgs">{{ _('Hide organization contests') }}</label>
{% endif %}
{% if create_url %} {% if create_url %}
<a href="{{create_url}}" class="button small" style="float: right"><i class="fa fa-plus"></i> {{ _('Create')}}</a> <a href="{{create_url}}" class="button small" style="float: right"><i class="fa fa-plus"></i> {{ _('Create')}}</a>
{% endif %} {% endif %}