lots of cleanup
This commit is contained in:
parent
aaf31a80b7
commit
ba2857d370
@ -2,6 +2,7 @@ from django.contrib import admin
|
|||||||
|
|
||||||
from .models import Star, Match, Event, League, Team
|
from .models import Star, Match, Event, League, Team
|
||||||
|
|
||||||
|
|
||||||
class StarAdmin(admin.ModelAdmin):
|
class StarAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'division')
|
list_display = ('name', 'division')
|
||||||
list_filter = ('division',)
|
list_filter = ('division',)
|
||||||
@ -10,6 +11,7 @@ admin.site.register(Star, StarAdmin)
|
|||||||
admin.site.register(Match)
|
admin.site.register(Match)
|
||||||
admin.site.register(Event)
|
admin.site.register(Event)
|
||||||
|
|
||||||
|
|
||||||
class TeamAdmin(admin.ModelAdmin):
|
class TeamAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'league')
|
list_display = ('name', 'league')
|
||||||
list_filter = ('league',)
|
list_filter = ('league',)
|
||||||
|
@ -4,6 +4,7 @@ import lxml.html
|
|||||||
|
|
||||||
from ...models import Star
|
from ...models import Star
|
||||||
|
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(NoArgsCommand):
|
||||||
|
|
||||||
def handle_noargs(self, **options):
|
def handle_noargs(self, **options):
|
||||||
@ -28,5 +29,5 @@ class Command(NoArgsCommand):
|
|||||||
id = url.rsplit('/', 1)[-1]
|
id = url.rsplit('/', 1)[-1]
|
||||||
photo_url = url + div.xpath('a/img/@data-fullsrc')[0]
|
photo_url = url + div.xpath('a/img/@data-fullsrc')[0]
|
||||||
|
|
||||||
star = Star.objects.create(id=id, name=name, division=division,
|
Star.objects.create(id=id, name=name, division=division,
|
||||||
photo_url=photo_url)
|
photo_url=photo_url)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from collections import defaultdict
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
@ -20,6 +19,7 @@ TITLES = (('wwe', 'WWE'),
|
|||||||
('diva', 'Divas'),
|
('diva', 'Divas'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Star(models.Model):
|
class Star(models.Model):
|
||||||
id = models.CharField(max_length=100, primary_key=True)
|
id = models.CharField(max_length=100, primary_key=True)
|
||||||
name = models.CharField(max_length=200)
|
name = models.CharField(max_length=200)
|
||||||
@ -171,7 +171,8 @@ class Match(models.Model):
|
|||||||
points[w.id] += 10
|
points[w.id] += 10
|
||||||
else:
|
else:
|
||||||
# defense by DQ
|
# 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
|
points[star.id] += 1
|
||||||
else:
|
else:
|
||||||
# look over titles in match, to score a title-nondefense
|
# look over titles in match, to score a title-nondefense
|
||||||
@ -200,6 +201,7 @@ class Match(models.Model):
|
|||||||
ret += ' (no contest)'
|
ret += ' (no contest)'
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class MatchTeam(models.Model):
|
class MatchTeam(models.Model):
|
||||||
members = models.ManyToManyField(Star)
|
members = models.ManyToManyField(Star)
|
||||||
match = models.ForeignKey(Match, related_name='teams')
|
match = models.ForeignKey(Match, related_name='teams')
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.core.management import call_command
|
|
||||||
from django.contrib.auth.models import User
|
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):
|
def _give_belt(star, belt):
|
||||||
Star.objects.get(pk=star).win_title(belt)
|
Star.objects.get(pk=star).win_title(belt)
|
||||||
|
|
||||||
|
|
||||||
class StarTest(TestCase):
|
class StarTest(TestCase):
|
||||||
def test_win_title(self):
|
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')
|
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')
|
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')
|
swagger = Star.objects.create(pk='swagger', name='Jack Swagger')
|
||||||
ziggler = Star.objects.create(pk='ziggler', name='Dolph Ziggler')
|
ziggler = Star.objects.create(pk='ziggler', name='Dolph Ziggler')
|
||||||
|
|
||||||
@ -36,7 +37,8 @@ class MatchTest(TestCase):
|
|||||||
fixtures = ['testdata']
|
fixtures = ['testdata']
|
||||||
|
|
||||||
def setUp(self):
|
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):
|
def test_basics(self):
|
||||||
match = self.event.add_match('tripleh', 'undertaker')
|
match = self.event.add_match('tripleh', 'undertaker')
|
||||||
@ -50,7 +52,6 @@ class MatchTest(TestCase):
|
|||||||
outcome='normal')
|
outcome='normal')
|
||||||
self.assertEqual(unicode(match), 'CM Punk (c) (v) vs. Rey Mysterio')
|
self.assertEqual(unicode(match), 'CM Punk (c) (v) vs. Rey Mysterio')
|
||||||
|
|
||||||
|
|
||||||
def test_do_title_change(self):
|
def test_do_title_change(self):
|
||||||
# title to punk
|
# title to punk
|
||||||
match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk',
|
match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk',
|
||||||
@ -96,8 +97,7 @@ class MatchTest(TestCase):
|
|||||||
'chrisjericho', winner='sheamus',
|
'chrisjericho', winner='sheamus',
|
||||||
outcome='normal')
|
outcome='normal')
|
||||||
self.assertEqual(match.points(), {'sheamus': 6, 'randyorton': 0,
|
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)
|
# win stacked match: 1 point for team (bonuses can apply)
|
||||||
match = self.event.add_match('santinomarella', ['markhenry', 'kane'],
|
match = self.event.add_match('santinomarella', ['markhenry', 'kane'],
|
||||||
@ -292,11 +292,16 @@ class LeagueTest(TestCase):
|
|||||||
self.league.score_event(event)
|
self.league.score_event(event)
|
||||||
|
|
||||||
# check TeamPoints objects
|
# check TeamPoints objects
|
||||||
self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='reymysterio').points, 0)
|
self.assertEqual(TeamPoints.objects.get(team=self.teddy,
|
||||||
self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='santinomarella').points, 1)
|
star__pk='reymysterio').points, 0)
|
||||||
self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match1, star__pk='sin-cara').points, 2)
|
self.assertEqual(TeamPoints.objects.get(team=self.teddy,
|
||||||
self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match3, star__pk='sin-cara').points, 12)
|
star__pk='santinomarella').points, 1)
|
||||||
self.assertEqual(TeamPoints.objects.get(team=self.johnny, star__pk='markhenry').points, 0)
|
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
|
# rename the event and rescore
|
||||||
event.name = 'Wrestlemania'
|
event.name = 'Wrestlemania'
|
||||||
@ -306,8 +311,13 @@ class LeagueTest(TestCase):
|
|||||||
|
|
||||||
self.league.score_event(event)
|
self.league.score_event(event)
|
||||||
# all should be one higher than before
|
# 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,
|
||||||
self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='santinomarella').points, 2)
|
star__pk='reymysterio').points, 1)
|
||||||
self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match1, star__pk='sin-cara').points, 3)
|
self.assertEqual(TeamPoints.objects.get(team=self.teddy,
|
||||||
self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match3, star__pk='sin-cara').points, 13)
|
star__pk='santinomarella').points, 2)
|
||||||
self.assertEqual(TeamPoints.objects.get(team=self.johnny, star__pk='markhenry').points, 1)
|
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)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from django.conf.urls import patterns, include, url
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'events/(?P<league_id>\d+)/$', 'fowl.game.views.events',
|
url(r'events/(?P<league_id>\d+)/$', 'fowl.game.views.events',
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from collections import defaultdict
|
|
||||||
from itertools import izip_longest
|
from itertools import izip_longest
|
||||||
from django.shortcuts import render, get_object_or_404
|
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):
|
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)
|
events = sorted(events.values(), key=lambda x: x.date, reverse=True)
|
||||||
return render(request, "events.html", {'events': events, 'view': 'events'})
|
return render(request, "events.html", {'events': events, 'view': 'events'})
|
||||||
|
|
||||||
|
|
||||||
def edit_event(request, event_id=None):
|
def edit_event(request, event_id=None):
|
||||||
if event_id:
|
if event_id:
|
||||||
event = get_object_or_404(Event, pk=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':
|
if request.method == 'GET':
|
||||||
return render(request, "edit_event.html", {"event": event})
|
return render(request, "edit_event.html", {"event": event})
|
||||||
|
|
||||||
|
|
||||||
def league(request, league_id):
|
def league(request, league_id):
|
||||||
context = {
|
context = {
|
||||||
'view': 'league',
|
'view': 'league',
|
||||||
@ -41,6 +42,7 @@ def league(request, league_id):
|
|||||||
for team in teams))
|
for team in teams))
|
||||||
return render(request, "stables.html", context)
|
return render(request, "stables.html", context)
|
||||||
|
|
||||||
|
|
||||||
def roster(request):
|
def roster(request):
|
||||||
context = {
|
context = {
|
||||||
'stars': Star.objects.all()
|
'stars': Star.objects.all()
|
||||||
|
@ -90,7 +90,6 @@ ROOT_URLCONF = 'fowl.urls'
|
|||||||
WSGI_APPLICATION = 'fowl.wsgi.application'
|
WSGI_APPLICATION = 'fowl.wsgi.application'
|
||||||
|
|
||||||
TEMPLATE_DIRS = (
|
TEMPLATE_DIRS = (
|
||||||
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
|
||||||
# Always use forward slashes, even on Windows.
|
# Always use forward slashes, even on Windows.
|
||||||
# Don't forget to use absolute paths, not relative paths.
|
# Don't forget to use absolute paths, not relative paths.
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user