Skip to content

Commit

Permalink
대회의 기본값도 폼으로 옮김
Browse files Browse the repository at this point in the history
  • Loading branch information
joonas-yoon committed Jan 24, 2018
1 parent 04a89de commit 1aaec45
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 13 deletions.
15 changes: 14 additions & 1 deletion judge/admin/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from django.forms import ModelForm, ModelMultipleChoiceField
from django.http import HttpResponseRedirect, Http404
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _, ungettext
from reversion.admin import VersionAdmin

from judge.models import Contest, ContestProblem, Profile, Rating
from judge.ratings import rate_contest
from judge.utils.generator import GenerateRandomFruitTextInput
from judge.utils.generator import make_key, GenerateRandomFruitTextInput
from judge.widgets import HeavySelect2Widget, HeavySelect2MultipleWidget, AdminPagedownWidget, Select2MultipleWidget, \
HeavyPreviewAdminPageDownWidget, Select2Widget

Expand Down Expand Up @@ -70,12 +71,24 @@ class ContestProblemInline(admin.TabularInline):
form = ContestProblemInlineForm


def today():
return timezone.localtime(timezone.now()).replace(hour=0, minute=0, second=0, microsecond=0)

def days_hence(days=7):
date = today() + timezone.timedelta(days=days)
return timezone.localtime(date.replace(hour=23, minute=59, second=59))


class ContestForm(ModelForm):
def __init__(self, *args, **kwargs):
super(ContestForm, self).__init__(*args, **kwargs)
if 'rate_exclude' in self.fields:
self.fields['rate_exclude'].queryset = \
Profile.objects.filter(contest_history__contest=self.instance).distinct()
self.fields['key'].initial = make_key()
self.fields['start_time'].initial = today()
self.fields['end_time'].initial = days_hence()


class Meta:
widgets = {
Expand Down
56 changes: 56 additions & 0 deletions judge/migrations/0069_auto_20180124_2023.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-01-24 20:23
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('judge', '0068_auto_20171229_1242'),
]

operations = [
migrations.AlterField(
model_name='contest',
name='access_code',
field=models.CharField(blank=True, help_text='An optional code to prompt contestants before they are allowed to join the contest. Leave it blank to disable.', max_length=255, verbose_name='access code'),
),
migrations.AlterField(
model_name='contest',
name='key',
field=models.CharField(max_length=20, unique=True, validators=[django.core.validators.RegexValidator(b'^[a-zA-Z0-9]+$', 'Contest id must be ^[a-z0-9]+$')], verbose_name='contest id'),
),
migrations.AlterField(
model_name='contest',
name='time_limit',
field=models.DurationField(blank=True, help_text='User must solve problems within the time given. Leave it blank to disable.', null=True, verbose_name='time limit'),
),
migrations.AlterField(
model_name='contestproblem',
name='points',
field=models.IntegerField(default=100, verbose_name='points'),
),
migrations.AlterField(
model_name='problem',
name='code',
field=models.CharField(help_text='You can only use lower case and hyphen. e.g. pr0b1em-c0de', max_length=20, unique=True, validators=[django.core.validators.RegexValidator(b'^[a-zA-Z0-9\\-]+$', 'Problem code must be ^[a-z0-9]+$')], verbose_name='problem code'),
),
migrations.AlterField(
model_name='problem',
name='memory_limit',
field=models.IntegerField(default=131072, help_text='The memory limit for this problem, in kilobytes (e.g. 64mb = 65536 kilobytes).', verbose_name='memory limit'),
),
migrations.AlterField(
model_name='problem',
name='points',
field=models.FloatField(default=10.0, help_text='Problem points should be between 1.0 and 20.0', validators=[django.core.validators.MinValueValidator(1.0), django.core.validators.MaxValueValidator(20.0)], verbose_name='points'),
),
migrations.AlterField(
model_name='problem',
name='time_limit',
field=models.FloatField(default=1.0, help_text='The time limit for this problem, in seconds. Fractional seconds (e.g. 1.5) are supported.', verbose_name='time limit'),
),
]
15 changes: 3 additions & 12 deletions judge/models/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from judge.models.problem import Problem
from judge.models.profile import Profile, Organization
from judge.models.submission import Submission
import judge.utils.generator as gen

__all__ = ['Contest', 'ContestTag', 'ContestParticipation', 'ContestProblem', 'ContestSubmission', 'Rating']

Expand Down Expand Up @@ -46,24 +45,16 @@ class Meta:
verbose_name_plural = _('contest tags')


def today():
return timezone.localtime(timezone.now()).replace(hour=0, minute=0, second=0, microsecond=0)

def days_hence(days=7):
date = today() + timezone.timedelta(days=days)
return timezone.localtime(date.replace(hour=23, minute=59, second=59))


class Contest(models.Model):
key = models.CharField(max_length=20, verbose_name=_('contest id'), unique=True, default=gen.make_key,
key = models.CharField(max_length=20, verbose_name=_('contest id'), unique=True,
validators=[RegexValidator('^[a-zA-Z0-9]+$', _('Contest id must be ^[a-z0-9]+$'))])
name = models.CharField(max_length=100, verbose_name=_('contest name'), db_index=True)
organizers = models.ManyToManyField(Profile, help_text=_('These people will be able to edit the contest.'),
related_name='organizers+')
description = models.TextField(verbose_name=_('description'), blank=True)
problems = models.ManyToManyField(Problem, verbose_name=_('problems'), through='ContestProblem')
start_time = models.DateTimeField(verbose_name=_('start time'), db_index=True, default=today)
end_time = models.DateTimeField(verbose_name=_('end time'), db_index=True, default=days_hence)
start_time = models.DateTimeField(verbose_name=_('start time'), db_index=True)
end_time = models.DateTimeField(verbose_name=_('end time'), db_index=True)
time_limit = models.DurationField(verbose_name=_('time limit'), blank=True, null=True,
help_text=_('User must solve problems within the time given. '
'Leave it blank to disable.'))
Expand Down

0 comments on commit 1aaec45

Please sign in to comment.