initial fowl
This commit is contained in:
commit
de1f312570
0
fowl/__init__.py
Normal file
0
fowl/__init__.py
Normal file
0
fowl/game/__init__.py
Normal file
0
fowl/game/__init__.py
Normal file
0
fowl/game/management/__init__.py
Normal file
0
fowl/game/management/__init__.py
Normal file
0
fowl/game/management/commands/__init__.py
Normal file
0
fowl/game/management/commands/__init__.py
Normal file
33
fowl/game/management/commands/loadstars.py
Normal file
33
fowl/game/management/commands/loadstars.py
Normal file
@ -0,0 +1,33 @@
|
||||
from django.core.management.base import NoArgsCommand
|
||||
import scrapelib
|
||||
import lxml.html
|
||||
|
||||
from ...models import Star
|
||||
|
||||
class Command(NoArgsCommand):
|
||||
|
||||
def handle_noargs(self, **options):
|
||||
url = 'http://www.wwe.com/superstars'
|
||||
data = scrapelib.urlopen(url)
|
||||
doc = lxml.html.fromstring(data)
|
||||
doc.make_links_absolute(url)
|
||||
|
||||
for div in doc.xpath('//div[starts-with(@class, "star ")]'):
|
||||
cssclass = div.get('class')
|
||||
if 'letter-champion' in cssclass:
|
||||
continue
|
||||
# get division
|
||||
divisions = ('divas', 'raw', 'smackdown')
|
||||
for division in divisions:
|
||||
if division in cssclass:
|
||||
break
|
||||
else:
|
||||
division = 'other'
|
||||
name = div.xpath('h2')[0].text_content().strip()
|
||||
url = div.xpath('a/@href')[0]
|
||||
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,
|
||||
active=(division != 'other'))
|
89
fowl/game/models.py
Normal file
89
fowl/game/models.py
Normal file
@ -0,0 +1,89 @@
|
||||
from django.db import models
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
class Star(models.Model):
|
||||
id = models.CharField(max_length=100, primary_key=True)
|
||||
name = models.CharField(max_length=200)
|
||||
photo_url = models.URLField()
|
||||
division = models.CharField(max_length=100)
|
||||
active = models.BooleanField()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class StarAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'division', 'active')
|
||||
list_filter = ('division', 'active')
|
||||
admin.site.register(Star, StarAdmin)
|
||||
|
||||
|
||||
class League(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
raw_picks = models.IntegerField(default=3)
|
||||
smackdown_picks = models.IntegerField(default=3)
|
||||
diva_picks = models.IntegerField(default=2)
|
||||
wildcard_picks = models.IntegerField(default=1)
|
||||
oldtimer_picks = models.IntegerField(default=2)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
admin.site.register(League)
|
||||
|
||||
|
||||
class Team(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
login = models.OneToOneField(User, related_name='team')
|
||||
league = models.ForeignKey(League, related_name='teams')
|
||||
stars = models.ManyToManyField(Star, related_name='teams')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
class TeamAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'league')
|
||||
list_filter = ('league',)
|
||||
|
||||
admin.site.register(Team, TeamAdmin)
|
||||
|
||||
class Event(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
date = models.DateField()
|
||||
|
||||
def __unicode__(self):
|
||||
return '{0} {1}'.format(self.name, self.date)
|
||||
|
||||
admin.site.register(Event)
|
||||
|
||||
WIN_TYPES = (('pin', 'pin'),
|
||||
('DQ', 'DQ'),
|
||||
('submission', 'submission'))
|
||||
class Match(models.Model):
|
||||
event = models.ForeignKey(Event, related_name='matches')
|
||||
win_type = models.CharField(max_length=10, choices=WIN_TYPES)
|
||||
|
||||
def add_team(self, *members):
|
||||
mt = MatchTeam.objects.create(match=self)
|
||||
for member in members:
|
||||
member = Star.objects.get(pk=member)
|
||||
mt.members.add(member)
|
||||
|
||||
def record_win(self, star, win_type):
|
||||
self.teams.find(members__pk=star).update(victorious=True)
|
||||
self.win_type = win_type
|
||||
self.save()
|
||||
|
||||
def __unicode__(self):
|
||||
return ' vs. '.join(str(t) for t in self.teams.all())
|
||||
|
||||
admin.site.register(Match)
|
||||
|
||||
class MatchTeam(models.Model):
|
||||
members = models.ManyToManyField(Star)
|
||||
match = models.ForeignKey(Match, related_name='teams')
|
||||
victorious = models.BooleanField(default=False)
|
||||
|
||||
def __unicode__(self):
|
||||
return ' & '.join([str(m) for m in self.members.all()])
|
16
fowl/game/tests.py
Normal file
16
fowl/game/tests.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
1
fowl/game/views.py
Normal file
1
fowl/game/views.py
Normal file
@ -0,0 +1 @@
|
||||
# Create your views here.
|
125
fowl/settings.py
Normal file
125
fowl/settings.py
Normal file
@ -0,0 +1,125 @@
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
ADMINS = (
|
||||
# ('Your Name', 'your_email@example.com'),
|
||||
)
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': 'fowl.db',
|
||||
}
|
||||
}
|
||||
|
||||
TIME_ZONE = 'America/New_York'
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
USE_I18N = True
|
||||
USE_L10N = True
|
||||
USE_TZ = True
|
||||
|
||||
# Absolute filesystem path to the directory that will hold user-uploaded files.
|
||||
# Example: "/home/media/media.lawrence.com/media/"
|
||||
MEDIA_ROOT = ''
|
||||
|
||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||
# trailing slash.
|
||||
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
|
||||
MEDIA_URL = ''
|
||||
|
||||
# Absolute path to the directory static files should be collected to.
|
||||
# Don't put anything in this directory yourself; store your static files
|
||||
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
|
||||
# Example: "/home/media/media.lawrence.com/static/"
|
||||
STATIC_ROOT = ''
|
||||
|
||||
# URL prefix for static files.
|
||||
# Example: "http://media.lawrence.com/static/"
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# Additional locations of static files
|
||||
STATICFILES_DIRS = (
|
||||
# Put strings here, like "/home/html/static" or "C:/www/django/static".
|
||||
# Always use forward slashes, even on Windows.
|
||||
# Don't forget to use absolute paths, not relative paths.
|
||||
)
|
||||
|
||||
# List of finder classes that know how to find static files in
|
||||
# various locations.
|
||||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
||||
)
|
||||
|
||||
# Make this unique, and don't share it with anybody.
|
||||
SECRET_KEY = 'emixprj(wfq&7ail(!_$!vm%ccd8ydrszt5&%2c7su3mol6+z^'
|
||||
|
||||
# List of callables that know how to import templates from various sources.
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
# 'django.template.loaders.eggs.Loader',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
# Uncomment the next line for simple clickjacking protection:
|
||||
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'fowl.urls'
|
||||
|
||||
# Python dotted path to the WSGI application used by Django's runserver.
|
||||
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.
|
||||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.admin',
|
||||
'fowl.game',
|
||||
)
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'filters': {
|
||||
'require_debug_false': {
|
||||
'()': 'django.utils.log.RequireDebugFalse'
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'mail_admins': {
|
||||
'level': 'ERROR',
|
||||
'filters': ['require_debug_false'],
|
||||
'class': 'django.utils.log.AdminEmailHandler'
|
||||
}
|
||||
},
|
||||
'loggers': {
|
||||
'django.request': {
|
||||
'handlers': ['mail_admins'],
|
||||
'level': 'ERROR',
|
||||
'propagate': True,
|
||||
},
|
||||
}
|
||||
}
|
10
fowl/urls.py
Normal file
10
fowl/urls.py
Normal file
@ -0,0 +1,10 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
#url(r'^', include('fowl.game.urls')),
|
||||
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
)
|
28
fowl/wsgi.py
Normal file
28
fowl/wsgi.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""
|
||||
WSGI config for fowl project.
|
||||
|
||||
This module contains the WSGI application used by Django's development server
|
||||
and any production WSGI deployments. It should expose a module-level variable
|
||||
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
|
||||
this application via the ``WSGI_APPLICATION`` setting.
|
||||
|
||||
Usually you will have the standard Django WSGI application here, but it also
|
||||
might make sense to replace the whole Django WSGI application with a custom one
|
||||
that later delegates to the Django one. For example, you could introduce WSGI
|
||||
middleware here, or combine a Django application with an application of another
|
||||
framework.
|
||||
|
||||
"""
|
||||
import os
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fowl.settings")
|
||||
|
||||
# This application object is used by any WSGI server configured to use this
|
||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||
# setting points here.
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
application = get_wsgi_application()
|
||||
|
||||
# Apply WSGI middleware here.
|
||||
# from helloworld.wsgi import HelloWorldApplication
|
||||
# application = HelloWorldApplication(application)
|
10
manage.py
Executable file
10
manage.py
Executable file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fowl.settings")
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
execute_from_command_line(sys.argv)
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Django
|
||||
lxml
|
||||
scrapelib
|
16
setup_league.py
Normal file
16
setup_league.py
Normal file
@ -0,0 +1,16 @@
|
||||
from django.contrib.auth.models import User
|
||||
from fowl.game.models import League, Star, Team, Event, Match
|
||||
|
||||
james = User.objects.create_superuser('james', 'james.p.turk@gmail.com', 'james')
|
||||
erin = User.objects.create_user('erin', 'erin.braswell@gmail.com', 'erin')
|
||||
kevin = User.objects.create_user('kevin', 'kevin.wohlgenant@gmail.com', 'kevin')
|
||||
league = League.objects.create(name='Fire Pro Wrestling')
|
||||
gm_punk = Team.objects.create(name='GM Punk', login=james, league=league)
|
||||
awesome = Team.objects.create(name="I'm AWEsome!", login=kevin, league=league)
|
||||
cobra = Team.objects.create(name='COBRA!', login=erin, league=league)
|
||||
|
||||
|
||||
wm = Event.objects.create(name='Wrestlemania XXX', date='2013-01-01')
|
||||
m1 = Match.objects.create(event=wm)
|
||||
m1.add_team('dolphziggler')
|
||||
m1.add_team('randysavage')
|
Loading…
Reference in New Issue
Block a user