Skip to content

Commit

Permalink
Added management to add submission
Browse files Browse the repository at this point in the history
  • Loading branch information
Beau Hargis committed Aug 6, 2013
1 parent dec93d4 commit bc7b3a0
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions codalab/apps/web/management/commands/add_submission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from django.core.management.base import BaseCommand, CommandError
from apps.web.models import Competition,CompetitionPhase,CompetitionParticipant,CompetitionSubmission
from django.contrib.auth import get_user_model
User = get_user_model()
from optparse import make_option

from django.core.files.base import File

class Command(BaseCommand):
help = "Creates a submission for a participant"

option_list = BaseCommand.option_list + (
make_option('--email',
dest='email',
help="Email of the user"),
make_option('--competition',
dest='competition',
default=None,
help="ID of the submission"),
make_option('--phase',
dest='phase',
default=None,
help="ID of the competition phase"),
make_option('--submission',
dest='submission',
default=None,
help="Path to the submission file"),

)

def handle(self, *args, **options):
competition_id = options['competition']
phase_id = options['phase']
submission = options['submission']
competition = None
phase = None
if not options['email']:
print " ERROR ... Email Required ... "
exit(1)
if not submission:
print " ERROR ... Submission File Required ... "
exit(1)

user = User.objects.get(email=options['email'])
while not competition and not phase:
if competition_id and phase_id:
try:
phase = CompetitionPhase.objects.get(pk=phase_id, competition__pk=competition_id)
break
except Competition.DoesNotExist:
pass
else:
print "Competition/Phase not specified or not valid:\n"

clist = CompetitionPhase.objects.order_by('competition__pk').all()
if not clist:
print " ... There are no competitions ..."
exit(1)
sel = []
i = 0
for c in clist:
sel.append((c.competition,c))
print " %d) %s - %s" % (i+1,c.competition.title,c.label)
i = i + 1
try:
inp = int(raw_input("\n Enter number --> "))
idx = inp - 1
competition = sel[idx][0]
phase = sel[idx][1]
except ValueError:
print " ... Bad Input ... "
competition_id = None
continue
except Exception as e:
print e

part = CompetitionParticipant.objects.get(user=user,
competition=competition
)
submission_file = File(open(options['submission'],'rb'))

s = CompetitionSubmission.objects.create(participant=part,phase=phase,file=submission_file)

print "OK. Submission Created"




0 comments on commit bc7b3a0

Please sign in to comment.