From 0becec73820e53833387b6445cc6222eb50b6ed3 Mon Sep 17 00:00:00 2001
From: James Turk
Date: Sun, 27 May 2012 01:45:54 -0400
Subject: [PATCH 1/2] work on events template
---
fowl/game/models.py | 6 +-
fowl/game/templates/base.html | 1 +
fowl/game/templates/events.html | 146 +++++++++++---------------------
fowl/game/views.py | 7 +-
fowl/settings.py | 4 +
setup_league.py | 17 +++-
6 files changed, 81 insertions(+), 100 deletions(-)
diff --git a/fowl/game/models.py b/fowl/game/models.py
index db1b49e..cdd4724 100644
--- a/fowl/game/models.py
+++ b/fowl/game/models.py
@@ -202,7 +202,7 @@ class Match(models.Model):
return points
def __unicode__(self):
- return ' vs. '.join(str(t) for t in self.teams.all())
+ return ' vs. '.join(str(t) for t in self.teams.all().prefetch_related('members'))
admin.site.register(Match)
@@ -227,5 +227,5 @@ class TeamPoints(models.Model):
match = models.ForeignKey(Match)
def __unicode__(self):
- return "{0} recieved {1} points for {2}'s performance in {3}".format(
- self.team, self.points, self.star, self.match)
\ No newline at end of file
+ return "{0} received {1} points for {2}'s performance in {3}".format(
+ self.team, self.points, self.star, self.match)
diff --git a/fowl/game/templates/base.html b/fowl/game/templates/base.html
index ffe633b..aa92ff1 100644
--- a/fowl/game/templates/base.html
+++ b/fowl/game/templates/base.html
@@ -12,6 +12,7 @@
padding-top: 60px;
padding-bottom: 40px;
}
+ .event-title { font-size: 125%; }
diff --git a/fowl/game/templates/events.html b/fowl/game/templates/events.html
index bd94eee..7011687 100644
--- a/fowl/game/templates/events.html
+++ b/fowl/game/templates/events.html
@@ -5,105 +5,61 @@
{% block content %}
Events
- Every event that has taken place on RAW, Smackdown, and on PPVs, since the creation of this league.
+Every event that has taken place on RAW, Smackdown, and on
+PPVs, since the creation of this league.
Events List:
- Yup, here are those events, collapsed in a nice way, click for match details:
+Yup, here are those events, collapsed in a nice way, click for
+match details:
-
-
-
-
-
+
-
-
-
- Event
- Points
-
-
-
-
- Rey Mysterio vs Sin Cara
-
-
- GM Punk gets 2 points for Sin Cara victory
- COBRA! gets 0 points for Sin Cara victory
-
-
-
-
- Big Show & Kane vs Kaval
-
-
- COBRA! gets 2 points for Big Show Victory
- GM Punk gets 2 points for Kane victory
- COBRA! & GM Punk get -2 points for murder
-
-
-
-
-
+{% regroup points by match.event as event_list %}
+{% for event in event_list %}
-
-
-
-
-
-
-
-
-
-
- Event
- Points
-
-
-
-
- Cody Rhodes vs John Cena
-
-
- GM Punk gets 2 points for Cody Rhodes victory
- I'm AWEsome gets 0 points for Cody Rhodes victory
-
-
-
-
- The Miz vs Santino
-
-
- COBRA! gets 2 points for Santino Victory
- COBRA! gets 4 points for US Championship title defense
-
-
-
-
-
-
-
-
-
-
-
-
- Didn't want to get presumptious with the scores on this one
-
-
-
-
+
+
+
+
+
+
+
+
+ Event
+ Scoring
+
+
+
+ {% regroup event.list by match as match_list %}
+ {% for match in match_list %}
+
+ {{match.grouper}}
+
+
+ {% for tp in match.list %}
+ {% if tp.points %}
+ {{tp.team}} received {{tp.points}}
+ point{{tp.points|pluralize}} for {{tp.star}}
+
+ {% endif %}
+ {% endfor %}
+
+
+
+ {% endfor %}
+
+
+
+
+
+
+
+{% endfor %}
+
{% endblock %}
diff --git a/fowl/game/views.py b/fowl/game/views.py
index 99c5da3..5989984 100644
--- a/fowl/game/views.py
+++ b/fowl/game/views.py
@@ -1,7 +1,12 @@
from django.shortcuts import render
+from fowl.game.models import TeamPoints
def events(request):
- return render(request, "events.html")
+ points = TeamPoints.objects.filter().order_by('match',
+ 'team').select_related()
+ totals = TeamPoints.objects.values('match__event',
+ 'team__name').annotate(points=Sum('points'))
+ return render(request, "events.html", {'points': points})
def stables(request):
return render(request, "stables.html")
diff --git a/fowl/settings.py b/fowl/settings.py
index c7b77e1..aa4dd4d 100644
--- a/fowl/settings.py
+++ b/fowl/settings.py
@@ -77,10 +77,13 @@ MIDDLEWARE_CLASSES = (
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
+ 'debug_toolbar.middleware.DebugToolbarMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
+INTERNAL_IPS = ('127.0.0.1',)
+
ROOT_URLCONF = 'fowl.urls'
# Python dotted path to the WSGI application used by Django's runserver.
@@ -100,6 +103,7 @@ INSTALLED_APPS = (
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
+ 'debug_toolbar',
'fowl.game',
)
diff --git a/setup_league.py b/setup_league.py
index aabbbbd..2c2ec7c 100644
--- a/setup_league.py
+++ b/setup_league.py
@@ -4,6 +4,7 @@ from fowl.game.models import League, Star, Team, Event, Match
User.objects.all().delete()
League.objects.all().delete()
Team.objects.all().delete()
+Event.objects.all().delete()
james = User.objects.create_superuser('james', 'james.p.turk@gmail.com', 'james')
erin = User.objects.create_user('erin', 'erin.braswell@gmail.com', 'erin')
@@ -26,4 +27,18 @@ for person in awesomes:
cobras = ('santinomarella', 'dolphziggler', 'kofikingston', 'albertodelrio',
'randyorton', 'bigshow', 'christian', 'layla', 'natalya')
for person in cobras:
- cobra.add_star(pk=person)
\ No newline at end of file
+ cobra.add_star(pk=person)
+
+event = Event.objects.create(name='RAW', date='2012-05-14')
+event.add_match(['cmpunk', 'santinomarella'], ['codyrhodes', 'danielbryan'],
+ winner='cmpunk', win_type='pin')
+event.add_match('aliciafox', 'bethphoenix', winner='bethphoenix',
+ win_type='pin')
+event.add_match('bigshow', 'kane', winner='kane', win_type='pin')
+event.add_match(['brodusclay', 'kofikingston', 'rtruth'],
+ ['themiz', 'jackswagger', 'dolphziggler'],
+ winner='brodusclay', win_type='pin')
+event.add_match('chrisjericho', 'randyorton',
+ winner='chrisjericho', win_type='DQ',
+ note='Sheamus interfered, giving Jericho the win')
+league.score_event(event)
From 860453a8d01c7039ad3e03c770eefe94aa445704 Mon Sep 17 00:00:00 2001
From: James Turk
Date: Sun, 27 May 2012 02:38:37 -0400
Subject: [PATCH 2/2] hopefully better events view
---
fowl/game/templates/events.html | 19 ++++++++++---------
fowl/game/views.py | 18 +++++++++++++++---
2 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/fowl/game/templates/events.html b/fowl/game/templates/events.html
index 7011687..078ff2d 100644
--- a/fowl/game/templates/events.html
+++ b/fowl/game/templates/events.html
@@ -15,18 +15,20 @@ match details:
-{% regroup points by match.event as event_list %}
-{% for event in event_list %}
+{% for event in events.values %}
-
+
@@ -36,13 +38,12 @@ match details:
- {% regroup event.list by match as match_list %}
- {% for match in match_list %}
+ {% for match, tp_list in event.match_list.items %}
- {{match.grouper}}
+ {{match}}
- {% for tp in match.list %}
+ {% for tp in tp_list %}
{% if tp.points %}
{{tp.team}} received {{tp.points}}
point{{tp.points|pluralize}} for {{tp.star}}
diff --git a/fowl/game/views.py b/fowl/game/views.py
index 5989984..e58068f 100644
--- a/fowl/game/views.py
+++ b/fowl/game/views.py
@@ -1,12 +1,24 @@
+from collections import defaultdict
from django.shortcuts import render
from fowl.game.models import TeamPoints
+
def events(request):
+ events = {}
points = TeamPoints.objects.filter().order_by('match',
'team').select_related()
- totals = TeamPoints.objects.values('match__event',
- 'team__name').annotate(points=Sum('points'))
- return render(request, "events.html", {'points': points})
+ for tp in points:
+ event_id = tp.match.event_id
+ 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):
return render(request, "stables.html")