Permalink
Browse files

Replay Uploads

  • Loading branch information...
1 parent 1d5096b commit 708999e2c694c4ba09dfe463cba03c216502bb6b @issackelly committed Mar 10, 2012
@@ -0,0 +1,128 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding M2M table for field replays on 'Match'
+ db.create_table('brackets_match_replays', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('from_match', models.ForeignKey(orm['brackets.match'], null=False)),
+ ('to_match', models.ForeignKey(orm['sc2match.match'], null=False))
+ ))
+ db.create_unique('brackets_match_replays', ['from_match_id', 'to_match_id'])
+
+ def backwards(self, orm):
+ # Removing M2M table for field replays on 'Match'
+ db.delete_table('brackets_match_replays')
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'brackets.bracket': {
+ 'Meta': {'ordering': "['tournament', 'order']", 'unique_together': "(['tournament', 'slug', 'order'],)", 'object_name': 'Bracket'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+ 'order': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+ 'tournament': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'brackets'", 'to': "orm['brackets.Tournament']"})
+ },
+ 'brackets.match': {
+ 'Meta': {'ordering': "['the_round', 'order']", 'object_name': 'Match'},
+ 'end_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'notes': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
+ 'order': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'outcome': ('django.db.models.fields.CharField', [], {'default': "'unplayed'", 'max_length': '32'}),
+ 'player_1': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'matches_1'", 'null': 'True', 'to': "orm['brackets.Player']"}),
+ 'player_1_score': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '32', 'blank': 'True'}),
+ 'player_2': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'matches_2'", 'null': 'True', 'to': "orm['brackets.Player']"}),
+ 'player_2_score': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '32', 'blank': 'True'}),
+ 'replays': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sc2match.Match']", 'null': 'True', 'symmetrical': 'False'}),
+ 'start_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'the_round': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'matches'", 'to': "orm['brackets.Round']"}),
+ 'winner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'matches_won'", 'null': 'True', 'to': "orm['brackets.Player']"})
+ },
+ 'brackets.player': {
+ 'Meta': {'ordering': "['player']", 'object_name': 'Player'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'league': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '64', 'blank': 'True'}),
+ 'player': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'tournament_profile'", 'to': "orm['auth.User']"}),
+ 'rank': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+ 'seed': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'tournament': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['brackets.Tournament']"})
+ },
+ 'brackets.round': {
+ 'Meta': {'ordering': "['bracket', 'order']", 'object_name': 'Round'},
+ 'bracket': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'rounds'", 'to': "orm['brackets.Bracket']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+ 'order': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'})
+ },
+ 'brackets.tournament': {
+ 'Meta': {'ordering': "['-start_date', 'name']", 'object_name': 'Tournament'},
+ 'end_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}),
+ 'start_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'sc2match.map': {
+ 'Meta': {'object_name': 'Map'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'map_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'})
+ },
+ 'sc2match.match': {
+ 'Meta': {'ordering': "['-modified']", 'object_name': 'Match'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'duration': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'}),
+ 'gateway': ('django.db.models.fields.CharField', [], {'default': "'us'", 'max_length': '32'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'mapfield': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sc2match.Map']", 'null': 'True'}),
+ 'modified': ('django.db.models.fields.DateTimeField', [], {}),
+ 'replay_file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'})
+ }
+ }
+
+ complete_apps = ['brackets']
View
@@ -27,7 +27,7 @@ class Meta:
ordering = ['player']
def __unicode__(self):
- return self.player
+ return self.player.username
@models.permalink
def get_absolute_url(self):
@@ -137,6 +137,7 @@ class Match(models.Model):
player_1_score = models.CharField(max_length=32, blank=True, default='')
player_2_score = models.CharField(max_length=32, blank=True, default='')
notes = models.TextField(blank=True, default='')
+ replays = models.ManyToManyField("sc2match.Match", null=True, blank=True)
class Meta:
verbose_name_plural = 'Matches'
View
@@ -6,6 +6,7 @@
url(r'^(?P<tournament_slug>[\w\d._-]+)/b/(?P<bracket_slug>[\w\d._-]+)/$', 'bracket_detail', name='tournament_bracket_detail'),
url(r'^(?P<tournament_slug>[\w\d._-]+)/b/(?P<bracket_slug>[\w\d._-]+)/r/(?P<round_slug>[\w\d._-]+)/$', 'round_detail', name='tournament_round_detail'),
url(r'^(?P<tournament_slug>[\w\d._-]+)/b/(?P<bracket_slug>[\w\d._-]+)/r/(?P<round_slug>[\w\d._-]+)/m/r/(?P<match_pk>\d+)/$', 'match_detail', name='tournament_match_detail'),
+ url(r'^(?P<tournament_slug>[\w\d._-]+)/b/(?P<bracket_slug>[\w\d._-]+)/r/(?P<round_slug>[\w\d._-]+)/m/r/(?P<match_pk>\d+)/upload_match/$', 'match_upload', name='tournament_match_upload'),
- url(r'^(?P<tournament_slug>[\w\d._-]+)/p/(?P<player_pk>[\w\d._-]+)/$', 'player_detail', name='tournament_player_detail'),
+ url(r'^(?P<tournament_slug>[\w\d._-]+)/p/(?P<username>[\w\d._-]+)/$', 'player_detail', name='tournament_player_detail'),
)
View
@@ -1,5 +1,8 @@
-from django.shortcuts import get_object_or_404, render
+from django.shortcuts import get_object_or_404, render, redirect
from .models import Player, Tournament, Bracket, Round, Match
+from django.views.decorators.http import require_POST
+from django.http import HttpResponse
+from sc2match.forms import MatchUpload
def tournament_detail(request, tournament_slug):
@@ -35,18 +38,35 @@ def match_detail(request, tournament_slug, bracket_slug, round_slug, match_pk):
bracket = get_object_or_404(tournament.brackets.all(), slug=bracket_slug)
the_round = get_object_or_404(bracket.rounds.all(), slug=round_slug)
match = get_object_or_404(the_round.matches.all(), pk=match_pk)
+ form = MatchUpload()
return render(request, 'brackets/match_detail.html', {
'tournament': tournament,
'bracket': bracket,
'round': the_round,
'match': match,
+ 'form': form,
})
-def player_detail(request, tournament_slug, player_slug):
+def player_detail(request, tournament_slug, username):
tournament = get_object_or_404(Tournament, slug=tournament_slug)
- player = get_object_or_404(Player, tournament__slug=tournament_slug, slug=player_slug)
+ player = get_object_or_404(Player, tournament__slug=tournament_slug, player__username=username)
return render(request, 'brackets/player_detail.html', {
'tournament': tournament,
'player': player,
})
+
+
+@require_POST
+def match_upload(request, tournament_slug, bracket_slug, round_slug, match_pk):
+ tournament = get_object_or_404(Tournament, slug=tournament_slug)
+ bracket = get_object_or_404(tournament.brackets.all(), slug=bracket_slug)
+ the_round = get_object_or_404(bracket.rounds.all(), slug=round_slug)
+ match = get_object_or_404(the_round.matches.all(), pk=match_pk)
+ form = MatchUpload(request.POST, request.FILES)
+ if form.is_valid():
+ replay = form.save()
+ match.replays.add(replay)
+ return redirect(match)
+ print form.errors
+ return HttpResponse(form.errors)
View
@@ -0,0 +1,10 @@
+from django.forms import ModelForm
+from sc2match.models import Match
+
+
+class MatchUpload(ModelForm):
+
+ class Meta:
+ model = Match
+ fields = ['replay_file']
+
@@ -2,19 +2,19 @@
<h4><a href="{{ match.get_absolute_url }}">Details</a></h4>
<div class="player_1">
{% if match.player_1 %}
- <span class="player_details"><a href="{% url tournament_player_detail tournament_slug=tournament.slug,player_slug=match.player_1.slug %}">{{ match.player_1.nickname }}</a></span>
+ <span class="player_details"><a href="{% url tournament_player_detail tournament_slug=tournament.slug,username=match.player_1.player.username %}">{{ match.player_1.player.username }}</a></span>
<span class="player_seed">{{ match.player_1.seed }}</span>
{% endif %}
</div>
<div class="player_2">
{% if match.player_2 %}
- <span class="player_details"><a href="{% url tournament_player_detail tournament_slug=tournament.slug,player_slug=match.player_2.slug %}">{{ match.player_2.nickname }}</a></span>
+ <span class="player_details"><a href="{% url tournament_player_detail tournament_slug=tournament.slug,username=match.player_2.player.username %}">{{ match.player_2.player.username }}</a></span>
<span class="player_seed">{{ match.player_2.seed }}</span>
{% endif %}
</div>
<div class="winner">
{% if match.winner %}
- <span class="player_details"><a href="{% url tournament_player_detail tournament_slug=tournament.slug,player_slug=match.winner.slug %}">{{ match.winner.nickname }}</a></span>
+ <span class="player_details"><a href="{% url tournament_player_detail tournament_slug=tournament.slug,username=match.winner.player.username %}">{{ match.winner.player.username }}</a></span>
{% endif %}
</div>
</div>
@@ -9,5 +9,21 @@ <h2>Match Details</h2>
</p>
{% include "brackets/includes/match.html" %}
+
+ {% if match.replays %}
+ <h3>Replays</h3>
+ <ul>
+ {% for replay in match.replays.all %}
+ <li><a href="{{ replay.replay_file.url }}">{{ replay }}</a></li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+
+ {% if request.user == match.player_1.player or request.user == match.player_2.player or request.user.is_superuser %}
+ <form method="POST" action="{% url tournament_match_upload tournament.slug, bracket.slug, round.slug, match.id %}" enctype="multipart/form-data">{% csrf_token %}
+ {{ form }}
+ <input type="submit" value="upload replay">
+ </form>
+ {% endif %}
</div>
{% endblock %}

0 comments on commit 708999e

Please sign in to comment.