-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmodels.py
More file actions
204 lines (155 loc) · 6.7 KB
/
models.py
File metadata and controls
204 lines (155 loc) · 6.7 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
"""
Models per docs/Schema.md section 1: Base tables, Identity, and profiles.
"""
from django.db import models
class ProfileType(models.TextChoices):
GITHUB = "github", "GitHub"
SLACK = "slack", "Slack"
MAILING_LIST = "mailing_list", "Mailing list"
WG21 = "wg21", "WG21"
DISCORD = "discord", "Discord"
YOUTUBE = "youtube", "YouTube"
class GitHubAccountType(models.TextChoices):
USER = "user", "User"
ORGANIZATION = "organization", "Organization"
ENTERPRISE = "enterprise", "Enterprise"
class Identity(models.Model):
"""Canonical user/account; one identity can have multiple BaseProfiles."""
display_name = models.CharField(max_length=255, db_index=True, blank=True)
description = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
verbose_name = "Identity"
verbose_name_plural = "Identities"
ordering = ["id"]
class TmpIdentity(models.Model):
"""Temporary identity for staging (CPPA User Tracker); merged into Identity later."""
display_name = models.CharField(max_length=255, db_index=True, blank=True)
description = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["id"]
verbose_name = "Temporary identity"
verbose_name_plural = "Temporary identities"
class BaseProfile(models.Model):
"""Base table for profiles; extended by platform-specific profile tables."""
identity = models.ForeignKey(
Identity,
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name="profiles",
db_column="identity_id",
)
type = models.CharField(
max_length=20,
choices=ProfileType.choices,
db_index=True,
)
class Meta:
abstract = False
class TempProfileIdentityRelation(models.Model):
"""Staging table: base_profile_id -> target_identity_id (CPPA User Tracker)."""
base_profile = models.ForeignKey(
BaseProfile,
on_delete=models.CASCADE,
related_name="temp_identity_relations",
db_column="base_profile_id",
)
target_identity = models.ForeignKey(
TmpIdentity,
on_delete=models.CASCADE,
related_name="temp_profile_relations",
db_column="target_identity_id",
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["id"]
verbose_name = "Temporary profile-identity relation"
verbose_name_plural = "Temporary profile-identity relations"
class Email(models.Model):
"""Email addresses linked to BaseProfile (one profile, many emails)."""
base_profile = models.ForeignKey(
BaseProfile,
on_delete=models.CASCADE,
related_name="emails",
db_column="base_profile_id",
)
email = models.CharField(max_length=255, db_index=True)
is_primary = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class GitHubAccount(BaseProfile):
"""Profile for GitHub (user/org/enterprise); extends BaseProfile."""
def save(self, *args, **kwargs):
self.type = ProfileType.GITHUB
super().save(*args, **kwargs)
github_account_id = models.BigIntegerField(db_index=True)
username = models.CharField(max_length=255, db_index=True, blank=True)
display_name = models.CharField(max_length=255, db_index=True, blank=True)
avatar_url = models.URLField(max_length=512, blank=True)
account_type = models.CharField(
max_length=20,
choices=GitHubAccountType.choices,
db_index=True,
default=GitHubAccountType.USER,
db_column="account_type",
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class SlackUser(BaseProfile):
"""Profile for Slack; extends BaseProfile."""
def save(self, *args, **kwargs):
self.type = ProfileType.SLACK
super().save(*args, **kwargs)
slack_user_id = models.CharField(max_length=64, unique=True)
username = models.CharField(max_length=255, db_index=True, blank=True)
display_name = models.CharField(max_length=255, db_index=True, blank=True)
avatar_url = models.URLField(max_length=512, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class MailingListProfile(BaseProfile):
"""Profile for mailing list; extends BaseProfile."""
def save(self, *args, **kwargs):
self.type = ProfileType.MAILING_LIST
super().save(*args, **kwargs)
display_name = models.CharField(max_length=255, db_index=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class WG21PaperAuthorProfile(BaseProfile):
"""Profile for WG21 paper authors; extends BaseProfile."""
def save(self, *args, **kwargs):
self.type = ProfileType.WG21
super().save(*args, **kwargs)
display_name = models.CharField(max_length=255, db_index=True, blank=True)
author_alias = models.CharField(max_length=255, blank=True, db_index=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class DiscordProfile(BaseProfile):
"""Profile for Discord; extends BaseProfile."""
def save(self, *args, **kwargs):
self.type = ProfileType.DISCORD
super().save(*args, **kwargs)
discord_user_id = models.BigIntegerField(unique=True, db_index=True)
username = models.CharField(max_length=255, db_index=True, blank=True)
display_name = models.CharField(max_length=255, db_index=True, blank=True)
avatar_url = models.URLField(max_length=512, blank=True)
is_bot = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class YoutubeSpeaker(BaseProfile):
"""YouTube speaker profile.
Uses external_id as canonical identifier (stable across updates). display_name is
a human-readable field and is not used as the identity key.
"""
def save(self, *args, **kwargs):
self.type = ProfileType.YOUTUBE
super().save(*args, **kwargs)
external_id = models.CharField(max_length=255, unique=True)
display_name = models.CharField(max_length=255, db_index=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)