avoid multiple overlapping title reigns
This commit is contained in:
parent
ea42891892
commit
e0ec71cc31
@ -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)
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user