Skip to content

Commit

Permalink
Added templates for searching.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Apr 6, 2024
1 parent c92e9c0 commit 097b720
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gameserver/templatetags/common_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ def debug():
return settings.DEBUG


@register.filter
@register.simple_tag
def startswith(string, substring):
return string.startswith(substring)


@register.simple_tag
def endswith(string, substring):
return string.endswith(substring)


@register.filter
def split(string, split_char=" "):
return string.split(split_char)
Expand Down
19 changes: 19 additions & 0 deletions gameserver/templatetags/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import re

from django import template
from django.shortcuts import resolve_url

register = template.Library()


@register.filter
def get_search_page(request):
if request.path in ["/users/", "/users"]:
return resolve_url("user_list")
elif match := re.fullmatch(r"^/contest/([^/]+)/scoreboard/organization/([^/]+$)", request.path):
return resolve_url(
"contest_organization_scoreboard", contest_slug=match.group(1), org_slug=match.group(2)
)
elif match := re.fullmatch(r"^/contest/([^/]+)/scoreboard$", request.path):
return resolve_url("contest_scoreboard", slug=match.group(1))
return
3 changes: 3 additions & 0 deletions templates/contest/scoreboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{% block heading %}{% if org %}{{ org.short_name }} {% endif %}Scoreboard for
<a href="{{ contest.get_absolute_url }}">{{ contest }}</a>{% endblock %}

{% block top %}
{% include 'snippets/search.html' %}
{% endblock top %}
{% block th %}
<th scope="col">Rank</th>
<th scope="col">Name</th>
Expand Down
12 changes: 12 additions & 0 deletions templates/snippets/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% load search %}

<form method="GET" action="{{ request|get_search_page }}">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Search" name="q" value="{{ request.GET.search }}">
<div class="input-group-append">
<button class="btn btn-outline-secondary"
style="border-bottom-left-radius: 0; border-top-left-radius: 0" type="submit">Search
</button>
</div>
</div>
</form>
2 changes: 2 additions & 0 deletions templates/table-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

{% block content %}
<div class="row mw-100">
{% block top %}
{% endblock %}
<div class="col">
{% block before_table %}
{% endblock %}
Expand Down
4 changes: 4 additions & 0 deletions templates/user/list.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{% extends 'table-list.html' %}

{% block top %}
{% include 'snippets/search.html' %}
{% endblock top %}

{% block th %}
<th scope="col">Rank</th>
<th scope="col">Username</th>
Expand Down

0 comments on commit 097b720

Please sign in to comment.