commit de1f312570e7c50d00bb5744e0842fba046a7399 Author: James Turk Date: Sat May 26 03:36:16 2012 -0400 initial fowl diff --git a/fowl/__init__.py b/fowl/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fowl/game/__init__.py b/fowl/game/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fowl/game/management/__init__.py b/fowl/game/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fowl/game/management/commands/__init__.py b/fowl/game/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fowl/game/management/commands/loadstars.py b/fowl/game/management/commands/loadstars.py new file mode 100644 index 0000000..452d34b --- /dev/null +++ b/fowl/game/management/commands/loadstars.py @@ -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')) diff --git a/fowl/game/models.py b/fowl/game/models.py new file mode 100644 index 0000000..114346e --- /dev/null +++ b/fowl/game/models.py @@ -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()]) \ No newline at end of file diff --git a/fowl/game/tests.py b/fowl/game/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/fowl/game/tests.py @@ -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) diff --git a/fowl/game/views.py b/fowl/game/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/fowl/game/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/fowl/settings.py b/fowl/settings.py new file mode 100644 index 0000000..9b536bd --- /dev/null +++ b/fowl/settings.py @@ -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, + }, + } +} diff --git a/fowl/urls.py b/fowl/urls.py new file mode 100644 index 0000000..7459325 --- /dev/null +++ b/fowl/urls.py @@ -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)), +) diff --git a/fowl/wsgi.py b/fowl/wsgi.py new file mode 100644 index 0000000..f82e135 --- /dev/null +++ b/fowl/wsgi.py @@ -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) diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..9c3a912 --- /dev/null +++ b/manage.py @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e606222 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Django +lxml +scrapelib diff --git a/setup_league.py b/setup_league.py new file mode 100644 index 0000000..b3a4bf6 --- /dev/null +++ b/setup_league.py @@ -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') \ No newline at end of file