add_match
This commit is contained in:
parent
f2c168b0c9
commit
3829147bfb
@ -3,11 +3,23 @@ from django.db import models
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
WIN_TYPES = (('pin', 'pin'),
|
||||
('DQ', 'DQ'),
|
||||
('submission', 'submission'))
|
||||
TITLES = (('wwe', 'WWE'),
|
||||
('heavyweight', 'Heavyweight'),
|
||||
('ic', 'Intercontinental'),
|
||||
('us', 'United States'),
|
||||
('tag', 'Tag Team'),
|
||||
('diva', 'Divas'),
|
||||
)
|
||||
|
||||
class Star(models.Model):
|
||||
id = models.CharField(max_length=100, primary_key=True)
|
||||
name = models.CharField(max_length=200)
|
||||
photo_url = models.URLField()
|
||||
division = models.CharField(max_length=100)
|
||||
title = models.CharField(max_length=20, choices=TITLES)
|
||||
active = models.BooleanField()
|
||||
|
||||
def drafted(self, league):
|
||||
@ -77,32 +89,26 @@ class Event(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
date = models.DateField()
|
||||
|
||||
def points(self):
|
||||
total = defaultdict(int)
|
||||
for match in self.matches.all():
|
||||
for star, points in match.points().iteritems():
|
||||
total[star] += points
|
||||
# PPV bonus
|
||||
if self.name.lower() not in ('smackdown', 'raw'):
|
||||
for star in total:
|
||||
total[star] += 1
|
||||
return total
|
||||
def add_match(self, *teams, **kwargs):
|
||||
winner = kwargs.get('winner', None)
|
||||
win_type = kwargs.get('win_type', None)
|
||||
title_at_stake = kwargs.get('title_at_stake', False)
|
||||
|
||||
match = Match.objects.create(event=self, title_at_stake=title_at_stake)
|
||||
for team in teams:
|
||||
if isinstance(team, (list, tuple)):
|
||||
match.add_team(*team)
|
||||
else:
|
||||
match.add_team(team)
|
||||
if winner:
|
||||
match.record_win(winner, win_type)
|
||||
return match
|
||||
|
||||
def __unicode__(self):
|
||||
return '{0} {1}'.format(self.name, self.date)
|
||||
|
||||
admin.site.register(Event)
|
||||
|
||||
WIN_TYPES = (('pin', 'pin'),
|
||||
('DQ', 'DQ'),
|
||||
('submission', 'submission'))
|
||||
TITLES = (('wwe', 'WWE'),
|
||||
('heavyweight', 'Heavyweight'),
|
||||
('ic', 'Intercontinental'),
|
||||
('us', 'United States'),
|
||||
('tag', 'Tag Team'),
|
||||
('diva', 'Divas'),
|
||||
)
|
||||
class Match(models.Model):
|
||||
event = models.ForeignKey(Event, related_name='matches')
|
||||
winner = models.ForeignKey(Star, null=True)
|
||||
@ -114,12 +120,15 @@ class Match(models.Model):
|
||||
mt = MatchTeam.objects.create(match=self, title=title)
|
||||
for member in members:
|
||||
member = Star.objects.get(pk=member)
|
||||
if not mt.title and member.title:
|
||||
mt.title = member.title
|
||||
mt.save()
|
||||
mt.members.add(member)
|
||||
|
||||
def record_win(self, star, win_type):
|
||||
self.teams.filter(members__pk=star).update(victorious=True)
|
||||
self.win_type = win_type
|
||||
self.winner_id = star
|
||||
self.win_type = win_type
|
||||
self.save()
|
||||
|
||||
def points(self):
|
||||
|
@ -1,7 +1,7 @@
|
||||
from django.test import TestCase
|
||||
from django.core.management import call_command
|
||||
from django.contrib.auth.models import User
|
||||
from .models import Match, Event, League, Team, TeamPoints
|
||||
from .models import Match, Event, League, Team, TeamPoints, Star
|
||||
|
||||
class MatchTest(TestCase):
|
||||
fixtures = ['testdata']
|
||||
@ -225,18 +225,13 @@ class LeagueTest(TestCase):
|
||||
self.johnny.add_star(pk='sin-cara')
|
||||
self.johnny.add_star(pk='markhenry')
|
||||
event = Event.objects.create(name='smackdown', date='2012-01-01')
|
||||
match1 = Match.objects.create(event=event)
|
||||
match1.add_team('reymysterio')
|
||||
match1.add_team('sin-cara')
|
||||
match1.record_win('sin-cara', 'pin')
|
||||
match2 = Match.objects.create(event=event)
|
||||
match2.add_team('santinomarella', 'mickfoley')
|
||||
match2.add_team('markhenry')
|
||||
match2.record_win('mickfoley', 'pin')
|
||||
match3 = Match.objects.create(event=event, title_at_stake=True)
|
||||
match3.add_team('codyrhodes', title='ic')
|
||||
match3.add_team('sin-cara')
|
||||
match3.record_win('sin-cara', 'pin')
|
||||
match1 = event.add_match('reymysterio', 'sin-cara', winner='sin-cara',
|
||||
win_type='pin')
|
||||
match2 = event.add_match('markhenry', ['santinomarella', 'mickfoley'],
|
||||
winner='mickfoley', win_type='pin')
|
||||
Star.objects.filter(pk='codyrhodes').update(title='ic')
|
||||
match3 = event.add_match('sin-cara', 'codyrhodes', title_at_stake=True,
|
||||
winner='sin-cara', win_type='pin')
|
||||
self.league.score_event(event)
|
||||
|
||||
# check TeamPoints objects
|
||||
@ -245,8 +240,6 @@ class LeagueTest(TestCase):
|
||||
self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match1, star__pk='sin-cara').points, 2)
|
||||
self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match3, star__pk='sin-cara').points, 12)
|
||||
self.assertEqual(TeamPoints.objects.get(team=self.johnny, star__pk='markhenry').points, 0)
|
||||
for obj in TeamPoints.objects.all():
|
||||
print obj
|
||||
|
||||
# rename the event and rescore
|
||||
event.name = 'Wrestlemania'
|
||||
|
@ -16,17 +16,14 @@ cobra = Team.objects.create(name='COBRA!', login=erin, league=league)
|
||||
punks = ('cmpunk', 'kane', 'rtruth', 'codyrhodes', 'sin-cara', 'antoniocesaro',
|
||||
'wadebarrett', 'aj', 'bethphoenix')
|
||||
for person in punks:
|
||||
print person
|
||||
gm_punk.add_star(pk=person)
|
||||
|
||||
awesomes = ('chrisjericho', 'sheamus', 'danielbryan', 'ryback', 'damien-sandow',
|
||||
'kharma', 'kellykelly', 'brodusclay', 'johncena')
|
||||
for person in awesomes:
|
||||
print person
|
||||
awesome.add_star(pk=person)
|
||||
|
||||
cobras = ('santinomarella', 'dolphziggler', 'kofikingston', 'albertodelrio',
|
||||
'randyorton', 'bigshow', 'christian', 'layla', 'natalya')
|
||||
for person in cobras:
|
||||
print person
|
||||
cobra.add_star(pk=person)
|
Loading…
Reference in New Issue
Block a user