started transitioning lineup and players to tables

This commit is contained in:
2021-11-15 15:57:43 -06:00
parent 27ff641d3e
commit 265c160f25
2 changed files with 45 additions and 18 deletions

View File

@@ -8,7 +8,7 @@
<div class="container">
<div class="row">
<div class="col-md-6">
<h6>Lineup</h6>
<h5>Lineup</h5>
{# <ul class="list-group">#}
<form action="{% url 'edit lineup' event_id=event.id%}" method="post">
@@ -23,12 +23,20 @@
<th scope="col">Position</th>
</tr>
</thead>
{% for form in positionings_formset %}
<tr>
<th scope="row">{{ form.order }}</th>
<td>{{ form.player }}</td>
<td>{{ form.position }}</td>
{% for player in positionings_players_initial|dictsort:"positioning.order" %}
{% if player.positioning %}
<tr data-player-id="{{ player.id }}",
data-positioning-position="{{ player.positioning.position }}"
>
{# <th scope="row">{{ form.order }}</th>#}
{# <td>{{ form.player }}</td>#}
{# <td>{{ form.position }}</td>#}
<th scope="row">{% if player.positioning.order %}{{ player.positioning.order }}{% endif %}</th>
<th>{{ player.first_name }} {{ player.last_name }}</th>
<td>{{ player.positioning.position }}</td>
</tr>
{% endif %}
{% endfor %}
</table>
{# {% endfor %}#}
@@ -37,10 +45,22 @@
</div>
<div class="col-md-6">
<h6>Players</h6>
<ul class="list-group">
<h5>Players</h5>
<div class="col-md-6">
<table class="table">
<tr>
<th scope="col"></th>
<th scope="col">Name</th>
<th scope="col">#</th>
<th scope="col">Avg</th>
<th scope="col">Slug</th>
<th scope="col">OBP</th>
</tr>
{% for player in players %}
<li class="list-group-item">
{% if not player.positioning %}
<tr>
<td>
{% if player.availability.available == 2 %}
<img class="bg-success p-2 rounded-circle" width="5" height="5"><span class="visually-hidden">Yes</span></img>
{% elif player.availability.available == 1%}
@@ -50,11 +70,16 @@
{% elif player.availability.available == -1%}
<img class="bg-secondary p-2 rounded-circle" width="5" height="5"><span class="visually-hidden">Unknown</span></span>
{% endif %}
{{ player.first_name }} {{ player.last_name }}
<code><small>{{ player.statline }}</small></code>
</li>
</td>
<th><span class="d-none d-md-block">{{ player.first_name }}</span> {{ player.last_name }}</th>
<td>{{ player.jersey_number }}</td>
<td><code>{{ player.statline.batting_avg|stringformat:".3f"|slice:"1:" }}</code></td>
<td><code>{{ player.statline.slugging_pct|stringformat:".3f"|slice:"1:" }}</code></td>
<td><code>{{ player.statline.onbase_pct|stringformat:".3f"|slice:"1:" }}</code></td>
</tr>
{% endif %}
{% endfor %}
</ul>
</table >
</div>
</div>
</div>

View File

@@ -29,18 +29,19 @@ def edit(request, event_id):
return render(request, 'success.html', {'call_back':'edit lineup','id':event_id}, status=200)
# return render(request, 'success.html', {'call_back':'schedule'})
event = Event.objects.get(id=event_id)
players = Player.objects.all().prefetch_related('availability_set', 'statline_set')
players = Player.objects.all().prefetch_related('availability_set', 'statline_set', 'positioning_set')
players = [
{
**model_to_dict(player),
'availability':player.availability_set.get(event_id=event_id),
# 'available_value': player.availability_set.get(event_id=event_id).available,
'statline': player.statline_set.get(player_id=player.id)
'statline': player.statline_set.get(player_id=player.id),
'positioning': player.positioning_set.filter(event_id=event_id).first()
}
for player in players
]
players.sort(key=lambda d: d['availability'].available, reverse = True)
qset = Positioning.objects.filter(event_id=event_id, order__isnull = False)
players.sort(key=lambda d: (-d['availability'].available, d['last_name']))
qset = Positioning.objects.filter(event_id=event_id)
formset = PositioningFormSet(queryset=qset)
for form in formset:
for field in form.fields:
@@ -48,4 +49,5 @@ def edit(request, event_id):
return render(request, 'lineups/lineup.html', {'title': 'Lineup',
'event': event,
'players': players,
'positionings_players_initial':[player for player in players if player['positioning']],
'positionings_formset':formset})