Skip to content

Commit

Permalink
Merge pull request #213 from EarthSchlange/add_search_page
Browse files Browse the repository at this point in the history
add search page
  • Loading branch information
Michael Hiiva authored Jul 23, 2021
2 parents 51a3d70 + f62f3f0 commit 65a5d0c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
1 change: 1 addition & 0 deletions agagd/agagd/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_extensions",
"django_tables2",
]

Expand Down
3 changes: 3 additions & 0 deletions agagd/agagd_core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from agagd_core.views.beta.information import InformationView
from agagd_core.views.beta.players_profile import players_profile
from agagd_core.views.beta.qualifications import QualificationsView
from agagd_core.views.beta.search import SearchView

# Django Imports
from django.urls import path
Expand All @@ -19,6 +20,8 @@
path('players/', list_all_players, name='players_list'),
path('players/<int:player_id>/', players_profile, name='players_profile'),
path('information/', InformationView.as_view(), name='ratings_overview'),
path('search/', SearchView.as_view(), name='search'),
path('search/q<str:query>/', SearchView.as_view(), name='search'),
path('tournaments/', list_all_tournaments, name='tournaments_list'),
path('tournaments/<slug:code>/', tournament_detail, name='tournament_detail'),
path('qualifications/', QualificationsView.as_view(), name='qualifications_overview')
Expand Down
26 changes: 26 additions & 0 deletions agagd/agagd_core/views/beta/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse
from django.views.generic import TemplateView


class SearchView(TemplateView):
template_name = "beta.search_page.html"

def get(self, request):
query = request.GET.get("q", "")

if not query:
return render(request, self.template_name)

if query.isdigit():
member_id = [int(query)]
return HttpResponseRedirect(reverse("member_detail", args=member_id))

return HttpResponseRedirect(f"/search/?q={query}")

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["page_title"] = "Search -- Players | Games | Tournaments"

return context
14 changes: 8 additions & 6 deletions agagd/jinja2/beta.base.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ <h6 class="header-subtext">
</h6>
</div>

<div class="col-12 col-md-6">
<form class="form-inline justify-content-md-end my-2 my-lg-0" action="{{ url("search") }}" method="get">
<input class="form-control mr-sm-2" type="search" name="q" placeholder="Player Name or AGA ID" aria-label="Search">
</form>
</div>
{% if not url("search") in request.path %}
<div class="col-12 col-md-6">
<form class="form-inline justify-content-md-end my-2 my-lg-0" action="{{ url("beta:search") }}" method="get">
<input class="form-control mr-sm-2" type="search" name="q" placeholder="Player Name or AGA ID" aria-label="Search">
</form>
</div>
{% endif %}
</header>

<main class="main-content">
{% block content %}{% endblock content %}
</main>

<footer class="footer mx-3">
<footer class="footer">
<nav class="footer-nav">
{% block footer_nav %}
<section class="container footer-nav-sections">
Expand Down
28 changes: 28 additions & 0 deletions agagd/jinja2/beta.search_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "beta.base.html" %}

{% block content %}

<div class="container my-4">
<div class="row">
<div class="col mx-2 px-4">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search" viewBox="0 0 16 16">
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"/>
</svg>
Search the American Go Association Games Database
</div>
</div>
<div class="row">
<div class="col mx-2 mb-2 pb-4 px-4">
<form id="search-form" action="{{ url('beta:search') }}" method="get">
<div class="d-flex-inline flex-column flex-sm-row">
<div class="flex-auto position-relative">
<input class="d-inline form-control w-75" aria-label="Search -- Players | Games | Tournaments" type="search" name="q">
<button class="d-inline btn btn-primary" type="Submit">Search</button>
</div>
<div class="small">Enter a Player ID or Name. For example, 2050 or Doe, John</div>
</div>
</form>
</div>
</div>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Django==3.1.12
django-admin-tools==0.4.1
django-debug-toolbar==3.2.1
django-tables2==2.3.0
django-extensions==3.1.3
jinja2==2.11.3
PyMySQL==1.0.2
yolk==0.4.3

0 comments on commit 65a5d0c

Please sign in to comment.