From 156be0b21d8f868718ba7bc157e50e8f189892c2 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sat, 17 Oct 2015 13:59:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=92=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=20contest=20=E5=92=8C=20problem=20=E9=83=A8=E5=88=86=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contest/models.py | 41 +------------------ contest/views.py | 2 +- problem/migrations/0010_auto_20151017_1226.py | 24 +++++++++++ problem/migrations/0011_auto_20151017_1227.py | 20 +++++++++ problem/models.py | 9 ++-- 5 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 problem/migrations/0010_auto_20151017_1226.py create mode 100644 problem/migrations/0011_auto_20151017_1227.py diff --git a/contest/models.py b/contest/models.py index 2708bcf4..2213f43e 100644 --- a/contest/models.py +++ b/contest/models.py @@ -22,12 +22,8 @@ CONTEST_UNDERWAY = 0 class Contest(models.Model): title = models.CharField(max_length=40, unique=True) description = RichTextField() - # 比赛模式:0 即为是acm模式,1 即为是按照总的 ac 题目数量排名模式 - mode = models.IntegerField() # 是否显示实时排名结果 real_time_rank = models.BooleanField() - # 是否显示别人的提交记录 - show_user_submission = models.BooleanField() # 只能超级管理员创建公开赛,管理员只能创建小组内部的比赛 # 如果这一项不为空,即为有密码的公开赛,没有密码的可以为小组赛或者是公开赛(此时用比赛的类型来表示) password = models.CharField(max_length=30, blank=True, null=True) @@ -68,46 +64,13 @@ class ContestProblem(AbstractProblem): contest = models.ForeignKey(Contest) # 比如A B 或者1 2 或者 a b 将按照这个排序 sort_index = models.CharField(max_length=30) - score = models.IntegerField(default=0) + # 是否已经公开了题目,防止重复公开 + is_public = models.BooleanField(default=False) class Meta: db_table = "contest_problem" -class ContestProblemTestCase(models.Model): - """ - 如果比赛是按照通过的测试用例总分计算的话,就需要这个model 记录每个测试用例的分数 - """ - # 测试用例的id 这个还在测试用例的配置文件里面有对应 - id = models.CharField(max_length=40, primary_key=True, db_index=True) - problem = models.ForeignKey(ContestProblem) - score = models.IntegerField() - - class Meta: - db_table = "contest_problem_test_case" - - -class ContestSubmission(models.Model): - """ - 用于保存比赛提交和排名的一些数据,加快检索速度 - """ - user = models.ForeignKey(User) - problem = models.ForeignKey(ContestProblem) - contest = models.ForeignKey(Contest) - total_submission_number = models.IntegerField(default=1) - # 这道题是 AC 还是没过 - ac = models.BooleanField() - # ac 用时以秒计 - ac_time = models.IntegerField(default=0) - # 总的时间,用于acm 类型的,也需要保存罚时 - total_time = models.IntegerField(default=0) - # 第一个解出此题目 - first_achieved = models.BooleanField(default=False) - - class Meta: - db_table = "contest_submission" - - class ContestRank(models.Model): user = models.ForeignKey(User) contest = models.ForeignKey(Contest) diff --git a/contest/views.py b/contest/views.py index cdf93970..e498e401 100644 --- a/contest/views.py +++ b/contest/views.py @@ -19,7 +19,7 @@ from account.models import SUPER_ADMIN, User from account.decorators import login_required from group.models import Group from utils.cache import get_cache_redis -from .models import (Contest, ContestProblem, ContestSubmission, CONTEST_ENDED, +from .models import (Contest, ContestProblem, CONTEST_ENDED, CONTEST_NOT_START, CONTEST_UNDERWAY, ContestRank) from .models import GROUP_CONTEST, PUBLIC_CONTEST, PASSWORD_PROTECTED_CONTEST from .decorators import check_user_contest_permission diff --git a/problem/migrations/0010_auto_20151017_1226.py b/problem/migrations/0010_auto_20151017_1226.py new file mode 100644 index 00000000..743497d0 --- /dev/null +++ b/problem/migrations/0010_auto_20151017_1226.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('problem', '0009_auto_20151008_1125'), + ] + + operations = [ + migrations.AddField( + model_name='problem', + name='last_update_time', + field=models.DateTimeField(null=True, blank=True), + ), + migrations.AlterField( + model_name='problem', + name='source', + field=models.CharField(max_length=200, null=True, blank=True), + ), + ] diff --git a/problem/migrations/0011_auto_20151017_1227.py b/problem/migrations/0011_auto_20151017_1227.py new file mode 100644 index 00000000..ae8b7d0d --- /dev/null +++ b/problem/migrations/0011_auto_20151017_1227.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import utils.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('problem', '0010_auto_20151017_1226'), + ] + + operations = [ + migrations.AlterField( + model_name='problem', + name='hint', + field=utils.models.RichTextField(null=True, blank=True), + ), + ] diff --git a/problem/models.py b/problem/models.py index a9e8f74b..5944ca6d 100644 --- a/problem/models.py +++ b/problem/models.py @@ -26,11 +26,12 @@ class AbstractProblem(models.Model): # 测试用例id 这个id 可以用来拼接得到测试用例的文件存储位置 test_case_id = models.CharField(max_length=40) # 提示 - hint = models.TextField(blank=True, null=True) + hint = RichTextField(blank=True, null=True) # 创建时间 create_time = models.DateTimeField(auto_now_add=True) - # 最后更新时间 - # last_update_time = models.DateTimeField(auto_now=True) + # 最后更新时间,不适用auto_now,因为本 model 里面的提交数量是变化的,导致每次 last_update_time 也更新了 + # 需要每次编辑后手动赋值 + last_update_time = models.DateTimeField(blank=True, null=True) # 这个题是谁创建的 created_by = models.ForeignKey(User) # 时间限制 单位是毫秒 @@ -63,4 +64,4 @@ class Problem(AbstractProblem): # 标签 tags = models.ManyToManyField(ProblemTag) # 来源 - source = models.CharField(max_length=30, blank=True, null=True) + source = models.CharField(max_length=200, blank=True, null=True)