-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmodels.py
190 lines (157 loc) · 5.22 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
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
"""
Contains classes which describe the structure of the Mongo Database.
"""
# flask_graphene_mongo/models.py
from mongoengine import Document, EmbeddedDocument
from mongoengine.fields import (
BooleanField,
DateTimeField,
DictField,
EmbeddedDocumentListField,
EnumField,
GenericReferenceField,
IntField,
StringField,
ReferenceField,
EmbeddedDocumentField,
ListField,
GeoPointField,
)
from utils import (
phone_number_regex,
email_regex,
ProgramType,
SectionType,
Weekday,
Quarter,
CourseType,
)
class College(Document):
"""
A sub-college of Cal Poly. E.g. College of Engineering
"""
meta = {"collection": "college"}
name = StringField(required=True, primary_key=True)
description = StringField()
departments = ListField(ReferenceField("Department"), default=list)
class Department(Document):
"""
An area of study within a college. E.g. Computer Science Department
"""
meta = {"collection": "department"}
name = StringField(required=True, primary_key=True)
description = StringField()
college = ReferenceField("College")
programs = ListField(ReferenceField("Program"))
faculty = ListField(ReferenceField("Professor"))
courses = ListField(ReferenceField("Course"))
office = ReferenceField("Room")
phone_number = StringField(regex=phone_number_regex)
associated_clubs = ListField(ReferenceField("Club"))
class Program(Document):
"""
A field of study taken up by a student. E.g. majoring in Computer Science
"""
meta = {"collection": "program"}
name = StringField(required=True, primary_key=True)
description = StringField()
graduate_level = BooleanField(default=False)
# e.g. major, minor TODO: make this an enum
program_types = ListField(StringField())
# TODO: maybe split this out into major support and GE courses
curriculum = ListField(ReferenceField("Course"))
department = ReferenceField("Department")
class Building(Document):
"""
Campus-owned buildings
"""
meta = {"collection": "building"}
name = StringField(required=True)
description = StringField(required=True)
coordinates = GeoPointField()
rooms = ListField(ReferenceField("Room"))
resources = DictField()
class Room(Document):
"""
A publically accessible room inside a campus building.
"""
meta = {"collection": "room"}
building_name = StringField(required=True)
building = ReferenceField("Building")
room_number = StringField(required=True, primary_key=True)
class Officer(EmbeddedDocument):
"""
A leader of a Cal Poly student organization.
"""
name = StringField(required=True)
major = StringField()
position = StringField()
email = StringField(regex=email_regex)
class Club(Document):
"""
A Cal Poly student organization
"""
meta = {"collection": "club"}
name = StringField(required=True, primary_key=True)
officers = EmbeddedDocumentListField(Officer, required=True)
email = StringField(regex=email_regex)
phone = StringField(regex=phone_number_regex)
social_media: DictField()
advisor = StringField()
class OfficeHours(EmbeddedDocument):
"""
A block of time a Professor sets aside to help students.
"""
start_time = DateTimeField()
end_time = DateTimeField()
link = StringField()
# TODO: Make this an enum Weekday
weekdays = ListField(field=StringField())
class Professor(Document):
"""
A person who teaches a class at Cal Poly
"""
meta = {"collection": "professor"}
name = StringField(required=True)
bio = StringField()
email = StringField(regex=email_regex)
phone_number = StringField(regex=phone_number_regex)
sections = ListField(ReferenceField("Section"))
office = ReferenceField("Room")
office_hours = EmbeddedDocumentListField(OfficeHours)
website = StringField()
class Course(Document):
"""
An abstract course that is taught at Cal Poly. For specific sections/classes taught in a specific quarter, see Section
"""
meta = {"collection": "course"}
name = StringField(required=True)
description = StringField(required=True)
# TODO: Should this be a list, since CSC 357 is also CPE 357
course_id = StringField(required=True)
department = ReferenceField("Department", required=True)
units = IntField(required=True)
prerequisites = ListField(ReferenceField("Course"))
sections = ListField(ReferenceField("Section"))
# TODO: Make Quarter enum
usually_offered = ListField(StringField())
# TODO: Make CourseType enum
course_type = ListField(StringField())
class Section(Document):
"""
An instance of a course that students attend.
"""
meta = {"collection": "section"}
course = ReferenceField("Course")
section_id = IntField(required=True, primary_key=True)
# TODO: Make enum type SectionType
type = StringField()
asynchronous = BooleanField()
start_time = DateTimeField()
end_time = DateTimeField()
# TODO: Make enum of Weekdays
weekdays = ListField(StringField())
room = ReferenceField("Room")
professors = ListField(ReferenceField("Professor"))
# TODO: Make enum of Quarter
quarter = StringField()