From 3bb3becfcf5f0aa47f856fde1834337fe989cf59 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Tue, 1 May 2018 12:54:27 +0800 Subject: [PATCH] alter to text field --- account/migrations/0010_auto_20180501_0436.py | 85 ++++++++++++++++++ account/migrations/0011_auto_20180501_0456.py | 20 +++++ account/models.py | 30 +++---- .../migrations/0003_auto_20180501_0436.py | 20 +++++ announcement/models.py | 2 +- conf/migrations/0004_auto_20180501_0436.py | 35 ++++++++ conf/models.py | 8 +- contest/migrations/0009_auto_20180501_0436.py | 35 ++++++++ contest/models.py | 8 +- options/migrations/0002_auto_20180501_0436.py | 20 +++++ options/models.py | 2 +- problem/migrations/0012_auto_20180501_0436.py | 87 +++++++++++++++++++ problem/models.py | 28 +++--- .../migrations/0012_auto_20180501_0436.py | 36 ++++++++ submission/models.py | 8 +- 15 files changed, 381 insertions(+), 43 deletions(-) create mode 100644 account/migrations/0010_auto_20180501_0436.py create mode 100644 account/migrations/0011_auto_20180501_0456.py create mode 100644 announcement/migrations/0003_auto_20180501_0436.py create mode 100644 conf/migrations/0004_auto_20180501_0436.py create mode 100644 contest/migrations/0009_auto_20180501_0436.py create mode 100644 options/migrations/0002_auto_20180501_0436.py create mode 100644 problem/migrations/0012_auto_20180501_0436.py create mode 100644 submission/migrations/0012_auto_20180501_0436.py diff --git a/account/migrations/0010_auto_20180501_0436.py b/account/migrations/0010_auto_20180501_0436.py new file mode 100644 index 00000000..1e7d65c6 --- /dev/null +++ b/account/migrations/0010_auto_20180501_0436.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2018-05-01 04:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0009_auto_20171125_1514'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='admin_type', + field=models.TextField(default='Regular User'), + ), + migrations.AlterField( + model_name='user', + name='auth_token', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='user', + name='open_api_appkey', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='user', + name='problem_permission', + field=models.TextField(default='None'), + ), + migrations.AlterField( + model_name='user', + name='reset_password_token', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='user', + name='tfa_token', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='user', + name='username', + field=models.TextField(unique=True), + ), + migrations.AlterField( + model_name='userprofile', + name='avatar', + field=models.TextField(default='/public/avatar/default.png'), + ), + migrations.AlterField( + model_name='userprofile', + name='blog', + field=models.URLField(null=True), + ), + migrations.AlterField( + model_name='userprofile', + name='github', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='userprofile', + name='major', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='userprofile', + name='mood', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='userprofile', + name='real_name', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='userprofile', + name='school', + field=models.TextField(null=True), + ), + ] diff --git a/account/migrations/0011_auto_20180501_0456.py b/account/migrations/0011_auto_20180501_0456.py new file mode 100644 index 00000000..5f170fbd --- /dev/null +++ b/account/migrations/0011_auto_20180501_0456.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2018-05-01 04:56 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0010_auto_20180501_0436'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='email', + field=models.TextField(null=True), + ), + ] diff --git a/account/models.py b/account/models.py index ceac9aff..b2b2c21d 100644 --- a/account/models.py +++ b/account/models.py @@ -24,22 +24,22 @@ class UserManager(models.Manager): class User(AbstractBaseUser): - username = models.CharField(max_length=32, unique=True) - email = models.EmailField(max_length=64, null=True) + username = models.TextField(unique=True) + email = models.TextField(null=True) create_time = models.DateTimeField(auto_now_add=True, null=True) # One of UserType - admin_type = models.CharField(max_length=32, default=AdminType.REGULAR_USER) - problem_permission = models.CharField(max_length=32, default=ProblemPermission.NONE) - reset_password_token = models.CharField(max_length=32, null=True) + admin_type = models.TextField(default=AdminType.REGULAR_USER) + problem_permission = models.TextField(default=ProblemPermission.NONE) + reset_password_token = models.TextField(null=True) reset_password_token_expire_time = models.DateTimeField(null=True) # SSO auth token - auth_token = models.CharField(max_length=32, null=True) + auth_token = models.TextField(null=True) two_factor_auth = models.BooleanField(default=False) - tfa_token = models.CharField(max_length=32, null=True) + tfa_token = models.TextField(null=True) session_keys = JSONField(default=list) # open api key open_api = models.BooleanField(default=False) - open_api_appkey = models.CharField(max_length=32, null=True) + open_api_appkey = models.TextField(null=True) is_disabled = models.BooleanField(default=False) USERNAME_FIELD = "username" @@ -87,13 +87,13 @@ class UserProfile(models.Model): # like acm_problems_status, merely add "score" field oi_problems_status = JSONField(default=dict) - real_name = models.CharField(max_length=32, blank=True, null=True) - avatar = models.CharField(max_length=256, default=f"{settings.AVATAR_URI_PREFIX}/default.png") - blog = models.URLField(blank=True, null=True) - mood = models.CharField(max_length=256, blank=True, null=True) - github = models.CharField(max_length=64, blank=True, null=True) - school = models.CharField(max_length=64, blank=True, null=True) - major = models.CharField(max_length=64, blank=True, null=True) + real_name = models.TextField(null=True) + avatar = models.TextField(default=f"{settings.AVATAR_URI_PREFIX}/default.png") + blog = models.URLField(null=True) + mood = models.TextField(null=True) + github = models.TextField(null=True) + school = models.TextField(null=True) + major = models.TextField(null=True) # for ACM accepted_number = models.IntegerField(default=0) # for OI diff --git a/announcement/migrations/0003_auto_20180501_0436.py b/announcement/migrations/0003_auto_20180501_0436.py new file mode 100644 index 00000000..6ecd492f --- /dev/null +++ b/announcement/migrations/0003_auto_20180501_0436.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2018-05-01 04:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('announcement', '0002_auto_20171011_1214'), + ] + + operations = [ + migrations.AlterField( + model_name='announcement', + name='title', + field=models.TextField(), + ), + ] diff --git a/announcement/models.py b/announcement/models.py index a19b06c4..37b8d597 100644 --- a/announcement/models.py +++ b/announcement/models.py @@ -5,7 +5,7 @@ from utils.models import RichTextField class Announcement(models.Model): - title = models.CharField(max_length=64) + title = models.TextField() # HTML content = RichTextField() create_time = models.DateTimeField(auto_now_add=True) diff --git a/conf/migrations/0004_auto_20180501_0436.py b/conf/migrations/0004_auto_20180501_0436.py new file mode 100644 index 00000000..00ede1c2 --- /dev/null +++ b/conf/migrations/0004_auto_20180501_0436.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2018-05-01 04:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('conf', '0003_judgeserver_is_disabled'), + ] + + operations = [ + migrations.AlterField( + model_name='judgeserver', + name='hostname', + field=models.TextField(), + ), + migrations.AlterField( + model_name='judgeserver', + name='ip', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='judgeserver', + name='judger_version', + field=models.TextField(), + ), + migrations.AlterField( + model_name='judgeserver', + name='service_url', + field=models.TextField(null=True), + ), + ] diff --git a/conf/models.py b/conf/models.py index 2317f81c..e0d1c93c 100644 --- a/conf/models.py +++ b/conf/models.py @@ -3,16 +3,16 @@ from django.utils import timezone class JudgeServer(models.Model): - hostname = models.CharField(max_length=128) - ip = models.CharField(max_length=32, blank=True, null=True) - judger_version = models.CharField(max_length=32) + hostname = models.TextField() + ip = models.TextField(null=True) + judger_version = models.TextField() cpu_core = models.IntegerField() memory_usage = models.FloatField() cpu_usage = models.FloatField() last_heartbeat = models.DateTimeField() create_time = models.DateTimeField(auto_now_add=True) task_number = models.IntegerField(default=0) - service_url = models.CharField(max_length=256, blank=True, null=True) + service_url = models.TextField(null=True) is_disabled = models.BooleanField(default=False) @property diff --git a/contest/migrations/0009_auto_20180501_0436.py b/contest/migrations/0009_auto_20180501_0436.py new file mode 100644 index 00000000..eab2add9 --- /dev/null +++ b/contest/migrations/0009_auto_20180501_0436.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2018-05-01 04:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('contest', '0008_contest_allowed_ip_ranges'), + ] + + operations = [ + migrations.AlterField( + model_name='contest', + name='password', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='contest', + name='rule_type', + field=models.TextField(), + ), + migrations.AlterField( + model_name='contest', + name='title', + field=models.TextField(), + ), + migrations.AlterField( + model_name='contestannouncement', + name='title', + field=models.TextField(), + ), + ] diff --git a/contest/models.py b/contest/models.py index 24aace4c..77dcf8e2 100644 --- a/contest/models.py +++ b/contest/models.py @@ -9,13 +9,13 @@ from utils.models import RichTextField class Contest(models.Model): - title = models.CharField(max_length=40) + title = models.TextField() description = RichTextField() # show real time rank or cached rank real_time_rank = models.BooleanField() - password = models.CharField(max_length=30, blank=True, null=True) + password = models.TextField(null=True) # enum of ContestRuleType - rule_type = models.CharField(max_length=36) + rule_type = models.TextField() start_time = models.DateTimeField() end_time = models.DateTimeField() create_time = models.DateTimeField(auto_now_add=True) @@ -88,7 +88,7 @@ class OIContestRank(AbstractContestRank): class ContestAnnouncement(models.Model): contest = models.ForeignKey(Contest) - title = models.CharField(max_length=128) + title = models.TextField() content = RichTextField() created_by = models.ForeignKey(User) visible = models.BooleanField(default=True) diff --git a/options/migrations/0002_auto_20180501_0436.py b/options/migrations/0002_auto_20180501_0436.py new file mode 100644 index 00000000..2e76be77 --- /dev/null +++ b/options/migrations/0002_auto_20180501_0436.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2018-05-01 04:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('options', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='sysoptions', + name='key', + field=models.TextField(db_index=True, unique=True), + ), + ] diff --git a/options/models.py b/options/models.py index 04dee5e2..30db2f62 100644 --- a/options/models.py +++ b/options/models.py @@ -3,5 +3,5 @@ from utils.models import JSONField class SysOptions(models.Model): - key = models.CharField(max_length=128, unique=True, db_index=True) + key = models.TextField(unique=True, db_index=True) value = JSONField() diff --git a/problem/migrations/0012_auto_20180501_0436.py b/problem/migrations/0012_auto_20180501_0436.py new file mode 100644 index 00000000..77b5c781 --- /dev/null +++ b/problem/migrations/0012_auto_20180501_0436.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2018-05-01 04:36 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import utils.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('problem', '0011_fix_problem_ac_count'), + ] + + operations = [ + migrations.AlterField( + model_name='problem', + name='_id', + field=models.TextField(db_index=True), + ), + migrations.AlterField( + model_name='problem', + name='contest', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='contest.Contest'), + ), + migrations.AlterField( + model_name='problem', + name='difficulty', + field=models.TextField(), + ), + migrations.AlterField( + model_name='problem', + name='hint', + field=utils.models.RichTextField(null=True), + ), + migrations.AlterField( + model_name='problem', + name='last_update_time', + field=models.DateTimeField(null=True), + ), + migrations.AlterField( + model_name='problem', + name='rule_type', + field=models.TextField(), + ), + migrations.AlterField( + model_name='problem', + name='source', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='problem', + name='spj_code', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='problem', + name='spj_language', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='problem', + name='spj_version', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='problem', + name='test_case_id', + field=models.TextField(), + ), + migrations.AlterField( + model_name='problem', + name='title', + field=models.TextField(), + ), + migrations.AlterField( + model_name='problem', + name='total_score', + field=models.IntegerField(default=0), + ), + migrations.AlterField( + model_name='problemtag', + name='name', + field=models.TextField(), + ), + ] diff --git a/problem/models.py b/problem/models.py index 12a54228..29e317bd 100644 --- a/problem/models.py +++ b/problem/models.py @@ -8,7 +8,7 @@ from utils.constants import Choices class ProblemTag(models.Model): - name = models.CharField(max_length=30) + name = models.TextField() class Meta: db_table = "problem_tag" @@ -27,26 +27,26 @@ class ProblemDifficulty(object): class Problem(models.Model): # display ID - _id = models.CharField(max_length=24, db_index=True) - contest = models.ForeignKey(Contest, null=True, blank=True) + _id = models.TextField(db_index=True) + contest = models.ForeignKey(Contest, null=True) # for contest problem is_public = models.BooleanField(default=False) - title = models.CharField(max_length=128) + title = models.TextField() # HTML description = RichTextField() input_description = RichTextField() output_description = RichTextField() # [{input: "test", output: "123"}, {input: "test123", output: "456"}] samples = JSONField() - test_case_id = models.CharField(max_length=32) + test_case_id = models.TextField() # [{"input_name": "1.in", "output_name": "1.out", "score": 0}] test_case_score = JSONField() - hint = RichTextField(blank=True, null=True) + hint = RichTextField(null=True) languages = JSONField() template = JSONField() create_time = models.DateTimeField(auto_now_add=True) # we can not use auto_now here - last_update_time = models.DateTimeField(blank=True, null=True) + last_update_time = models.DateTimeField(null=True) created_by = models.ForeignKey(User) # ms time_limit = models.IntegerField() @@ -54,17 +54,17 @@ class Problem(models.Model): memory_limit = models.IntegerField() # special judge related spj = models.BooleanField(default=False) - spj_language = models.CharField(max_length=32, blank=True, null=True) - spj_code = models.TextField(blank=True, null=True) - spj_version = models.CharField(max_length=32, blank=True, null=True) + spj_language = models.TextField(null=True) + spj_code = models.TextField(null=True) + spj_version = models.TextField(null=True) spj_compile_ok = models.BooleanField(default=False) - rule_type = models.CharField(max_length=32) + rule_type = models.TextField() visible = models.BooleanField(default=True) - difficulty = models.CharField(max_length=32) + difficulty = models.TextField() tags = models.ManyToManyField(ProblemTag) - source = models.CharField(max_length=200, blank=True, null=True) + source = models.TextField(null=True) # for OI mode - total_score = models.IntegerField(default=0, blank=True) + total_score = models.IntegerField(default=0) submission_number = models.BigIntegerField(default=0) accepted_number = models.BigIntegerField(default=0) # {JudgeStatus.ACCEPTED: 3, JudgeStaus.WRONG_ANSWER: 11}, the number means count diff --git a/submission/migrations/0012_auto_20180501_0436.py b/submission/migrations/0012_auto_20180501_0436.py new file mode 100644 index 00000000..b8108729 --- /dev/null +++ b/submission/migrations/0012_auto_20180501_0436.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2018-05-01 04:36 +from __future__ import unicode_literals + +from django.db import migrations, models +import utils.shortcuts + + +class Migration(migrations.Migration): + + dependencies = [ + ('submission', '0011_fix_submission_number'), + ] + + operations = [ + migrations.AlterField( + model_name='submission', + name='id', + field=models.TextField(db_index=True, default=utils.shortcuts.rand_str, primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name='submission', + name='ip', + field=models.TextField(null=True), + ), + migrations.AlterField( + model_name='submission', + name='language', + field=models.TextField(), + ), + migrations.AlterField( + model_name='submission', + name='username', + field=models.TextField(), + ), + ] diff --git a/submission/models.py b/submission/models.py index 0c4aeda9..261052e9 100644 --- a/submission/models.py +++ b/submission/models.py @@ -21,22 +21,22 @@ class JudgeStatus: class Submission(models.Model): - id = models.CharField(max_length=32, default=rand_str, primary_key=True, db_index=True) + id = models.TextField(default=rand_str, primary_key=True, db_index=True) contest = models.ForeignKey(Contest, null=True) problem = models.ForeignKey(Problem) create_time = models.DateTimeField(auto_now_add=True) user_id = models.IntegerField(db_index=True) - username = models.CharField(max_length=30) + username = models.TextField() code = models.TextField() result = models.IntegerField(db_index=True, default=JudgeStatus.PENDING) # 从JudgeServer返回的判题详情 info = JSONField(default=dict) - language = models.CharField(max_length=20) + language = models.TextField() shared = models.BooleanField(default=False) # 存储该提交所用时间和内存值,方便提交列表显示 # {time_cost: "", memory_cost: "", err_info: "", score: 0} statistic_info = JSONField(default=dict) - ip = models.CharField(max_length=32, null=True, blank=True) + ip = models.TextField(null=True) def check_user_permission(self, user, check_share=True): return self.user_id == user.id or \