avoid multiple overlapping title reigns

This commit is contained in:
James Turk 2012-05-30 21:39:06 -04:00
parent ea42891892
commit e0ec71cc31
2 changed files with 11 additions and 0 deletions

View File

@ -33,6 +33,11 @@ class Star(models.Model):
return self.division != 'other'
def win_title(self, title, date, tag_partner=None):
# if they have title on that date (or won it then), don't add anything
if (self.has_title(date) or
self.reigns.filter(title=title, begin_date=date).count()):
return
# end current title reigns
TitleReign.objects.filter(title=title).update(end_date=date)
self.reigns.create(title=title, begin_date=date)

View File

@ -25,6 +25,12 @@ class StarTest(TestCase):
self.assertEqual(Star.objects.get(pk='cmpunk').has_title(), None)
self.assertEqual(Star.objects.get(pk='danielbryan').has_title(), 'wwe')
# test multiple win does nothing
dbry.win_title('wwe', datetime.date(2012,1,1))
dbry.win_title('wwe', datetime.date(2012,2,1))
dbry.win_title('wwe', datetime.date(2012,3,1))
self.assertEqual(dbry.reigns.count(), 1)
# tag belt win
self.assertEqual(Star.objects.get(pk='kofi').has_title(), 'tag')
self.assertEqual(Star.objects.get(pk='rtruth').has_title(), 'tag')