hopefully better events view

This commit is contained in:
James Turk 2012-05-27 02:38:37 -04:00
parent 0becec7382
commit 860453a8d0
2 changed files with 25 additions and 12 deletions

View File

@ -15,18 +15,20 @@ match details:</p>
<div class="accordion" id="accordion"> <div class="accordion" id="accordion">
{% regroup points by match.event as event_list %} {% for event in events.values %}
{% for event in event_list %}
<div class="accordion-group"> <div class="accordion-group">
<div class="accordion-heading"> <div class="accordion-heading">
<a class="accordion-toggle event-title" data-toggle="collapse" <a class="accordion-toggle event-title" data-toggle="collapse"
data-parent="#accordion" href="#event-{{event.grouper.id}}"> data-parent="#accordion" href="#event-{{event.id}}">
{{event.grouper.name}} - {{event.grouper.date}} {{event.name}} - {{event.date}}
</a> </a>
{% for team,score in event.scores.iteritems %}
{{team}}: {{score}}
{% endfor %}
</div> </div>
<div id="event-{{event.grouper.id}}" class="accordion-body collapse in"> <div id="event-{{event.id}}" class="accordion-body collapse in">
<div class="accordion-inner"> <div class="accordion-inner">
<table class="table"> <table class="table">
<thead> <thead>
@ -36,13 +38,12 @@ match details:</p>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% regroup event.list by match as match_list %} {% for match, tp_list in event.match_list.items %}
{% for match in match_list %}
<tr> <tr>
<td>{{match.grouper}}</td> <td>{{match}}</td>
<td> <td>
<ul> <ul>
{% for tp in match.list %} {% for tp in tp_list %}
{% if tp.points %} {% if tp.points %}
<li> {{tp.team}} received {{tp.points}} <li> {{tp.team}} received {{tp.points}}
point{{tp.points|pluralize}} for {{tp.star}} point{{tp.points|pluralize}} for {{tp.star}}

View File

@ -1,12 +1,24 @@
from collections import defaultdict
from django.shortcuts import render from django.shortcuts import render
from fowl.game.models import TeamPoints from fowl.game.models import TeamPoints
def events(request): def events(request):
events = {}
points = TeamPoints.objects.filter().order_by('match', points = TeamPoints.objects.filter().order_by('match',
'team').select_related() 'team').select_related()
totals = TeamPoints.objects.values('match__event', for tp in points:
'team__name').annotate(points=Sum('points')) event_id = tp.match.event_id
return render(request, "events.html", {'points': points}) if event_id not in events:
events[event_id] = tp.match.event
events[event_id].scores = {}
events[event_id].match_list = {}
events[event_id].match_list.setdefault(tp.match, []
).append(tp)
events[event_id].scores.setdefault(tp.team.name, 0)
events[event_id].scores[tp.team.name] += tp.points
return render(request, "events.html", {'events': events})
def stables(request): def stables(request):
return render(request, "stables.html") return render(request, "stables.html")