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()
|
||||
|
||||
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()]
|
||||
}
|
||||
return d
|
||||
|
||||
@staticmethod
|
||||
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']:
|
||||
event.add_match(*match['teams'],
|
||||
winner=match['winner'],
|
||||
|
@ -1,56 +1,63 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<form class="well form-inline">
|
||||
<form class="well form-inline" action="." method="post">
|
||||
<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>
|
||||
<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 -->
|
||||
<hr>
|
||||
<h4>Match #1</h4>
|
||||
<h4>Match #{{forloop.counter}}</h4>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th>member #1</th>
|
||||
<th>member #2</th>
|
||||
<th>member #3</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for team in match.teams %}
|
||||
<tr>
|
||||
<th>team #1</th>
|
||||
<td><input type="text" class="span3"></td>
|
||||
<td><input type="text" class="span3"></td>
|
||||
<td><input type="text" class="span3"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>team #2</th>
|
||||
<td><input type="text" class="span3"></td>
|
||||
<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>
|
||||
<th>team #{{forloop.counter}}</th>
|
||||
{% for member in team %}
|
||||
<td><input type="text" class="span3"
|
||||
{# member-event_id-team_id #}
|
||||
name="members-{{forloop.parentloop.parentloop.counter}}-{{forloop.parentloop.counter}}"
|
||||
value="{{member}}">
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<label>Winner</label>
|
||||
<input type="text" class="span3">
|
||||
<label>Win Type</label>
|
||||
<select>
|
||||
<option>Pin</option>
|
||||
<option>Submission</option>
|
||||
<option>Disqualification</option>
|
||||
<label>Outcome</label>
|
||||
<select name="outcome">
|
||||
{% for val, name in OUTCOMES %}
|
||||
<option value="{{val}}"
|
||||
{% if match.outcome == val %}selected="selected"{% endif %}>
|
||||
{{name}}</option>
|
||||
{% endfor %}
|
||||
</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 Member</button>
|
||||
<button class="btn btn-danger">Delete Match</button>
|
||||
<!-- /match -->
|
||||
<!-- match -->
|
||||
{% endfor %}
|
||||
<!-- match clean
|
||||
<hr>
|
||||
<h4>Match #2</h4>
|
||||
<table class="table">
|
||||
@ -94,10 +101,11 @@
|
||||
<button class="btn">Add Team</button>
|
||||
<button class="btn">Add Member</button>
|
||||
<button class="btn btn-danger">Delete Match</button>
|
||||
<!-- /match -->
|
||||
/match clean -->
|
||||
<div>
|
||||
<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>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
@ -45,7 +45,7 @@ class EventTest(TestCase):
|
||||
event.add_match('jimross', 'jerrylawler',
|
||||
winner='jimross', outcome='submission')
|
||||
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': [
|
||||
{'teams': [[u'jimross'],[u'jerrylawler']],
|
||||
'winner': u'jimross',
|
||||
@ -80,6 +80,28 @@ class EventTest(TestCase):
|
||||
self.assertEqual(match_one.notes, '')
|
||||
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):
|
||||
fixtures = ['testdata']
|
||||
|
@ -5,6 +5,8 @@ urlpatterns = patterns('',
|
||||
name='events'),
|
||||
url(r'league/(?P<league_id>\d+)/$', 'fowl.game.views.league',
|
||||
name='league'),
|
||||
url(r'^edit_event/$', 'fowl.game.views.edit_event', name='edit_event'),
|
||||
url(r'^roster/(?P<league_id>\d+)/$', 'fowl.game.views.roster', name='roster'),
|
||||
url(r'^edit_event/(?P<event>\d+|new)/$', 'fowl.game.views.edit_event',
|
||||
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 collections import defaultdict
|
||||
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):
|
||||
@ -23,14 +25,43 @@ def events(request, league_id):
|
||||
return render(request, "events.html", {'events': events, 'view': 'events', 'league': league, 'leagues':leagues})
|
||||
|
||||
|
||||
def edit_event(request, event_id=None):
|
||||
if event_id:
|
||||
event = get_object_or_404(Event, pk=event_id)
|
||||
else:
|
||||
def edit_event(request, event):
|
||||
if event == 'new':
|
||||
event = None
|
||||
if request.method == 'GET':
|
||||
return render(request, "edit_event.html", {"event": event})
|
||||
else:
|
||||
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):
|
||||
league = get_object_or_404(League, pk = league_id)
|
||||
|
Loading…
Reference in New Issue
Block a user