-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathaccount.py
More file actions
169 lines (152 loc) · 4.17 KB
/
Copy pathaccount.py
File metadata and controls
169 lines (152 loc) · 4.17 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
from enum import Enum
from typing import List
from django.db import models
from setfield import SetField
from home.models.mixins.privacyprotectedfields import (
PrivacyProtectedFieldsMixin,
PrivateFieldInfo,
FieldType,
)
SAN_FRANCISCO_ZIP_CODES = set(
[
"94102",
"94103",
"94104",
"94105",
"94107",
"94108",
"94109",
"94110",
"94111",
"94112",
"94114",
"94115",
"94116",
"94117",
"94118",
"94121",
"94122",
"94123",
"94124",
"94127",
"94129",
"94130",
"94131",
"94132",
"94133",
"94134",
"94158",
]
)
class GenderLabels(Enum):
CF = "Female"
CM = "Male"
TF = "Trans Female"
TM = "Trans Male"
NB = "Non-binary"
OT = "Other"
DA = "Decline to answer"
class RaceLabels(Enum):
NA = "American Indian or Alaska Native"
BL = "Black"
AS = "Asian"
PI = "Native Hawaiian or other Pacific Islander"
WH = "White"
OT = "Other"
DA = "Decline to answer"
class SexualOrientationLabels(Enum):
BS = "Bisexual"
SG = "SameGenderLoving"
US = "Unsure"
HS = "Heterosexual"
OT = "Other"
DA = "Decline to answer"
class IsLatinoLabels(Enum):
YE = "Yes"
NO = "No"
DA = "Decline to answer"
# Note: Maybe inherit from Django's User model?
class Account(models.Model, PrivacyProtectedFieldsMixin):
"""
Stores a single user account as identified by email. This is created when
the app is installed and the user signs up for the first time and is has
multiple devices - :model: `home.Device` associated with it
"""
email = models.EmailField(
unique=True, help_text="Email which uniquely identifies an account"
)
name = models.CharField(max_length=250, help_text="User's name")
zip = models.CharField(max_length=25, help_text="User's zipcode")
age = models.IntegerField(help_text="User's age")
is_sf_resident = models.BooleanField(
null=True,
help_text="Whether the user is a SF resident or not, based on zip",
)
is_latino = models.CharField(
max_length=2,
null=True,
blank=True,
help_text="Latino or Hispanic origin",
)
race = SetField(
models.CharField(
max_length=2, choices=list(RaceLabels.__members__.items())
),
default=list,
blank=True,
)
race_other = models.CharField(
max_length=75,
null=True,
blank=True,
help_text="Free-form text field for 'race' value 'OT'",
)
gender = models.CharField(
max_length=2,
null=True,
blank=True,
help_text="Self-identified gender identity of user",
)
gender_other = models.CharField(
max_length=75,
null=True,
blank=True,
help_text="Free-form text field for 'gender' value 'OT'",
)
sexual_orien = models.CharField(
max_length=2,
null=True,
blank=True,
help_text="Self-identified sexual orientation of user",
)
sexual_orien_other = models.CharField(
max_length=75,
null=True,
blank=True,
help_text="Free-form text field for 'sexual_orien' value 'OT'",
)
is_tester = models.BooleanField(
default=False, help_text="User is an app tester"
)
contests = models.ManyToManyField(
"Contest",
blank=True,
help_text="All the contests the account has enrolled in",
)
created = models.DateTimeField(
auto_now_add=True, help_text="Accounts creation timestamp"
)
updated = models.DateTimeField(
auto_now=True, help_text="Accounts updation timestamp"
)
def __str__(self):
return f"{self.name} | {self.email}"
@staticmethod
def privacy_protected_fields() -> List[PrivateFieldInfo]:
"""Privacy protected fields overrides the PrivacyProtectedFields mixin.c"""
return [
PrivateFieldInfo(name="email", type=FieldType.EMAIL),
PrivateFieldInfo(name="name", type=FieldType.NAME),
]
class Meta:
ordering = ("-created",)