lots of cleanup

This commit is contained in:
James Turk 2012-05-28 13:11:02 -04:00
parent aaf31a80b7
commit ba2857d370
7 changed files with 43 additions and 27 deletions

View File

@ -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',)

View File

@ -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)

View File

@ -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')

View File

@ -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)

View File

@ -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<league_id>\d+)/$', 'fowl.game.views.events',

View File

@ -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()

View File

@ -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.
)