Skip to content

Commit

Permalink
Merge pull request #180 from EarthSchlange/add_player_list_without_dj…
Browse files Browse the repository at this point in the history
…ango_tables2

add player list without django tables2
  • Loading branch information
Michael Hiiva committed Apr 20, 2021
2 parents e652439 + fd552b5 commit 2f28531
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 16 deletions.
3 changes: 2 additions & 1 deletion agagd/agagd/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from agagd_core import urls as beta_urls
from agagd_core import views as agagd_views
from agagd_core.views import InformationPageView, QualificationsPageView
from django.conf import settings
Expand Down Expand Up @@ -59,5 +60,5 @@
path("information/", InformationPageView.as_view()),
path("qualifications/", QualificationsPageView.as_view()),
# Beta
url(r"^beta/", include("agagd_core.urls")),
path("beta/", include(beta_urls.beta_patterns)),
)
7 changes: 6 additions & 1 deletion agagd/agagd_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ class Meta:
class Chapters(models.Model):
# The member_id for a chapter is the same in this table and in the chapter's corresponding Member object.
member_id = models.ForeignKey(
Member, db_column="member_id", primary_key=True, on_delete=models.DO_NOTHING
"Member",
db_column="member_id",
to_field="chapter_id",
unique=True,
primary_key=True,
on_delete=models.DO_NOTHING,
)

name = models.CharField(max_length=255, blank=True)
Expand Down
11 changes: 8 additions & 3 deletions agagd/agagd_core/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from agagd_core.views import beta as agagd_beta_views
from django.conf.urls import url
from agagd_core.views import beta
from django.urls import path

urlpatterns = (url(r"$", agagd_beta_views.index),)
# Note: Based of request for single qoutes.
# fmt: off
beta_patterns = ([
path('', beta.index, name='index'),
path('players/', beta.list_all_players, name='players_list'),
], 'beta')
69 changes: 69 additions & 0 deletions agagd/agagd_core/views/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,31 @@
import agagd_core.tables.beta as agagd_tables

# Django Imports
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db.models import F, Prefetch, Q
from django.shortcuts import get_object_or_404, redirect, render

# Django Table Imports
from django_tables2 import RequestConfig


def agagd_paginator_helper(
request, query_list_object, max_rows_per_page=50, page_request_get_value="pg"
):
paginator = Paginator(query_list_object, max_rows_per_page)

page_number = request.GET.get(page_request_get_value, 1)

try:
query_list_object_with_page_information = paginator.page(page_number)
except PageNotAnInteger:
query_list_object_with_page_information = paginator.page(1)
except EmptyPage:
query_list_object_with_page_information = paginator.page(paginator.num_pages)

return query_list_object_with_page_information


def index(request):
game_list = agagd_models.Game.objects.filter(
game_date__gte=datetime.now() - timedelta(days=180)
Expand Down Expand Up @@ -48,3 +67,53 @@ def index(request):
"tournaments": t_table,
},
)


def list_all_players(request):
list_all_players_query = (
agagd_models.Member.objects.select_related("chapters")
.filter(status="accepted")
.filter(players__rating__isnull=False)
.exclude(type="chapter")
.exclude(type="e-journal")
.exclude(type="library")
.exclude(type="institution")
.values(
"member_id",
"chapter_id",
"chapters__member_id",
"chapters__name",
"full_name",
"type",
"players__rating",
"state",
"players__sigma",
)
.order_by("-players__rating")
)

mobile_column_attrs = "d-none d-lg-table-cell d-xl-table-cell"

list_all_players_columns = (
{"name": "Name", "attrs": None},
{"name": "Chapter", "attrs": None},
{"name": "State", "attrs": mobile_column_attrs},
{"name": "Type", "attrs": mobile_column_attrs},
{"name": "Rating", "attrs": None},
{"name": "Sigma", "attrs": mobile_column_attrs},
)

list_all_players_with_pagination = agagd_paginator_helper(
request, list_all_players_query
)

return render(
request,
"agagd_core/players_list.html",
{
"mobile_column_attrs": mobile_column_attrs,
"list_all_players_columns": list_all_players_columns,
"list_all_players_data": list_all_players_with_pagination,
"page_title": "Members Ratings",
},
)
81 changes: 81 additions & 0 deletions agagd/templates/agagd_core/players_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{% extends "base.beta.html" %}

{% block content %}
<section id="list-all-players-block" class="container">
<section class="row">
<section class="col-sm-12 col-md-12 col-lg-12">
<h5 class="table-headers list-all-players-table-headers">Members Ratings</h5>

<div class="list-all-players-table">
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
{% for player_column in list_all_players_columns %}
<th scope="col" {% if player_column.attrs %} class="{{ player_column.attrs }}" {% endif %}>{{ player_column.name }}</th>
{% endfor %}
</tr>
</thead>

<tbody>
{% for player_data in list_all_players_data %}
<tr>
<th scope="row">
{{ forloop.counter0|add:list_all_players_data.start_index }}
</th>
<td>
<a href="/player/{{ player_data.member_id }}">
{{ player_data.full_name }} ({{ player_data.member_id }})
</a>
</td>
<td>
{% if player_data.chapters__name %}
<a href="/chapter/{{ player_data.chapter_id }}">{{ player_data.chapters__name }}</a>
{% else %}
&#8212;
{% endif %}
</td>
<td class="{{ mobile_column_attrs }}">{{ player_data.state }}</td>
<td class="{{ mobile_column_attrs }}">
{{ player_data.type }}
</td>
<td>
{{ player_data.players__rating }}
</td>
<td class="{{ mobile_column_attrs }}">
{{ player_data.players__sigma }}
</td>
</tr>
{% endfor %}
</tbody>
</table>

<nav aria-label="Table Page Navigation">

{% if list_all_players_data.has_other_pages %}
<ul class="pagination justify-content-center">
{% if list_all_players_data.has_previous %}
<li class="previous page-item">
<a href="?pg={{ list_all_players_data.previous_page_number }}" class="page-link">«</a>
</li>
{% endif %}

{% for page_number in list_all_players_data.paginator.page_range %}
<li class="page-item {% if list_all_players_data.number == page_number %} active {% endif %}">
<a href="?pg={{ page_number }}" class="page-link">{{ page_number }}</a>
</li>
{% endfor %}

{% if list_all_players_data.has_next %}
<li class="next page-item">
<a href="?pg={{ list_all_players_data.next_page_number }}" class="page-link">»</a>
</li>
{% endif %}
</ul>
{% endif %}
</nav>
</div>
</section>
</section>
</section>
{% endblock %}
39 changes: 28 additions & 11 deletions agagd/templates/base.beta.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

<html>
<head>
<title>{% block title %} AGAGD | American Go Game Database {% endblock title %}</title>
<title>
{% block title %}
{% if page_title %}
{{ "AGAGD | "|add:page_title }}
{% else %}
AGAGD | American Go Game Database
{% endif %}
{% endblock title %}
</title>
{% block css %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
{% endblock %}
Expand Down Expand Up @@ -58,23 +66,32 @@ <h6 class="header-subtext">
<footer class="footer mx-3">
<nav class="footer-nav">
{% block footer_nav %}
<h5>Ratings</h5>
<ul class="list-unstyled">
<li>
<a href="/information/">Information</a>
</li>
<section class="container footer-nav-sections">
<section class="row">
<div class="col-12 col-md-3">
<h5>Ratings</h5>
<ul class="list-unstyled">
<li>
<a href="{% url 'beta:players_list' %}">Members Ratings</a>
</li>
<li>
<a href="/information/">Information</a>
</li>

<li>
<a href="/qualifications/">Qualifications</a>
</li>
</ul>
<li>
<a href="/qualifications/">Qualifications</a>
</li>
</ul>
</div>
</section>
</section>
{% endblock footer_nav %}
</nav>

<section class="footer-copy">
{% block footer_copy %}
<div class="footer-copyright text-center">&copy; 2020 <a href="https://www.usgo.org">American Go Association</a></div>
{% endblock footer_copy %}
{% endblock footer_copy %}
</section>
</footer>
</section>
Expand Down

0 comments on commit 2f28531

Please sign in to comment.