mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-01-16 01:13:47 +00:00
重构
This commit is contained in:
parent
61ab910d53
commit
078de956e5
65
account/migrations/0004_auto_20160925_1649.py
Normal file
65
account/migrations/0004_auto_20160925_1649.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9.5 on 2016-09-25 08:49
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('account', '0003_auto_20160925_1402'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='userprofile',
|
||||||
|
name='language',
|
||||||
|
field=models.CharField(blank=True, max_length=32, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='userprofile',
|
||||||
|
name='major',
|
||||||
|
field=models.CharField(blank=True, max_length=200, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='userprofile',
|
||||||
|
name='time_zone',
|
||||||
|
field=models.CharField(blank=True, max_length=32, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='auth_token',
|
||||||
|
field=models.CharField(max_length=40, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='email',
|
||||||
|
field=models.EmailField(max_length=254, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='open_api_appkey',
|
||||||
|
field=models.CharField(max_length=35, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='real_name',
|
||||||
|
field=models.CharField(max_length=30, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='reset_password_token',
|
||||||
|
field=models.CharField(max_length=40, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='reset_password_token_create_time',
|
||||||
|
field=models.DateTimeField(null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='tfa_token',
|
||||||
|
field=models.CharField(max_length=40, null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -1,4 +1,5 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
from django.contrib.auth.models import AbstractBaseUser
|
from django.contrib.auth.models import AbstractBaseUser
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from jsonfield import JSONField
|
from jsonfield import JSONField
|
||||||
@ -33,8 +34,8 @@ class UserManager(models.Manager):
|
|||||||
|
|
||||||
class User(AbstractBaseUser):
|
class User(AbstractBaseUser):
|
||||||
username = models.CharField(max_length=30, unique=True)
|
username = models.CharField(max_length=30, unique=True)
|
||||||
real_name = models.CharField(max_length=30, blank=True, null=True)
|
real_name = models.CharField(max_length=30, null=True)
|
||||||
email = models.EmailField(max_length=254, blank=True, null=True)
|
email = models.EmailField(max_length=254, null=True)
|
||||||
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
||||||
# One of UserType
|
# One of UserType
|
||||||
admin_type = models.IntegerField(default=0)
|
admin_type = models.IntegerField(default=0)
|
||||||
@ -43,15 +44,15 @@ class User(AbstractBaseUser):
|
|||||||
# Store user problem solution status with json string format
|
# Store user problem solution status with json string format
|
||||||
# {"problems": {1: ProblemSolutionStatus.ACCEPTED}, "contest_problems": {20: ProblemSolutionStatus.PENDING)}
|
# {"problems": {1: ProblemSolutionStatus.ACCEPTED}, "contest_problems": {20: ProblemSolutionStatus.PENDING)}
|
||||||
problems_status = JSONField(default={})
|
problems_status = JSONField(default={})
|
||||||
reset_password_token = models.CharField(max_length=40, blank=True, null=True)
|
reset_password_token = models.CharField(max_length=40, null=True)
|
||||||
reset_password_token_create_time = models.DateTimeField(blank=True, null=True)
|
reset_password_token_create_time = models.DateTimeField(null=True)
|
||||||
# SSO auth token
|
# SSO auth token
|
||||||
auth_token = models.CharField(max_length=40, blank=True, null=True)
|
auth_token = models.CharField(max_length=40, null=True)
|
||||||
two_factor_auth = models.BooleanField(default=False)
|
two_factor_auth = models.BooleanField(default=False)
|
||||||
tfa_token = models.CharField(max_length=40, blank=True, null=True)
|
tfa_token = models.CharField(max_length=40, null=True)
|
||||||
# open api key
|
# open api key
|
||||||
open_api = models.BooleanField(default=False)
|
open_api = models.BooleanField(default=False)
|
||||||
open_api_appkey = models.CharField(max_length=35, blank=True, null=True)
|
open_api_appkey = models.CharField(max_length=35, null=True)
|
||||||
is_disabled = models.BooleanField(default=False)
|
is_disabled = models.BooleanField(default=False)
|
||||||
|
|
||||||
USERNAME_FIELD = 'username'
|
USERNAME_FIELD = 'username'
|
||||||
@ -80,8 +81,10 @@ class UserProfile(models.Model):
|
|||||||
submission_number = models.IntegerField(default=0)
|
submission_number = models.IntegerField(default=0)
|
||||||
phone_number = models.CharField(max_length=15, blank=True, null=True)
|
phone_number = models.CharField(max_length=15, blank=True, null=True)
|
||||||
school = models.CharField(max_length=200, blank=True, null=True)
|
school = models.CharField(max_length=200, blank=True, null=True)
|
||||||
|
major = models.CharField(max_length=200, blank=True, null=True)
|
||||||
student_id = models.CharField(max_length=15, blank=True, null=True)
|
student_id = models.CharField(max_length=15, blank=True, null=True)
|
||||||
|
time_zone = models.CharField(max_length=32, blank=True, null=True)
|
||||||
|
language = models.CharField(max_length=32, blank=True, null=True)
|
||||||
|
|
||||||
def add_accepted_problem_number(self):
|
def add_accepted_problem_number(self):
|
||||||
self.accepted_problem_number = models.F("accepted_problem_number") + 1
|
self.accepted_problem_number = models.F("accepted_problem_number") + 1
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
# coding=utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
|
class SMTPConfig(models.Model):
|
||||||
|
pass
|
||||||
|
0
contest/__init__.py
Normal file
0
contest/__init__.py
Normal file
3
contest/admin.py
Normal file
3
contest/admin.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
0
contest/migrations/__init__.py
Normal file
0
contest/migrations/__init__.py
Normal file
106
contest/models.py
Normal file
106
contest/models.py
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from group.models import Group
|
||||||
|
from jsonfield import JSONField
|
||||||
|
|
||||||
|
from account.models import User
|
||||||
|
from problem.models import AbstractProblem
|
||||||
|
from utils.models import RichTextField
|
||||||
|
|
||||||
|
|
||||||
|
class ContestType(object):
|
||||||
|
GROUP_CONTEST = 0
|
||||||
|
PUBLIC_CONTEST = 1
|
||||||
|
PASSWORD_PROTECTED_CONTEST = 2
|
||||||
|
PASSWORD_PROTECTED_GROUP_CONTEST = 3
|
||||||
|
|
||||||
|
|
||||||
|
class ContestStatus(object):
|
||||||
|
CONTEST_NOT_START = 1
|
||||||
|
CONTEST_ENDED = -1
|
||||||
|
CONTEST_UNDERWAY = 0
|
||||||
|
|
||||||
|
|
||||||
|
class ContestRuleType(object):
|
||||||
|
ACM = 0
|
||||||
|
OI = 1
|
||||||
|
|
||||||
|
|
||||||
|
class Contest(models.Model):
|
||||||
|
title = models.CharField(max_length=40, unique=True)
|
||||||
|
description = RichTextField()
|
||||||
|
# show real time rank or cached rank
|
||||||
|
real_time_rank = models.BooleanField()
|
||||||
|
password = models.CharField(max_length=30, blank=True, null=True)
|
||||||
|
# enum of ContestType
|
||||||
|
contest_type = models.IntegerField()
|
||||||
|
# enum of ContestRuleType
|
||||||
|
rule_type = models.IntegerField()
|
||||||
|
start_time = models.DateTimeField()
|
||||||
|
end_time = models.DateTimeField()
|
||||||
|
create_time = models.DateTimeField(auto_now_add=True)
|
||||||
|
last_updated_time = models.DateTimeField(auto_now=True)
|
||||||
|
created_by = models.ForeignKey(User)
|
||||||
|
groups = models.ManyToManyField(Group)
|
||||||
|
# 是否可见 false的话相当于删除
|
||||||
|
visible = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status(self):
|
||||||
|
if self.start_time > now():
|
||||||
|
# 没有开始 返回1
|
||||||
|
return ContestStatus.CONTEST_NOT_START
|
||||||
|
elif self.end_time < now():
|
||||||
|
# 已经结束 返回-1
|
||||||
|
return ContestStatus.CONTEST_ENDED
|
||||||
|
else:
|
||||||
|
# 正在进行 返回0
|
||||||
|
return ContestStatus.CONTEST_UNDERWAY
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = "contest"
|
||||||
|
|
||||||
|
|
||||||
|
class ContestProblem(AbstractProblem):
|
||||||
|
contest = models.ForeignKey(Contest)
|
||||||
|
# 比如A B 或者1 2 或者 a b 将按照这个排序
|
||||||
|
sort_index = models.CharField(max_length=30)
|
||||||
|
# 是否已经公开了题目,防止重复公开
|
||||||
|
is_public = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = "contest_problem"
|
||||||
|
|
||||||
|
|
||||||
|
class ContestRank(models.Model):
|
||||||
|
user = models.ForeignKey(User)
|
||||||
|
contest = models.ForeignKey(Contest)
|
||||||
|
total_submission_number = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
class ACMContestRank(ContestRank):
|
||||||
|
total_ac_number = models.IntegerField(default=0)
|
||||||
|
# total_time is only for ACM contest total_time = ac time + none-ac times * 20 * 60
|
||||||
|
total_time = models.IntegerField(default=0)
|
||||||
|
# {23: {"is_ac": True, "ac_time": 8999, "error_number": 2, "is_first_ac": True}}
|
||||||
|
# key is problem id
|
||||||
|
submission_info = JSONField(default={})
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = "acm_contest_rank"
|
||||||
|
|
||||||
|
|
||||||
|
class OIContestRank(ContestRank):
|
||||||
|
total_score = models.IntegerField(default=0)
|
||||||
|
# {23: {"score": 80, "total_score": 100}}
|
||||||
|
# key is problem id
|
||||||
|
submission_info = JSONField(default={})
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = "oi_contenst_rank"
|
3
contest/tests.py
Normal file
3
contest/tests.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
3
contest/views.py
Normal file
3
contest/views.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
0
group/__init__.py
Normal file
0
group/__init__.py
Normal file
3
group/admin.py
Normal file
3
group/admin.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
7
group/apps.py
Normal file
7
group/apps.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class GroupConfig(AppConfig):
|
||||||
|
name = 'group'
|
0
group/migrations/__init__.py
Normal file
0
group/migrations/__init__.py
Normal file
8
group/models.py
Normal file
8
group/models.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class Group(models.Model):
|
||||||
|
pass
|
3
group/tests.py
Normal file
3
group/tests.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
3
group/views.py
Normal file
3
group/views.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
0
problem/__init__.py
Normal file
0
problem/__init__.py
Normal file
3
problem/admin.py
Normal file
3
problem/admin.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
0
problem/migrations/__init__.py
Normal file
0
problem/migrations/__init__.py
Normal file
69
problem/models.py
Normal file
69
problem/models.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from jsonfield import JSONField
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
from account.models import User
|
||||||
|
from utils.models import RichTextField
|
||||||
|
|
||||||
|
|
||||||
|
class ProblemTag(models.Model):
|
||||||
|
name = models.CharField(max_length=30)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = "problem_tag"
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractProblem(models.Model):
|
||||||
|
title = models.CharField(max_length=50)
|
||||||
|
# HTML
|
||||||
|
description = RichTextField()
|
||||||
|
input_description = models.CharField(max_length=10000)
|
||||||
|
output_description = models.CharField(max_length=10000)
|
||||||
|
# [{input: "test", output: "123"}, {input: "test123", output: "456"}]
|
||||||
|
samples = models.TextField(blank=True)
|
||||||
|
test_case_id = models.CharField(max_length=40)
|
||||||
|
hint = RichTextField(blank=True, null=True)
|
||||||
|
create_time = models.DateTimeField(auto_now_add=True)
|
||||||
|
# we can not use auto_now here
|
||||||
|
last_update_time = models.DateTimeField(blank=True, null=True)
|
||||||
|
created_by = models.ForeignKey(User)
|
||||||
|
# ms
|
||||||
|
time_limit = models.IntegerField()
|
||||||
|
# MB
|
||||||
|
memory_limit = models.IntegerField()
|
||||||
|
# special judge related
|
||||||
|
spj = models.BooleanField(default=False)
|
||||||
|
spj_language = models.IntegerField(blank=True, null=True)
|
||||||
|
spj_code = models.TextField(blank=True, null=True)
|
||||||
|
spj_version = models.CharField(max_length=32, blank=True, null=True)
|
||||||
|
visible = models.BooleanField(default=True)
|
||||||
|
total_submit_number = models.IntegerField(default=0)
|
||||||
|
total_accepted_number = models.IntegerField(default=0)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = "problem"
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
def add_submission_number(self):
|
||||||
|
self.accepted_problem_number = models.F("total_submit_number") + 1
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
def add_ac_number(self):
|
||||||
|
self.accepted_problem_number = models.F("total_accepted_number") + 1
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Problem(AbstractProblem):
|
||||||
|
difficulty = models.IntegerField()
|
||||||
|
tags = models.ManyToManyField(ProblemTag)
|
||||||
|
source = models.CharField(max_length=200, blank=True, null=True)
|
||||||
|
|
||||||
|
|
||||||
|
class TestCaseScore(models.Model):
|
||||||
|
test_case_id = models.CharField(max_length=32)
|
||||||
|
score = JSONField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = "test_case_score"
|
3
problem/tests.py
Normal file
3
problem/tests.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
3
problem/views.py
Normal file
3
problem/views.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
Loading…
x
Reference in New Issue
Block a user