Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

143 lines (89 sloc) 3.81 KB
from django.contrib import admin
from django.contrib.auth.models import User, Permission
from django.contrib.auth.admin import UserAdmin
from django.db.models import Q
from challenges.models import (Challenge, Phase, Submission, ExternalLink,
Category, ExclusionFlag, JudgingCriterion,
JudgingAnswer, Judgement, JudgeAssignment,
class JudgeAwareUserAdmin(UserAdmin):
def is_judge(self, user):
judge_permission = Permission.objects.get(codename='judge_submission')
judges = User.objects.filter(Q(user_permissions=judge_permission) |
return user in judges
# Enable the pretty tick boxes in the Django admin
is_judge.boolean = True
list_display = UserAdmin.list_display + ('is_judge',)
class PhaseInline(admin.TabularInline):
model = Phase
class PhaseCriterionInline(admin.TabularInline):
model = PhaseCriterion
class CategoryAdmin(admin.ModelAdmin):
model = Category
prepopulated_fields = {"slug": ("name",)}
class JudgeAssignmentInline(admin.StackedInline):
model = JudgeAssignment
max_num = 1
class ExclusionFlagInline(admin.StackedInline):
model = ExclusionFlag
extra = 1
class PhaseAdmin(admin.ModelAdmin):
inlines = (PhaseCriterionInline,)
class SubmissionAdmin(admin.ModelAdmin):
model = Submission
list_display = ('title', 'created_by', 'category', 'phase', 'is_draft',
'is_winner', 'excluded', 'judge_assignment',
list_filter = ('category', 'is_draft', 'is_winner')
list_select_related = True # For the judgement fields
inlines = (JudgeAssignmentInline, ExclusionFlagInline)
def judge_assignment(self, submission):
"""Return the names of all judges assigned to this submission."""
assignments = submission.judgeassignment_set.all()
if not assignments:
return 'No judge'
return ', '.join(a.judge.display_name for a in assignments)
def excluded(self, submission):
return submission.exclusionflag_set.exists()
excluded.boolean = True
def judgement_count(self, submission):
return submission.judgement_set.count()
class ChallengeAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("title",)}
inlines = (PhaseInline,)
class JudgingCriterionAdmin(admin.ModelAdmin):
list_display = ('question', 'max_value')
class JudgingAnswerInline(admin.StackedInline):
model = JudgingAnswer
class JudgementAdmin(admin.ModelAdmin):
inlines = (JudgingAnswerInline,)
list_display = ('__unicode__', 'submission', 'judge', 'complete', 'score')
def complete(self, judgement):
except Judgement.Incomplete:
return False
return True
complete.boolean = True
def score(self, judgement):
return judgement.get_score()
except Judgement.Incomplete:
return 'Incomplete'
class ExclusionFlagAdmin(admin.ModelAdmin):
model = ExclusionFlag
list_display = ('submission', 'notes'), JudgeAwareUserAdmin), ChallengeAdmin), SubmissionAdmin), PhaseAdmin), CategoryAdmin), ExclusionFlagAdmin), JudgingCriterionAdmin), JudgementAdmin)
Jump to Line
Something went wrong with that request. Please try again.