Merge branch 'master' of github.com:jamesturk/fowl

This commit is contained in:
Erin Braswell 2012-05-28 02:21:31 -04:00
commit 905e1ff14a
4 changed files with 69 additions and 54 deletions

View File

@ -4,8 +4,7 @@ from django.contrib.auth.models import User
# these things are independent of the game
OUTCOMES = (
('no contest', 'no contest'),
OUTCOMES = (('no contest', 'no contest'),
('normal', 'normal'),
('DQ', 'DQ'),
('submission', 'submission'),
@ -53,7 +52,7 @@ class Event(models.Model):
def add_match(self, *teams, **kwargs):
winner = kwargs.get('winner', None)
outcome = kwargs.get('outcome', '')
title_at_stake = kwargs.get('title_at_stake', False)
title_at_stake = kwargs.get('title_at_stake', None)
notes = kwargs.get('notes', '')
match = Match.objects.create(event=self,
@ -89,7 +88,7 @@ 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)
title_at_stake = models.BooleanField(default=False)
title_at_stake = models.CharField(max_length=50, choices=TITLES, null=True)
notes = models.TextField(blank=True, default='')
def record_win(self, star, outcome):
@ -100,6 +99,16 @@ class Match(models.Model):
self.outcome = outcome
self.save()
def do_title_change(self):
if self.title_at_stake:
victors = list(self.teams.get(victorious=True).members.all())
if len(victors) == 1:
victor[0].win_title(self.title_at_stake)
elif len(victors) == 2 and self.title_at_stake == 'tag':
victor[0].win_title(self.title_at_stake, victor[1])
else:
raise ValueError('invalid number of victors for title change')
def points(self):
points = {}
winners = None
@ -147,39 +156,41 @@ class Match(models.Model):
for w in winners.members.all():
points[w.id] = base_points
# if multiple people in this match and this person was credited
# w/ win, give them the bonus points
if allies and w.id == self.winner_id:
points[w.id] += 1
if w.id == self.winner_id and self.outcome == 'submission':
points[w.id] += 1
# look over all titles in this match
for title, title_team in title_teams.iteritems():
if self.title_at_stake:
if winners.title == self.title_at_stake:
# title defense
if winners.title == title and self.title_at_stake:
if title in ('heavyweight', 'wwe'):
if winners.title in ('heavyweight', 'wwe'):
points[w.id] += 5
else:
points[w.id] += 3
# beat someone w/ title
elif winners.title != title:
# title win
if self.title_at_stake and self.outcome != 'DQ':
if title in ('heavyweight', 'wwe'):
elif self.outcome in ('normal', 'submission'):
# title win!
if self.title_at_stake in ('heavyweight', 'wwe'):
points[w.id] += 20
else:
points[w.id] += 10
# title team gets a point if they defend title by DQ
elif self.title_at_stake and self.outcome == 'DQ':
for star in title_team.members.all():
else:
# defense by DQ
for star in title_teams[self.title_at_stake].members.all():
points[star.id] += 1
else:
# look over titles in match, to score a title-nondefense
for title, title_team in title_teams.iteritems():
# beat someone w/ title in a non-defense
if winners.title != title:
# beat tag champs in tag match w/o tag belt on line
elif title == 'tag' and all(c == 2 for c in losers):
if title == 'tag' and all(c == 2 for c in losers):
points[w.id] += 2
# beat champ in non-handicap match w/o belt on line
elif all(c == 1 for c in losers):
points[w.id] += 2
# if multiple people in this match and this person was credited
# w/ win, give them the bonus points
if allies:
points[self.winner_id] += 1
if self.outcome == 'submission':
points[self.winner_id] += 1
return points
def __unicode__(self):
@ -208,6 +219,7 @@ class MatchTeam(models.Model):
class League(models.Model):
name = models.CharField(max_length=100)
active = models.BooleanField(default=True)
raw_picks = models.IntegerField(default=3)
smackdown_picks = models.IntegerField(default=3)
diva_picks = models.IntegerField(default=2)

View File

@ -17,7 +17,9 @@
<table class="table">
<thead>
<tr>
<td class="belt-img" colspan="2"><img src="{% get_static_prefix %}images/{{belt}}.png"></td>
<td class="belt-img" colspan="2">
<img src="{% get_static_prefix %}images/{{belt}}.png">
</td>
</tr>
</thead>
<tody>

View File

@ -170,31 +170,31 @@ class MatchTest(TestCase):
# defending wwe belt is worth +5
match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk',
outcome='normal', title_at_stake=True)
outcome='normal', title_at_stake='wwe')
self.assertEqual(match.points(), {'cmpunk': 7, 'reymysterio': 0})
# winning wwe belt
match = self.event.add_match('cmpunk', 'reymysterio',
winner='reymysterio', outcome='normal',
title_at_stake=True)
title_at_stake='wwe')
self.assertEqual(match.points(), {'reymysterio': 22, 'cmpunk': 0})
# defending other belt is worth +3
match = self.event.add_match('christian', 'codyrhodes',
winner='christian', outcome='normal',
title_at_stake=True)
title_at_stake='ic')
self.assertEqual(match.points(), {'christian': 5, 'codyrhodes': 0})
# winning other belt is worth +10
match = self.event.add_match('christian', 'codyrhodes',
winner='codyrhodes', outcome='normal',
title_at_stake=True)
title_at_stake='ic')
self.assertEqual(match.points(), {'codyrhodes': 12, 'christian': 0})
# title non-defense (DQ/countout)
match = self.event.add_match('christian', 'codyrhodes',
winner='codyrhodes', outcome='DQ',
title_at_stake=True)
title_at_stake='ic')
self.assertEqual(match.points(), {'codyrhodes': 1, 'christian': 1})
# no bonus in a tag match
@ -215,7 +215,7 @@ class MatchTest(TestCase):
match = self.event.add_match(['kofikingston', 'rtruth'],
['reymysterio', 'sin-cara'],
winner='reymysterio', outcome='normal',
title_at_stake=True)
title_at_stake='tag')
self.assertEqual(match.points(), {'sin-cara': 12, 'reymysterio': 13,
'kofikingston': 0, 'rtruth': 0})
@ -253,7 +253,7 @@ class LeagueTest(TestCase):
match2 = event.add_match('markhenry', ['santinomarella', 'mickfoley'],
winner='mickfoley', outcome='normal')
_give_belt('codyrhodes', 'ic')
match3 = event.add_match('sin-cara', 'codyrhodes', title_at_stake=True,
match3 = event.add_match('sin-cara', 'codyrhodes', title_at_stake='ic',
winner='sin-cara', outcome='normal')
self.league.score_event(event)

View File

@ -84,17 +84,18 @@ event.add_match('alexriley', 'christian', 'curthawkins', 'darrenyoung',
'tylerreks', 'tysonkidd', 'williamregal', 'yoshitatsu',
winner='christian', outcome='normal')
event.add_match(['kofikingston', 'rtruth'], ['dolphziggler', 'jackswagger'],
winner='kofikingston', outcome='normal', title_at_stake=True)
winner='kofikingston', outcome='normal', title_at_stake='tag')
event.add_match('layla', 'bethphoenix', winner='layla',
outcome='normal', title_at_stake=True)
outcome='normal', title_at_stake='divas')
event.add_match('sheamus', 'randyorton', 'chrisjericho', 'albertodelrio',
winner='sheamus', outcome='normal', title_at_stake=True)
winner='sheamus', outcome='normal',
title_at_stake='heavyweight')
event.add_match('brodusclay', 'themiz', winner='brodusclay', outcome='normal')
event.add_match('christian', 'codyrhodes', winner='christian', outcome='normal',
title_at_stake=True)
event.add_match('christian', 'codyrhodes', winner='christian',
outcome='normal', title_at_stake='ic')
_give_belt('christian', 'ic')
event.add_match('cmpunk', 'danielbryan', winner='cmpunk', outcome='normal',
title_at_stake=True)
title_at_stake='wwe')
event.add_match('ryback', 'camacho', winner='ryback', outcome='normal')
event.add_match('john-laurinaitis', 'johncena', 'bigshow',
winner='john-laurinaitis',