-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from EarthSchlange/update_beta_search
update beta search
- Loading branch information
Showing
3 changed files
with
86 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,52 @@ | ||
from agagd_core.models import Member | ||
from agagd_core.tables.beta import SearchResultsTable | ||
from django.db.models import F, Q | ||
from django.http import HttpResponseRedirect | ||
from django.shortcuts import render | ||
from django.template.response import TemplateResponse | ||
from django.urls import reverse | ||
from django.views.generic import TemplateView | ||
from django.views.generic import DetailView | ||
from django_tables2 import RequestConfig | ||
|
||
|
||
class SearchView(TemplateView): | ||
class SearchView(DetailView): | ||
template_name = "beta.search_page.html" | ||
search_results_template_name = "beta.search_results.html" | ||
|
||
def get(self, request): | ||
query = request.GET.get("q", "") | ||
|
||
if not query: | ||
return render(request, self.template_name) | ||
return TemplateResponse(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 | ||
member_table_data = ( | ||
Member.objects.filter(Q(member_id=F("players__pin_player"))) | ||
.filter(full_name__icontains=query) | ||
.values( | ||
"member_id", | ||
"chapter_id", | ||
"renewal_due", | ||
"state", | ||
"players__rating", | ||
"country", | ||
"full_name", | ||
"family_name", | ||
) | ||
.order_by("family_name") | ||
) | ||
|
||
self.template_name = self.search_results_template_name | ||
|
||
member_results_table = SearchResultsTable(member_table_data) | ||
RequestConfig(request, paginate={"per_page": 25}).configure( | ||
member_results_table | ||
) | ||
|
||
context = locals() | ||
context["search_query"] = query | ||
context["member_results_table"] = member_results_table | ||
|
||
return TemplateResponse(request, self.template_name, context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends "beta.base.html" %} | ||
|
||
{% block content %} | ||
|
||
<div class="container my-4"> | ||
<div class="row"> | ||
<div class="col mx-0 px-0"> | ||
<h3>Search Results for {{ search_query }}</h3> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col mx-0 mb-2 pb-4 px-0"> | ||
{{ member_results_table.as_html(request) }} | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |