diff --git a/fowl/game/models.py b/fowl/game/models.py index 0aa02f8..7a5f978 100644 --- a/fowl/game/models.py +++ b/fowl/game/models.py @@ -6,20 +6,21 @@ Q = models.Q # these things are independent of the game OUTCOMES = (('no contest', 'no contest'), - ('normal', 'normal'), - ('DQ', 'DQ'), + ('normal', 'pinfall/normal'), + ('dq', 'disqualification'), ('submission', 'submission'), ('appearance', 'appearance'), ('brawl', 'brawl'), ) TITLES = (('wwe', 'WWE'), - ('heavyweight', 'Heavyweight'), + ('world', 'World Heavyweight'), ('ic', 'Intercontinental'), ('us', 'United States'), ('tag', 'Tag Team'), ('diva', 'Divas'), ) +TITLE_DICT = dict(TITLES) class Star(models.Model): @@ -48,8 +49,9 @@ class Star(models.Model): def has_title(self, date=None): if date: - current_title = list(self.reigns.filter(Q(begin_date__lt=date) & - (Q(end_date__gte=date) | Q(end_date__isnull=True)))) + current_title = list(self.reigns.filter( + Q(begin_date__lt=date) & (Q(end_date__gte=date) | + Q(end_date__isnull=True)))) else: current_title = list(self.reigns.filter(end_date__isnull=True)) if len(current_title) < 1: @@ -59,6 +61,12 @@ class Star(models.Model): else: return 'multiple' # FIXME + def titled_name(self, date): + title = self.has_title(date) + name = self.name + if title: + name = '{0} ({1} Champion)'.format(name, TITLE_DICT[title]) + return name def __unicode__(self): return self.name @@ -104,7 +112,7 @@ class Event(models.Model): def add_match(self, *teams, **kwargs): winner = kwargs.get('winner', None) - outcome = kwargs.get('outcome', '') + outcome = kwargs.get('outcome', 'no contest') title_at_stake = kwargs.get('title_at_stake', None) notes = kwargs.get('notes', '') @@ -139,7 +147,8 @@ class Event(models.Model): class Match(models.Model): event = models.ForeignKey(Event, related_name='matches') winner = models.ForeignKey(Star, null=True) - outcome = models.CharField(max_length=10, choices=OUTCOMES) + outcome = models.CharField(max_length=10, choices=OUTCOMES, + default='no contest') title_at_stake = models.CharField(max_length=50, choices=TITLES, null=True) notes = models.TextField(blank=True, default='') @@ -202,7 +211,7 @@ class Match(models.Model): # figure out base points for winning # DQ wins are worth 1 point no matter what - if self.outcome == 'DQ': + if self.outcome == 'dq': base_points = 1 allies = 0 # allies don't matter in a DQ # rumble is worth participants/2 @@ -221,13 +230,13 @@ class Match(models.Model): if self.title_at_stake: if winners.title == self.title_at_stake: # title defense - if winners.title in ('heavyweight', 'wwe'): + if winners.title in ('world', 'wwe'): points[w.id] += 5 else: points[w.id] += 3 elif self.outcome in ('normal', 'submission'): # title win! - if self.title_at_stake in ('heavyweight', 'wwe'): + if self.title_at_stake in ('world', 'wwe'): points[w.id] += 20 else: points[w.id] += 10 @@ -256,11 +265,22 @@ class Match(models.Model): points[self.winner_id] += 1 return points - def __unicode__(self): - ret = ' vs. '.join(str(t) for t in - self.teams.all().prefetch_related('members')) - if not self.winner_id: - ret += ' (no contest)' + def fancy(self): + teams = [t.fancy(self.event.date) for t in + self.teams.all().order_by('-victorious') + .prefetch_related('members')] + if self.outcome in ('normal', 'dq', 'submission'): + ret = '{0} defeats {1}'.format(teams[0], ', '.join(teams[1:])) + ret += {'normal': '', 'dq': ' via disqualification', + 'submission': ' via submission'}[self.outcome] + elif self.outcome == 'appearance': + ret = 'appearance by {0}'.format(', '.join(teams)) + elif self.outcome == 'brawl': + ret = 'brawl between {0}'.format(', '.join(teams)) + elif self.outcome == 'no contest': + ret = '{0} - fight to a no contest'.format(' vs. '.join(teams)) + else: + print self.outcome return ret @@ -270,13 +290,8 @@ class MatchTeam(models.Model): victorious = models.BooleanField(default=False) title = models.CharField(max_length=50, choices=TITLES, null=True) - def __unicode__(self): - ret = ' & '.join([str(m) for m in self.members.all()]) - if self.title: - ret += ' (c)' - if self.victorious: - ret += ' (v)' - return ret + def fancy(self, date): + return ' & '.join([m.titled_name(date) for m in self.members.all()]) # fantasy stuff diff --git a/fowl/game/templates/events.html b/fowl/game/templates/events.html index 217a076..816544a 100644 --- a/fowl/game/templates/events.html +++ b/fowl/game/templates/events.html @@ -41,7 +41,7 @@ PPVs, since the creation of this league.

{% for match, tp_list in event.match_list.items %} -

{{match}}

+

{{match.fancy}}

{{match.notes}}

diff --git a/fowl/game/tests.py b/fowl/game/tests.py index 1aa4bb7..ea7a148 100644 --- a/fowl/game/tests.py +++ b/fowl/game/tests.py @@ -135,17 +135,21 @@ class MatchTest(TestCase): self.event = Event.objects.create(name='Wrestlemania 29', date='2012-04-01') - def test_display(self): + def test_fancy_display(self): + # no contest match = self.event.add_match('tripleh', 'undertaker') - self.assertEqual(unicode(match), - 'Triple H vs. Undertaker (no contest)') + self.assertEqual(match.fancy(), + 'Triple H vs. Undertaker - fight to a no contest') + + # normal win match.record_win('undertaker', 'normal') - self.assertEqual(unicode(match), 'Triple H vs. Undertaker (v)') + self.assertEqual(match.fancy(), 'Undertaker defeats Triple H') _give_belt('cmpunk', 'wwe') - match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk', - outcome='normal') - self.assertEqual(unicode(match), 'CM Punk (c) (v) vs. Rey Mysterio') + match = self.event.add_match('cmpunk', 'reymysterio', 'danielbryan', + winner='cmpunk', outcome='submission') + self.assertEqual(match.fancy(), + 'CM Punk (WWE Champion) defeats Rey Mysterio, Daniel Bryan via submission') def test_to_dict(self): match = self.event.add_match('jimross', 'jerrylawler', 'michaelcole', @@ -216,7 +220,7 @@ class MatchTest(TestCase): # DQ : 1 point match = self.event.add_match('kane', 'undertaker', winner='undertaker', - outcome='DQ') + outcome='dq') self.assertEqual(match.points(), {'undertaker': 1, 'kane': 0}) # submission: +1 @@ -254,7 +258,7 @@ class MatchTest(TestCase): match = self.event.add_match(['kofikingston', 'rtruth'], ['jackswagger', 'dolphziggler'], winner='dolphziggler', - outcome='DQ') + outcome='dq') self.assertEqual(match.points(), {'jackswagger': 1, 'dolphziggler': 1, 'kofikingston': 0, @@ -336,7 +340,7 @@ class MatchTest(TestCase): # title non-defense (DQ/countout) match = self.event.add_match('christian', 'codyrhodes', - winner='codyrhodes', outcome='DQ', + winner='codyrhodes', outcome='dq', title_at_stake='ic') self.assertEqual(match.points(), {'codyrhodes': 1, 'christian': 1}) diff --git a/fowl/game/views.py b/fowl/game/views.py index 2f83690..15e7405 100644 --- a/fowl/game/views.py +++ b/fowl/game/views.py @@ -96,7 +96,7 @@ def league(request, league_id): 'teams': {team: 0 for team in teams}}, 'ic': {'name': None, 'points': 0, 'date': None, 'teams': {team: 0 for team in teams}}, - 'heavyweight': {'name': None, 'points': 0, 'date': None, + 'world': {'name': None, 'points': 0, 'date': None, 'teams': {team: 0 for team in teams}}, 'wwe': {'name': None, 'points': 0, 'date': None, 'teams': {team: 0 for team in teams}}, @@ -106,7 +106,7 @@ def league(request, league_id): # go over all events in order to determine belt holders for event in Event.objects.all().order_by('date'): # determine which belt is being competed for - belt_name = belt_mapping.get(event.name.lower(), 'heavyweight') + belt_name = belt_mapping.get(event.name.lower(), 'world') # get team scores for this event team_points = TeamPoints.objects.filter(match__event=event ).values('team__name').annotate(points=Sum('points')) @@ -132,7 +132,7 @@ def league(request, league_id): belts[belt_name]['name'] = ew belts[belt_name]['date'] = event.date # do WWE belt check on PPVs - if belt_name == 'heavyweight': + if belt_name == 'world': belt_name = 'wwe' if belts[belt_name]['teams'][ew] > belts[belt_name]['points']: belts[belt_name]['points'] = belts[belt_name]['teams'][ew] diff --git a/setup_league.py b/setup_league.py index b928ab2..bd907b0 100644 --- a/setup_league.py +++ b/setup_league.py @@ -8,7 +8,7 @@ Team.objects.all().delete() Event.objects.all().delete() _give_belt('cmpunk', 'wwe') -_give_belt('sheamus', 'heavyweight') +_give_belt('sheamus', 'world') _give_belt('kofikingston', 'tag') _give_belt('rtruth', 'tag') _give_belt('layla', 'diva') @@ -56,7 +56,7 @@ event.add_match(['brodusclay', 'kofikingston', 'rtruth'], ['themiz', 'jackswagger', 'dolphziggler'], winner='brodusclay', outcome='normal') event.add_match('chrisjericho', 'randyorton', - winner='chrisjericho', outcome='DQ', + winner='chrisjericho', outcome='dq', notes='Sheamus interfered, giving Jericho the win') event.add_match('paulheyman', outcome='appearance', notes='Paul Heyman is going to sue for Bork Laser') @@ -93,7 +93,7 @@ event.add_match('layla', 'bethphoenix', winner='layla', outcome='normal', title_at_stake='diva') event.add_match('sheamus', 'randyorton', 'chrisjericho', 'albertodelrio', winner='sheamus', outcome='normal', - title_at_stake='heavyweight') + title_at_stake='world') event.add_match('brodusclay', 'themiz', winner='brodusclay', outcome='normal') m = event.add_match('christian', 'codyrhodes', winner='christian', outcome='normal', title_at_stake='ic') @@ -113,8 +113,8 @@ event.add_match('davidotunga', 'johncena', winner='johncena', # Brawl: Tyler Reks & Curt Hawkins & Titus O'Neil & Daren Young & Sheamus # Brawl: Santino vs. Ricardo event.add_match('albertodelrio', 'randyorton', winner='randyorton', - outcome='DQ', notes='Jericho codebreaks RKO, Orton wins') -event.add_match('danielbryan', 'kane', winner='danielbryan', outcome='DQ', + outcome='dq', notes='Jericho codebreaks RKO, Orton wins') +event.add_match('danielbryan', 'kane', winner='danielbryan', outcome='dq', notes='Kane uses chair, Bryan wins') event.add_match('christian', 'jindermahal', winner='christian', outcome='normal') event.add_match('bethphoenix', 'kellykelly', winner='bethphoenix',