Skip to content

Commit

Permalink
Added functionality to upload bots
Browse files Browse the repository at this point in the history
  • Loading branch information
arunchaganty committed Aug 19, 2010
1 parent 96f7d3e commit 28eb333
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 5 deletions.
Binary file modified web/desdemona.db
Binary file not shown.
5 changes: 1 addition & 4 deletions web/home/urls.py
@@ -1,11 +1,8 @@
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('web.home.views',
(r'^register/$', 'register'),
(r'^logout/$', 'logout'),
(r'^login/$', 'login'),
(r'^$', 'home'),
)
Empty file added web/judge/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions web/judge/forms.py
@@ -0,0 +1,24 @@
from django import forms
from django.db import models as d_models

import models

import hashlib

class SubmissionForm( forms.ModelForm ):
data = forms.FileField(label="Bot Binary")
class Meta:
model = models.Submission
exclude = ('timestamp','team', 'sha1sum')

def clean(self):
forms.ModelForm.clean(self)
self.clean_sha1sum()
self.cleaned_data["data"].name = self.cleaned_data["sha1sum"]
return self.cleaned_data

def clean_sha1sum(self):
data = self.cleaned_data["data"]
self.cleaned_data["sha1sum"] = hashlib.sha1(data.read()).hexdigest()
print self.cleaned_data

11 changes: 11 additions & 0 deletions web/judge/models.py
@@ -0,0 +1,11 @@
from django.db import models

from web.home import models as home_models

class Submission( models.Model ):
team = models.ForeignKey( home_models.Team )
timestamp = models.DateTimeField( auto_now = True )
sha1sum = models.CharField( max_length=100 )
data = models.FileField( upload_to='bots' )
comments = models.TextField()

26 changes: 26 additions & 0 deletions web/judge/templates/manage.html
@@ -0,0 +1,26 @@
{% extends "base.html" %}

{% block body %}
<div>
<div id="add-submission">
<form method="POST" action="" enctype="multipart/form-data">
{% csrf_token %}
<table>
{{form}}
<tr>
<td></td>
<td>
<span class="right">
<input type="submit" value="Submit" />
</span>
</td>
</table>

</form>
</div>
<div id="view-submission">

</div>
</div>
{% endblock %}

23 changes: 23 additions & 0 deletions web/judge/tests.py
@@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these 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.failUnlessEqual(1 + 1, 2)

__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

7 changes: 7 additions & 0 deletions web/judge/urls.py
@@ -0,0 +1,7 @@
from django.conf.urls.defaults import *

urlpatterns = patterns('web.judge.views',
(r'^manage/$', 'manage'),
(r'^standings/$', 'standings'),
(r'^results/$', 'results'),
)
27 changes: 27 additions & 0 deletions web/judge/views.py
@@ -0,0 +1,27 @@
# Create your views here.

from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.http import HttpResponse, HttpResponseRedirect
import django.contrib.auth as auth
import django.contrib.auth.views as auth_views
import forms
import models

from web import settings

def manage(request):
if request.POST:
data = request.POST
file_data = request.FILES
sub = models.Submission(team = request.user)
form = forms.SubmissionForm(data=data, files=file_data, instance=sub)
if form.is_valid():
form.save()
else:
form = forms.SubmissionForm()

return render_to_response("manage.html",
{'form':form},
context_instance = RequestContext(request))

5 changes: 4 additions & 1 deletion web/home/templates/base.html → web/templates/base.html
Expand Up @@ -16,9 +16,12 @@

<div id="linkbar">
<a href="/home/">Home</a>
{% if user.is_authenticated %}
&middot; <a href="/judge/manage/">Manage Submissions</a>
{% endif %}
&middot; <a href="/judge/standings/">Standings</a>
&middot; <a href="/judge/results/">Match Results</a>
{% if user.is_authenticated %}
&middot; <a href="/judge/submissions/manage/">Manage Submissions</a>
&middot; <a href="/home/logout/">Logout</a>
{% endif %}
</div>
Expand Down
1 change: 1 addition & 0 deletions web/urls.py
Expand Up @@ -6,6 +6,7 @@

urlpatterns = patterns('',
(r'^home/', include('web.home.urls')),
(r'^judge/', include('web.judge.urls')),

# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
Expand Down

0 comments on commit 28eb333

Please sign in to comment.