-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.py
50 lines (37 loc) · 1.49 KB
/
models.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Courseware models"""
from django.conf import settings
from django.db import models
from courseware.constants import COURSEWARE_PLATFORM_CHOICES, PLATFORM_EDX
from mitxpro.models import TimestampedModel
class CoursewareUser(TimestampedModel):
"""Model representing a User in a courseware platform"""
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="courseware_users",
)
platform = models.CharField(
max_length=20, choices=COURSEWARE_PLATFORM_CHOICES, default=PLATFORM_EDX
)
has_been_synced = models.BooleanField(
default=True,
help_text="Indicates whether a corresponding user has been created on the courseware platform",
)
def __str__(self):
return f"CoursewareUser for {self.user} in {self.platform}"
class Meta:
unique_together = ("user", "platform")
class OpenEdxApiAuth(TimestampedModel):
"""Model that stores OAuth2 tokens for authenticating Open edX API calls"""
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="openedx_api_auth",
)
refresh_token = models.CharField(max_length=128)
access_token = models.CharField(null=True, max_length=128) # noqa: DJ001
access_token_expires_on = models.DateTimeField(null=True)
def __str__(self):
return f"OpenEdxApiAuth for {self.user}"
class Meta:
index_together = ("user", "access_token_expires_on")