Merge branch 'master' of github.com:jamesturk/fowl
This commit is contained in:
commit
10d2621656
@ -50,14 +50,20 @@ class Event(models.Model):
|
|||||||
date = models.DateField()
|
date = models.DateField()
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
d = {'name': self.name, 'date': self.date,
|
d = {'id': self.id, 'name': self.name, 'date': self.date,
|
||||||
'matches': [m.to_dict() for m in self.matches.all()]
|
'matches': [m.to_dict() for m in self.matches.all()]
|
||||||
}
|
}
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_dict(d):
|
def from_dict(d):
|
||||||
event = Event.objects.create(name=d['name'], date=d['date'])
|
if d.get('id'):
|
||||||
|
event = Event.objects.get(pk=d['id'])
|
||||||
|
event.name = d['name']
|
||||||
|
event.date = d['date']
|
||||||
|
event.matches.all().delete()
|
||||||
|
else:
|
||||||
|
event = Event.objects.create(name=d['name'], date=d['date'])
|
||||||
for match in d['matches']:
|
for match in d['matches']:
|
||||||
event.add_match(*match['teams'],
|
event.add_match(*match['teams'],
|
||||||
winner=match['winner'],
|
winner=match['winner'],
|
||||||
|
@ -1,56 +1,63 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form class="well form-inline">
|
<form class="well form-inline" action="." method="post">
|
||||||
<label>Show Name</label>
|
<label>Show Name</label>
|
||||||
<input type="text" class="span3" placeholder="RAW/Smackdown/PPV Name">
|
<input type="text" class="span3" name="name" value="{{event.name}}"
|
||||||
|
placeholder="RAW/Smackdown/PPV Name">
|
||||||
<label>Date</label>
|
<label>Date</label>
|
||||||
<input type="text" class="span3" placeholder="YYYY-MM-DD">
|
<input type="text" class="span3" name="date" value="{{event.date}}"
|
||||||
|
placeholder="YYYY-MM-DD">
|
||||||
|
{% for match in event.matches %}
|
||||||
<!-- match -->
|
<!-- match -->
|
||||||
<hr>
|
<hr>
|
||||||
<h4>Match #1</h4>
|
<h4>Match #{{forloop.counter}}</h4>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th> </th>
|
|
||||||
<th>member #1</th>
|
|
||||||
<th>member #2</th>
|
|
||||||
<th>member #3</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
<tbody>
|
||||||
|
{% for team in match.teams %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>team #1</th>
|
<th>team #{{forloop.counter}}</th>
|
||||||
<td><input type="text" class="span3"></td>
|
{% for member in team %}
|
||||||
<td><input type="text" class="span3"></td>
|
<td><input type="text" class="span3"
|
||||||
<td><input type="text" class="span3"></td>
|
{# member-event_id-team_id #}
|
||||||
</tr>
|
name="members-{{forloop.parentloop.parentloop.counter}}-{{forloop.parentloop.counter}}"
|
||||||
<tr>
|
value="{{member}}">
|
||||||
<th>team #2</th>
|
</td>
|
||||||
<td><input type="text" class="span3"></td>
|
{% endfor %}
|
||||||
<td><input type="text" class="span3"></td>
|
|
||||||
<td><input type="text" class="span3"></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>team #3</th>
|
|
||||||
<td><input type="text" class="span3"></td>
|
|
||||||
<td><input type="text" class="span3"></td>
|
|
||||||
<td><input type="text" class="span3"></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<label>Winner</label>
|
<label>Outcome</label>
|
||||||
<input type="text" class="span3">
|
<select name="outcome">
|
||||||
<label>Win Type</label>
|
{% for val, name in OUTCOMES %}
|
||||||
<select>
|
<option value="{{val}}"
|
||||||
<option>Pin</option>
|
{% if match.outcome == val %}selected="selected"{% endif %}>
|
||||||
<option>Submission</option>
|
{{name}}</option>
|
||||||
<option>Disqualification</option>
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
<label>Winner</label>
|
||||||
|
<input type="text" class="span3" name="winner"
|
||||||
|
value="{{match.winner}}">
|
||||||
|
<label>Title</label>
|
||||||
|
<select name="title">
|
||||||
|
<option value="">(none)</option>
|
||||||
|
{% for val, name in TITLES %}
|
||||||
|
<option value="{{val}}"
|
||||||
|
{% if match.title_at_stake == val %}selected="selected"{% endif %}>
|
||||||
|
{{name}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<br>
|
||||||
|
<label>Notes</label>
|
||||||
|
<input type="text" class="span6" name="notes"
|
||||||
|
value="{{match.notes}}">
|
||||||
|
<br>
|
||||||
<button class="btn">Add Team</button>
|
<button class="btn">Add Team</button>
|
||||||
<button class="btn">Add Member</button>
|
<button class="btn">Add Member</button>
|
||||||
<button class="btn btn-danger">Delete Match</button>
|
<button class="btn btn-danger">Delete Match</button>
|
||||||
<!-- /match -->
|
<!-- /match -->
|
||||||
<!-- match -->
|
{% endfor %}
|
||||||
|
<!-- match clean
|
||||||
<hr>
|
<hr>
|
||||||
<h4>Match #2</h4>
|
<h4>Match #2</h4>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
@ -94,10 +101,11 @@
|
|||||||
<button class="btn">Add Team</button>
|
<button class="btn">Add Team</button>
|
||||||
<button class="btn">Add Member</button>
|
<button class="btn">Add Member</button>
|
||||||
<button class="btn btn-danger">Delete Match</button>
|
<button class="btn btn-danger">Delete Match</button>
|
||||||
<!-- /match -->
|
/match clean -->
|
||||||
<div>
|
<div>
|
||||||
<button class="btn">Add Match</button>
|
<button class="btn">Add Match</button>
|
||||||
<button class="btn btn-primary">Save</button>
|
{% csrf_token %}
|
||||||
|
<input type="submit" value="Save Event" class="btn btn-primary"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -45,7 +45,7 @@ class EventTest(TestCase):
|
|||||||
event.add_match('jimross', 'jerrylawler',
|
event.add_match('jimross', 'jerrylawler',
|
||||||
winner='jimross', outcome='submission')
|
winner='jimross', outcome='submission')
|
||||||
event = Event.objects.get()
|
event = Event.objects.get()
|
||||||
expected = {'name': 'RAW', 'date': datetime.date(2012,1,1),
|
expected = {'id': 1, 'name': 'RAW', 'date': datetime.date(2012,1,1),
|
||||||
'matches': [
|
'matches': [
|
||||||
{'teams': [[u'jimross'],[u'jerrylawler']],
|
{'teams': [[u'jimross'],[u'jerrylawler']],
|
||||||
'winner': u'jimross',
|
'winner': u'jimross',
|
||||||
@ -80,6 +80,28 @@ class EventTest(TestCase):
|
|||||||
self.assertEqual(match_one.notes, '')
|
self.assertEqual(match_one.notes, '')
|
||||||
self.assertEqual(match_one.title_at_stake, None)
|
self.assertEqual(match_one.title_at_stake, None)
|
||||||
|
|
||||||
|
# test updating a dict
|
||||||
|
edict = {'id': 1, 'name': 'Smackdown', 'date': datetime.date(2013,1,1),
|
||||||
|
'matches': [
|
||||||
|
{'teams': [[u'jimross'],[u'jerrylawler']],
|
||||||
|
'winner': u'jimross',
|
||||||
|
'outcome': u'submission',
|
||||||
|
'notes': '',
|
||||||
|
'title_at_stake': None,
|
||||||
|
},
|
||||||
|
{'teams': [[u'michaelcole']],
|
||||||
|
'outcome': u'appearance',
|
||||||
|
'winner': None,
|
||||||
|
'notes': '',
|
||||||
|
'title_at_stake': None,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
event = Event.from_dict(edict)
|
||||||
|
self.assertEqual(event.name, 'Smackdown')
|
||||||
|
self.assertEqual(event.date, datetime.date(2013,1,1))
|
||||||
|
self.assertEqual(event.matches.count(), 2)
|
||||||
|
|
||||||
|
|
||||||
class MatchTest(TestCase):
|
class MatchTest(TestCase):
|
||||||
fixtures = ['testdata']
|
fixtures = ['testdata']
|
||||||
|
@ -5,6 +5,8 @@ urlpatterns = patterns('',
|
|||||||
name='events'),
|
name='events'),
|
||||||
url(r'league/(?P<league_id>\d+)/$', 'fowl.game.views.league',
|
url(r'league/(?P<league_id>\d+)/$', 'fowl.game.views.league',
|
||||||
name='league'),
|
name='league'),
|
||||||
url(r'^edit_event/$', 'fowl.game.views.edit_event', name='edit_event'),
|
url(r'^edit_event/(?P<event>\d+|new)/$', 'fowl.game.views.edit_event',
|
||||||
url(r'^roster/(?P<league_id>\d+)/$', 'fowl.game.views.roster', name='roster'),
|
name='edit_event'),
|
||||||
|
url(r'^roster/(?P<league_id>\d+)/$', 'fowl.game.views.roster',
|
||||||
|
name='roster'),
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
from itertools import izip_longest
|
from itertools import izip_longest
|
||||||
|
from collections import defaultdict
|
||||||
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, Event, League
|
from fowl.game.models import (Team, TeamPoints, Star, Event, League,
|
||||||
|
OUTCOMES, TITLES)
|
||||||
|
|
||||||
|
|
||||||
def events(request, league_id):
|
def events(request, league_id):
|
||||||
@ -23,14 +25,43 @@ def events(request, league_id):
|
|||||||
return render(request, "events.html", {'events': events, 'view': 'events', 'league': league, 'leagues':leagues})
|
return render(request, "events.html", {'events': events, 'view': 'events', 'league': league, 'leagues':leagues})
|
||||||
|
|
||||||
|
|
||||||
def edit_event(request, event_id=None):
|
def edit_event(request, event):
|
||||||
if event_id:
|
if event == 'new':
|
||||||
event = get_object_or_404(Event, pk=event_id)
|
|
||||||
else:
|
|
||||||
event = None
|
event = None
|
||||||
if request.method == 'GET':
|
else:
|
||||||
return render(request, "edit_event.html", {"event": event})
|
event = get_object_or_404(Event, pk=event).to_dict()
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
edict = {}
|
||||||
|
edict['id'] = request.POST.get('id')
|
||||||
|
edict['name'] = request.POST.get('name')
|
||||||
|
edict['date'] = request.POST.get('date')
|
||||||
|
edict['matches'] = []
|
||||||
|
|
||||||
|
outcomes = request.POST.getlist('outcome')
|
||||||
|
winners = request.POST.getlist('winner')
|
||||||
|
titles = request.POST.getlist('title')
|
||||||
|
notes = request.POST.getlist('notes')
|
||||||
|
for i, note in enumerate(notes):
|
||||||
|
edict['matches'].append({'outcome': outcomes[i],
|
||||||
|
'winner': winners[i],
|
||||||
|
'title_at_stake': titles[i],
|
||||||
|
'notes': notes[i],
|
||||||
|
'teams': [],
|
||||||
|
})
|
||||||
|
|
||||||
|
for k,v in request.POST.iterlists():
|
||||||
|
if k.startswith('members'):
|
||||||
|
_, match, team = k.split('-')
|
||||||
|
edict['matches'][int(match)-1]['teams'].append(v)
|
||||||
|
|
||||||
|
event = Event.from_dict(edict)
|
||||||
|
|
||||||
|
return render(request, "edit_event.html",
|
||||||
|
{'event': event,
|
||||||
|
'OUTCOMES': OUTCOMES,
|
||||||
|
'TITLES': TITLES}
|
||||||
|
)
|
||||||
|
|
||||||
def league(request, league_id):
|
def league(request, league_id):
|
||||||
league = get_object_or_404(League, pk = league_id)
|
league = get_object_or_404(League, pk = league_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user