playerlist
This commit is contained in:
parent
1c13f65b64
commit
aba0533b82
@ -8,6 +8,7 @@
|
|||||||
<div>
|
<div>
|
||||||
{% if user.coached_teams.all or user.assisted_teams.all %}
|
{% if user.coached_teams.all or user.assisted_teams.all %}
|
||||||
<a href="{% url 'select-event-type' %}" class="btn btn-primary">Create New Event</a>
|
<a href="{% url 'select-event-type' %}" class="btn btn-primary">Create New Event</a>
|
||||||
|
<a href="{% url 'player_list' %}" class="btn btn-info">Player List</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
63
dashboard/templates/dashboard/player_list.html
Normal file
63
dashboard/templates/dashboard/player_list.html
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container mt-4">
|
||||||
|
<h2 class="mb-4">Player List</h2>
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<label for="teamFilter" class="form-label">Filter by Team:</label>
|
||||||
|
<select id="teamFilter" class="form-select">
|
||||||
|
<option value="">All Teams</option>
|
||||||
|
{% for team in teams %}
|
||||||
|
<option value="{{ team.name }}">{{ team.name }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="table table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Name</th>
|
||||||
|
<th scope="col">Team</th>
|
||||||
|
<th scope="col">Player Number</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="playerTableBody">
|
||||||
|
{% for player in players %}
|
||||||
|
<tr data-team="{{ player.team.name }}">
|
||||||
|
<td>{{ player.first_name }} {{ player.last_name }}</td>
|
||||||
|
<td>{{ player.team.name }}</td>
|
||||||
|
<td>{{ player.player_number }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% block extra_js %}
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const teamFilter = document.getElementById('teamFilter');
|
||||||
|
const playerTableBody = document.getElementById('playerTableBody');
|
||||||
|
const rows = playerTableBody.getElementsByTagName('tr');
|
||||||
|
|
||||||
|
teamFilter.addEventListener('change', function() {
|
||||||
|
const selectedTeam = this.value;
|
||||||
|
|
||||||
|
for (let i = 0; i < rows.length; i++) {
|
||||||
|
const row = rows[i];
|
||||||
|
const teamCell = row.getAttribute('data-team');
|
||||||
|
|
||||||
|
if (selectedTeam === "" || teamCell === selectedTeam) {
|
||||||
|
row.style.display = "";
|
||||||
|
} else {
|
||||||
|
row.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
{% endblock %}
|
||||||
@ -3,4 +3,5 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.dashboard, name='dashboard'),
|
path('', views.dashboard, name='dashboard'),
|
||||||
|
path('players/', views.player_list, name='player_list'),
|
||||||
]
|
]
|
||||||
@ -2,6 +2,7 @@ from django.shortcuts import render
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from calendars.models import Event, EventParticipation
|
from calendars.models import Event, EventParticipation
|
||||||
from clubs.models import Team
|
from clubs.models import Team
|
||||||
|
from accounts.models import CustomUser
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
import datetime
|
import datetime
|
||||||
@ -109,3 +110,23 @@ def dashboard(request):
|
|||||||
'now': timezone.now()
|
'now': timezone.now()
|
||||||
}
|
}
|
||||||
return render(request, 'dashboard/dashboard.html', context)
|
return render(request, 'dashboard/dashboard.html', context)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def player_list(request):
|
||||||
|
user = request.user
|
||||||
|
coached_teams = user.coached_teams.all()
|
||||||
|
assisted_teams = user.assisted_teams.all()
|
||||||
|
|
||||||
|
all_coached_teams = list(coached_teams)
|
||||||
|
for team in coached_teams:
|
||||||
|
all_coached_teams.extend(get_all_child_teams(team))
|
||||||
|
|
||||||
|
all_teams = set(list(all_coached_teams) + list(assisted_teams))
|
||||||
|
|
||||||
|
players = CustomUser.objects.filter(team__in=all_teams).distinct()
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'players': players,
|
||||||
|
'teams': all_teams
|
||||||
|
}
|
||||||
|
return render(request, 'dashboard/player_list.html', context)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user