Skip to content

Commit

Permalink
Merge branch 'master' into beaudev
Browse files Browse the repository at this point in the history
  • Loading branch information
Beau Hargis committed Aug 6, 2013
2 parents bc7b3a0 + 2cf63ee commit 5eb828a
Show file tree
Hide file tree
Showing 31 changed files with 1,074 additions and 414 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# CodaLab Files #
#################
codalab/config/generated
codalab/static/*/*
codalab/static/**/**
codalab/media/**/**
/bundles/*

# Virtuelenv files #
Expand Down
36 changes: 23 additions & 13 deletions codalab/apps/api/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from . import serializers
from rest_framework import (viewsets,views,permissions)
from rest_framework.decorators import action,link
Expand All @@ -12,16 +13,21 @@ class CompetitionAPIViewSet(viewsets.ModelViewSet):
serializer_class = serializers.CompetitionSerial
queryset = webmodels.Competition.objects.all()


@action(permission_classes=[permissions.IsAuthenticated])
def participate(self,request,pk=None):
comp = self.get_object()
terms = request.DATA['agreed_terms']
status = webmodels.ParticipantStatus.objects.get(codename='pending')
p,cr = webmodels.CompetitionParticipant.objects.get_or_create(user=self.request.user,
competition=comp,
defaults={'status': status,
'reason': None})
return Response(status=(201 if cr else 200))
response_data = {
'result' : 201 if cr else 200,
'id' : p.id
}

return Response(json.dumps(response_data), content_type="application/json")

def _get_userstatus(self,request,pk=None,participant_id=None):
comp = self.get_object()
Expand All @@ -41,23 +47,29 @@ def mystatus(self,request,pk=None):

@action(methods=['POST','PUT'], permission_classes=[permissions.IsAuthenticated])
def participation_status(self,request,pk=None):
print "made it into handler"
comp = self.get_object()
resp = {}
status = request.DATA['status']
part = request.DATA['participant_id']
reason = request.DATA['reason']

try:
p = webmodels.CompetitionParticipant.objects.get(competition=comp,
pk=part)
p = webmodels.CompetitionParticipant.objects.get(competition=comp, pk=part)
p.status = webmodels.ParticipantStatus.objects.get(codename=status)
p.reason = reason
p.save()
except ObjectDoesNotExist as e:
return Response(status=400)
resp = { 'status': status,
'participantId': part,
'reason': reason }
return Response(resp,status=200)
resp = {
'status': status,
'participantId': part,
'reason': reason
}
except ObjectDoesNotExist as e:
resp = {
'status' : 400
}

return Response(json.dumps(resp), content_type="application/json")


@action(permission_classes=[permissions.IsAuthenticated]
Expand Down Expand Up @@ -191,9 +203,7 @@ def pre_save(self,obj):
if not obj.participant:
obj.participant = self.request.user


@action( permission_classes=[permissions.IsAuthenticated]
)
@action(permission_classes=[permissions.IsAuthenticated])
def leaderboard(self, request, pk=None,competition_id=None):
submission = self.get_object()
if True or submission.phase.is_active:
Expand Down
16 changes: 2 additions & 14 deletions codalab/apps/web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __unicode__(self):
class DefaultContentItem(models.Model):
category = TreeForeignKey(ContentCategory)
label = models.CharField(max_length=100)
codename = models.SlugField(max_length=100,unique=True)
rank = models.IntegerField(default=0)
required = models.BooleanField(default=False)
initial_visibility = models.ForeignKey(ContentVisibility)
Expand All @@ -60,6 +61,7 @@ def save(self,*args,**kwargs):
class Page(models.Model):
category = TreeForeignKey(ContentCategory)
defaults = models.ForeignKey(DefaultContentItem, null=True, blank=True)
codename = models.SlugField(max_length=100,unique=True)
container = models.ForeignKey(PageContainer, related_name='pages')
title = models.CharField(max_length=100, null=True, blank=True)
label = models.CharField(max_length=100)
Expand Down Expand Up @@ -116,22 +118,15 @@ def __unicode__(self):
return self.name
# End External File Models


# Join+ Model for Participants of a competition
class ParticipantStatus(models.Model):
name = models.CharField(max_length=30)
codename = models.CharField(max_length=30,unique=True)
description = models.CharField(max_length=50)



def __unicode__(self):
return self.name

class CompetitionPageSection(models.Model):
title = models.CharField(max_length=32)
slug = models.CharField(max_length=16)

class Competition(models.Model):
""" This is the base competition. """
title = models.CharField(max_length=100)
Expand All @@ -144,7 +139,6 @@ class Competition(models.Model):
modified_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='competitioninfo_modified_by')
last_modified = models.DateTimeField(auto_now_add=True)
pagecontent = models.ForeignKey(PageContainer,null=True,blank=True)
page_sections = models.ManyToManyField(CompetitionPageSection)

class Meta:
permissions = (
Expand Down Expand Up @@ -175,12 +169,6 @@ def image_url(self):
def is_active(self):
return self.end_date < now().date()

class CompetitionPageSubSection(models.Model):
title = models.CharField(max_length=32)
content = models.TextField(null=True, blank=True)
slug = models.CharField(max_length=16)
section = models.ForeignKey(CompetitionPageSection, related_name='sections')

# Dataset model
class Dataset(models.Model):
"""
Expand Down
Loading

0 comments on commit 5eb828a

Please sign in to comment.