Skip to content

Commit 097b720

Browse files
Added templates for searching.
1 parent c92e9c0 commit 097b720

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

gameserver/templatetags/common_tags.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ def debug():
99
return settings.DEBUG
1010

1111

12-
@register.filter
12+
@register.simple_tag
1313
def startswith(string, substring):
1414
return string.startswith(substring)
1515

1616

17+
@register.simple_tag
18+
def endswith(string, substring):
19+
return string.endswith(substring)
20+
21+
1722
@register.filter
1823
def split(string, split_char=" "):
1924
return string.split(split_char)

gameserver/templatetags/search.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import re
2+
3+
from django import template
4+
from django.shortcuts import resolve_url
5+
6+
register = template.Library()
7+
8+
9+
@register.filter
10+
def get_search_page(request):
11+
if request.path in ["/users/", "/users"]:
12+
return resolve_url("user_list")
13+
elif match := re.fullmatch(r"^/contest/([^/]+)/scoreboard/organization/([^/]+$)", request.path):
14+
return resolve_url(
15+
"contest_organization_scoreboard", contest_slug=match.group(1), org_slug=match.group(2)
16+
)
17+
elif match := re.fullmatch(r"^/contest/([^/]+)/scoreboard$", request.path):
18+
return resolve_url("contest_scoreboard", slug=match.group(1))
19+
return

templates/contest/scoreboard.html

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
{% block heading %}{% if org %}{{ org.short_name }} {% endif %}Scoreboard for
66
<a href="{{ contest.get_absolute_url }}">{{ contest }}</a>{% endblock %}
77

8+
{% block top %}
9+
{% include 'snippets/search.html' %}
10+
{% endblock top %}
811
{% block th %}
912
<th scope="col">Rank</th>
1013
<th scope="col">Name</th>

templates/snippets/search.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% load search %}
2+
3+
<form method="GET" action="{{ request|get_search_page }}">
4+
<div class="input-group mb-3">
5+
<input type="text" class="form-control" placeholder="Search" name="q" value="{{ request.GET.search }}">
6+
<div class="input-group-append">
7+
<button class="btn btn-outline-secondary"
8+
style="border-bottom-left-radius: 0; border-top-left-radius: 0" type="submit">Search
9+
</button>
10+
</div>
11+
</div>
12+
</form>

templates/table-list.html

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
{% block content %}
44
<div class="row mw-100">
5+
{% block top %}
6+
{% endblock %}
57
<div class="col">
68
{% block before_table %}
79
{% endblock %}

templates/user/list.html

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{% extends 'table-list.html' %}
22

3+
{% block top %}
4+
{% include 'snippets/search.html' %}
5+
{% endblock top %}
6+
37
{% block th %}
48
<th scope="col">Rank</th>
59
<th scope="col">Username</th>

0 commit comments

Comments
 (0)