-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmodels.py
More file actions
37 lines (27 loc) · 1.24 KB
/
models.py
File metadata and controls
37 lines (27 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
id = models.AutoField(primary_key=True)
is_teacher = models.BooleanField(default=False, null=False)
is_student = models.BooleanField(default=True, null=False)
is_imported = models.BooleanField(default=False, null=False)
# rating
is_gauntlet_running = models.BooleanField(default=False, null=False)
last_gauntlet_run = models.DateTimeField(null=True)
@property
def has_management_permission(self) -> bool:
return self.is_teacher or self.is_staff or self.is_superuser
@property
def short_name(self):
return self.username
def get_social_auth(self):
return self.social_auth.get(provider="ion")
def save(self, *args, **kwargs):
existing_user = User.objects.filter(username=self.username, is_imported=True).first()
if existing_user:
from ..games.models import Submission # cannot import at top of file b/c Submission references User (circular import)
Submission.objects.filter(user=existing_user).update(user=self)
existing_user.delete()
super().save(*args, **kwargs)
def __str__(self):
return self.short_name