feat: Erweiterung der Dashboard-Anzeige für Trainer um Spieler-Teilnahmestatus
This commit is contained in:
parent
066a749363
commit
852c776879
Binary file not shown.
@ -12,28 +12,47 @@
|
||||
</div>
|
||||
|
||||
<h3>Your Events</h3>
|
||||
{% if events %}
|
||||
{% if events_with_participation %}
|
||||
<div class="list-group">
|
||||
{% for event in events %}
|
||||
{% for item in events_with_participation %}
|
||||
<div class="list-group-item list-group-item-action flex-column align-items-start
|
||||
{% if event.game %}
|
||||
{% if item.event.game %}
|
||||
event-game
|
||||
{% elif event.training %}
|
||||
{% elif item.event.training %}
|
||||
event-training
|
||||
{% else %}
|
||||
event-generic
|
||||
{% endif %}
|
||||
">
|
||||
<div class="d-flex w-100 justify-content-between">
|
||||
<h5 class="mb-1">{{ event.title }}</h5>
|
||||
<small>{{ event.start_time|localize }}</small>
|
||||
<h5 class="mb-1">{{ item.event.title }}</h5>
|
||||
<small>{{ item.event.start_time|localize }}</small>
|
||||
</div>
|
||||
<p class="mb-1">{{ item.event.description }}</p>
|
||||
<small>Location: {{ item.event.location_address }}</small>
|
||||
<a href="{{ item.event.maps_shortlink }}" target="_blank" class="btn btn-secondary btn-sm">View on Map</a>
|
||||
{% if user == item.event.team.head_coach or user in item.event.team.assistant_coaches.all %}
|
||||
<a href="{% url 'event-update' item.event.pk %}" class="btn btn-warning btn-sm">Edit</a>
|
||||
<a href="{% url 'event-delete' item.event.pk %}" class="btn btn-danger btn-sm">Delete</a>
|
||||
|
||||
<div class="mt-3">
|
||||
<h6>Player Participation ({{ item.accepted_count }}/{{ item.required_players }})</h6>
|
||||
<div style="column-count: 3;">
|
||||
<ul class="list-unstyled">
|
||||
{% for p in item.player_participations %}
|
||||
<li class="
|
||||
{% if p.status == 'attending' %}
|
||||
text-success
|
||||
{% elif p.status == 'rejected' %}
|
||||
text-danger
|
||||
{% else %} {# status is 'maybe' #}
|
||||
text-warning
|
||||
{% endif %}
|
||||
">{{ p.player.first_name }} {{ p.player.last_name }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<p class="mb-1">{{ event.description }}</p>
|
||||
<small>Location: {{ event.location_address }}</small>
|
||||
<a href="{{ event.maps_shortlink }}" target="_blank" class="btn btn-secondary btn-sm">View on Map</a>
|
||||
{% if user == event.team.head_coach or user in event.team.assistant_coaches.all %}
|
||||
<a href="{% url 'event-update' event.pk %}" class="btn btn-warning btn-sm">Edit</a>
|
||||
<a href="{% url 'event-delete' event.pk %}" class="btn btn-danger btn-sm">Delete</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
@ -6,7 +6,7 @@ from clubs.models import Team
|
||||
@login_required
|
||||
def dashboard(request):
|
||||
user = request.user
|
||||
events = []
|
||||
events_with_participation = []
|
||||
children_events = []
|
||||
|
||||
# Get user's own events
|
||||
@ -18,7 +18,27 @@ def dashboard(request):
|
||||
from itertools import chain
|
||||
all_teams = list(set(chain(player_teams, coached_teams, assisted_teams)))
|
||||
if all_teams:
|
||||
events = Event.objects.filter(team__in=all_teams).select_related('game', 'training').order_by('start_time')
|
||||
events = Event.objects.filter(team__in=all_teams).select_related('game', 'training').prefetch_related('team__players', 'eventparticipation_set__user').order_by('start_time')
|
||||
|
||||
for event in events:
|
||||
participations = event.eventparticipation_set.all()
|
||||
accepted_count = sum(1 for p in participations if p.status == 'attending')
|
||||
required_players = event.game.min_players if hasattr(event, 'game') else 0
|
||||
|
||||
player_participations = []
|
||||
team_players = event.team.players.all()
|
||||
participation_map = {p.user_id: p.status for p in participations}
|
||||
|
||||
for player in team_players:
|
||||
status = participation_map.get(player.id, 'maybe')
|
||||
player_participations.append({'player': player, 'status': status})
|
||||
|
||||
events_with_participation.append({
|
||||
'event': event,
|
||||
'accepted_count': accepted_count,
|
||||
'required_players': required_players,
|
||||
'player_participations': player_participations
|
||||
})
|
||||
|
||||
# Get children's events
|
||||
if hasattr(user, 'children'):
|
||||
@ -32,7 +52,7 @@ def dashboard(request):
|
||||
children_events.append({'child': child, 'events': child_events_list})
|
||||
|
||||
context = {
|
||||
'events': events,
|
||||
'events_with_participation': events_with_participation,
|
||||
'children_events': children_events,
|
||||
}
|
||||
return render(request, 'dashboard/dashboard.html', context)
|
||||
Loading…
x
Reference in New Issue
Block a user