Skip to content

Commit

Permalink
Add access code field to organizations; #232
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyene committed Sep 8, 2016
1 parent 8049d4e commit ab48269
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions judge/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class Organization(models.Model):
slots = models.IntegerField(verbose_name=_('maximum size'), null=True, blank=True,
help_text=_('Maximum amount of users in this organization, '
'only applicable to private organizations'))
access_code = models.CharField(max_length=7, help_text=_('Student access code'),
verbose_name=_('access code'), null=True, blank=True)

def __contains__(self, item):
if isinstance(item, (int, long)):
Expand Down Expand Up @@ -244,12 +246,13 @@ def calculate_points(self):
Submission.objects.filter(user=self, points__isnull=False, problem__is_public=True)
.values('problem_id').distinct().annotate(points=Max('points'))))
problems = (self.submission_set.filter(points__gt=0, problem__is_public=True)
.values('problem').distinct().count())
.values('problem').distinct().count())
if self.points != points or problems != self.problem_count:
self.points = points
self.problem_count = problems
self.save()
return points

calculate_points.alters_data = True

@cached_property
Expand All @@ -269,12 +272,14 @@ def long_display_name(self):
def remove_contest(self):
self.current_contest = None
self.save()

remove_contest.alters_data = True

def update_contest(self):
contest = self.current_contest
if contest is not None and contest.ended:
self.remove_contest()

update_contest.alters_data = True

def get_absolute_url(self):
Expand Down Expand Up @@ -478,6 +483,7 @@ def update_stats(self):
submissions = self.submission_set.count()
self.ac_rate = 100.0 * self.submission_set.filter(result='AC').count() / submissions if submissions else 0
self.save()

update_stats.alters_data = True

def _get_limits(self, key):
Expand Down Expand Up @@ -649,10 +655,12 @@ def long_status(self):

def judge(self):
judge_submission(self)

judge.alters_data = True

def abort(self):
abort_submission(self)

abort.alters_data = True

def is_graded(self):
Expand Down Expand Up @@ -734,7 +742,7 @@ class MPTTMeta:

@classmethod
def most_recent(cls, user, n, batch=None):
queryset = cls.objects.filter(hidden=False).select_related('author__user')\
queryset = cls.objects.filter(hidden=False).select_related('author__user') \
.defer('author__about', 'body').order_by('-id')
if user.is_superuser:
return queryset[:n]
Expand Down Expand Up @@ -890,7 +898,7 @@ def __unicode__(self):
@cached_property
def runtime_versions(self):
qs = (self.runtimeversion_set.values('language__key', 'language__name', 'version', 'name')
.order_by('language__key', 'priority'))
.order_by('language__key', 'priority'))

ret = OrderedDict()

Expand Down Expand Up @@ -1028,6 +1036,7 @@ def get_absolute_url(self):
def update_user_count(self):
self.user_count = self.users.filter(virtual=0).count()
self.save()

update_user_count.alters_data = True

class Meta:
Expand Down Expand Up @@ -1092,14 +1101,15 @@ def time_remaining(self):
def update_cumtime(self):
cumtime = 0
for problem in self.contest.contest_problems.all():
solution = problem.submissions.filter(participation=self, points__gt=0)\
solution = problem.submissions.filter(participation=self, points__gt=0) \
.values('submission__user_id').annotate(time=Max('submission__date'))
if not solution:
continue
dt = solution[0]['time'] - self.start
cumtime += dt.days * 86400 + dt.seconds
self.cumtime = cumtime
self.save()

update_cumtime.alters_data = True

def __unicode__(self):
Expand Down

0 comments on commit ab48269

Please sign in to comment.