diff --git a/fowl/game/admin.py b/fowl/game/admin.py index fa91f1d..d93f864 100644 --- a/fowl/game/admin.py +++ b/fowl/game/admin.py @@ -2,6 +2,7 @@ from django.contrib import admin from .models import Star, Match, Event, League, Team + class StarAdmin(admin.ModelAdmin): list_display = ('name', 'division') list_filter = ('division',) @@ -10,6 +11,7 @@ admin.site.register(Star, StarAdmin) admin.site.register(Match) admin.site.register(Event) + class TeamAdmin(admin.ModelAdmin): list_display = ('name', 'league') list_filter = ('league',) diff --git a/fowl/game/management/commands/loadstars.py b/fowl/game/management/commands/loadstars.py index e2c4578..178d081 100644 --- a/fowl/game/management/commands/loadstars.py +++ b/fowl/game/management/commands/loadstars.py @@ -4,6 +4,7 @@ import lxml.html from ...models import Star + class Command(NoArgsCommand): def handle_noargs(self, **options): @@ -28,5 +29,5 @@ class Command(NoArgsCommand): id = url.rsplit('/', 1)[-1] photo_url = url + div.xpath('a/img/@data-fullsrc')[0] - star = Star.objects.create(id=id, name=name, division=division, - photo_url=photo_url) + Star.objects.create(id=id, name=name, division=division, + photo_url=photo_url) diff --git a/fowl/game/models.py b/fowl/game/models.py index 2295101..71cba79 100644 --- a/fowl/game/models.py +++ b/fowl/game/models.py @@ -1,4 +1,3 @@ -from collections import defaultdict from django.db import models from django.contrib.auth.models import User @@ -20,6 +19,7 @@ TITLES = (('wwe', 'WWE'), ('diva', 'Divas'), ) + class Star(models.Model): id = models.CharField(max_length=100, primary_key=True) name = models.CharField(max_length=200) @@ -171,7 +171,8 @@ class Match(models.Model): points[w.id] += 10 else: # defense by DQ - for star in title_teams[self.title_at_stake].members.all(): + 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 @@ -200,6 +201,7 @@ class Match(models.Model): ret += ' (no contest)' return ret + class MatchTeam(models.Model): members = models.ManyToManyField(Star) match = models.ForeignKey(Match, related_name='teams') diff --git a/fowl/game/tests.py b/fowl/game/tests.py index 53a2b50..1b3aae5 100644 --- a/fowl/game/tests.py +++ b/fowl/game/tests.py @@ -1,18 +1,19 @@ 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, Star +from .models import Event, League, Team, TeamPoints, Star + def _give_belt(star, belt): Star.objects.get(pk=star).win_title(belt) + class StarTest(TestCase): def test_win_title(self): - cmpunk = Star.objects.create(pk='cmpunk', name='CM Punk', title='wwe') + Star.objects.create(pk='cmpunk', name='CM Punk', title='wwe') dbry = Star.objects.create(pk='danielbryan', name='Daniel Bryan') - kofi = Star.objects.create(pk='kofi', name='Kofi Kingston', + Star.objects.create(pk='kofi', name='Kofi Kingston', title='tag') - rtruth = Star.objects.create(pk='rtruth', name='R Truth', title='tag') + Star.objects.create(pk='rtruth', name='R Truth', title='tag') swagger = Star.objects.create(pk='swagger', name='Jack Swagger') ziggler = Star.objects.create(pk='ziggler', name='Dolph Ziggler') @@ -36,7 +37,8 @@ class MatchTest(TestCase): fixtures = ['testdata'] def setUp(self): - self.event = Event.objects.create(name='Wrestlemania 29', date='2012-04-01') + self.event = Event.objects.create(name='Wrestlemania 29', + date='2012-04-01') def test_basics(self): match = self.event.add_match('tripleh', 'undertaker') @@ -50,7 +52,6 @@ class MatchTest(TestCase): outcome='normal') self.assertEqual(unicode(match), 'CM Punk (c) (v) vs. Rey Mysterio') - def test_do_title_change(self): # title to punk match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk', @@ -96,8 +97,7 @@ class MatchTest(TestCase): 'chrisjericho', winner='sheamus', outcome='normal') self.assertEqual(match.points(), {'sheamus': 6, 'randyorton': 0, - 'albertodelrio': 0, 'chrisjericho': 0} - ) + 'albertodelrio': 0, 'chrisjericho': 0}) # win stacked match: 1 point for team (bonuses can apply) match = self.event.add_match('santinomarella', ['markhenry', 'kane'], @@ -292,11 +292,16 @@ class LeagueTest(TestCase): self.league.score_event(event) # check TeamPoints objects - self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='reymysterio').points, 0) - self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='santinomarella').points, 1) - 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) + self.assertEqual(TeamPoints.objects.get(team=self.teddy, + star__pk='reymysterio').points, 0) + self.assertEqual(TeamPoints.objects.get(team=self.teddy, + star__pk='santinomarella').points, 1) + 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) # rename the event and rescore event.name = 'Wrestlemania' @@ -306,8 +311,13 @@ class LeagueTest(TestCase): self.league.score_event(event) # all should be one higher than before - self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='reymysterio').points, 1) - self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='santinomarella').points, 2) - self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match1, star__pk='sin-cara').points, 3) - self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match3, star__pk='sin-cara').points, 13) - self.assertEqual(TeamPoints.objects.get(team=self.johnny, star__pk='markhenry').points, 1) + self.assertEqual(TeamPoints.objects.get(team=self.teddy, + star__pk='reymysterio').points, 1) + self.assertEqual(TeamPoints.objects.get(team=self.teddy, + star__pk='santinomarella').points, 2) + self.assertEqual(TeamPoints.objects.get(team=self.johnny, + match=match1, star__pk='sin-cara').points, 3) + self.assertEqual(TeamPoints.objects.get(team=self.johnny, + match=match3, star__pk='sin-cara').points, 13) + self.assertEqual(TeamPoints.objects.get(team=self.johnny, + star__pk='markhenry').points, 1) diff --git a/fowl/game/urls.py b/fowl/game/urls.py index 68d235f..8fabf2c 100644 --- a/fowl/game/urls.py +++ b/fowl/game/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import patterns, include, url +from django.conf.urls import patterns, url urlpatterns = patterns('', url(r'events/(?P\d+)/$', 'fowl.game.views.events', diff --git a/fowl/game/views.py b/fowl/game/views.py index 17e0853..b4d22e2 100644 --- a/fowl/game/views.py +++ b/fowl/game/views.py @@ -1,7 +1,6 @@ -from collections import defaultdict from itertools import izip_longest from django.shortcuts import render, get_object_or_404 -from fowl.game.models import Team, TeamPoints, Star +from fowl.game.models import Team, TeamPoints, Star, Event def events(request, league_id): @@ -21,6 +20,7 @@ def events(request, league_id): events = sorted(events.values(), key=lambda x: x.date, reverse=True) return render(request, "events.html", {'events': events, 'view': 'events'}) + def edit_event(request, event_id=None): if event_id: event = get_object_or_404(Event, pk=event_id) @@ -29,6 +29,7 @@ def edit_event(request, event_id=None): if request.method == 'GET': return render(request, "edit_event.html", {"event": event}) + def league(request, league_id): context = { 'view': 'league', @@ -41,6 +42,7 @@ def league(request, league_id): for team in teams)) return render(request, "stables.html", context) + def roster(request): context = { 'stars': Star.objects.all() diff --git a/fowl/settings.py b/fowl/settings.py index aa4dd4d..bef5977 100644 --- a/fowl/settings.py +++ b/fowl/settings.py @@ -90,7 +90,6 @@ ROOT_URLCONF = 'fowl.urls' WSGI_APPLICATION = 'fowl.wsgi.application' TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. )