You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.8 KiB
88 lines
2.8 KiB
|
3 years ago
|
from django.db import models
|
||
|
|
|
||
|
|
# Create your models here.
|
||
|
|
|
||
|
|
|
||
|
|
class UserType(object):
|
||
|
|
REGULAR_USER = "Regular User"
|
||
|
|
ADMIN = "Admin"
|
||
|
|
SUPER_ADMIN = "Super Admin"
|
||
|
|
|
||
|
|
|
||
|
|
# class ProblemPermission(object):
|
||
|
|
# NONE = "None"
|
||
|
|
# OWN = "Own"
|
||
|
|
# ALL = "All"
|
||
|
|
|
||
|
|
|
||
|
|
class User(models.Model):
|
||
|
|
user_id = models.CharField(max_length=64, primary_key=True)
|
||
|
|
user_name = models.CharField(max_length=64, unique=True)
|
||
|
|
user_password = models.CharField(max_length=64, null=False)
|
||
|
|
user_password_confirm = models.CharField(max_length=64, null=False)
|
||
|
|
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
||
|
|
user_type = models.CharField(max_length=20,default=UserType.REGULAR_USER)
|
||
|
|
is_active = models.BooleanField(default=True)
|
||
|
|
|
||
|
|
def is_admin(self):
|
||
|
|
return self.admin_type == UserType.ADMIN
|
||
|
|
|
||
|
|
def is_super_admin(self):
|
||
|
|
return self.admin_type == UserType.SUPER_ADMIN
|
||
|
|
|
||
|
|
def is_admin_role(self):
|
||
|
|
return self.admin_type in [UserType.ADMIN, UserType.SUPER_ADMIN]
|
||
|
|
|
||
|
|
|
||
|
|
class UserProfile(models.Model):
|
||
|
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||
|
|
# acm_problems_status examples:
|
||
|
|
# {
|
||
|
|
# "problems": {
|
||
|
|
# "1": {
|
||
|
|
# "status": JudgeStatus.ACCEPTED,
|
||
|
|
# "_id": "1000"
|
||
|
|
# }
|
||
|
|
# },
|
||
|
|
# "contest_problems": {
|
||
|
|
# "1": {
|
||
|
|
# "status": JudgeStatus.ACCEPTED,
|
||
|
|
# "_id": "1000"
|
||
|
|
# }
|
||
|
|
# }
|
||
|
|
# }
|
||
|
|
# acm_problems_status = JSONField(default=dict)
|
||
|
|
# # like acm_problems_status, merely add "score" field
|
||
|
|
# oi_problems_status = JSONField(default=dict)
|
||
|
|
|
||
|
|
user_mail = models.CharField(max_length=64, 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
|
||
|
|
# total_score = models.BigIntegerField(default=0)
|
||
|
|
# submission_number = models.IntegerField(default=0)
|
||
|
|
|
||
|
|
# def add_accepted_problem_number(self):
|
||
|
|
# self.accepted_number = models.F("accepted_number") + 1
|
||
|
|
# self.save()
|
||
|
|
|
||
|
|
# def add_submission_number(self):
|
||
|
|
# self.submission_number = models.F("submission_number") + 1
|
||
|
|
# self.save()
|
||
|
|
|
||
|
|
# # 计算总分时, 应先减掉上次该题所得分数, 然后再加上本次所得分数
|
||
|
|
# def add_score(self, this_time_score, last_time_score=None):
|
||
|
|
# last_time_score = last_time_score or 0
|
||
|
|
# self.total_score = models.F("total_score") - last_time_score + this_time_score
|
||
|
|
# self.save()
|
||
|
|
|
||
|
|
# class Meta:
|
||
|
|
# db_table = "user_profile"
|