-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
72 lines (58 loc) · 2 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
"""Houses the schema for the database and is used to create/update the index"""
from elasticsearch_dsl import (
Document,
Text,
Keyword,
Boolean,
Short,
InnerDoc,
Nested,
Join,
Integer,
Object
)
class StudentVote(InnerDoc):
student_id = Keyword(required=True)
choice = Integer()
class MentorProject(Document):
name = Keyword(required=True)
company = Text()
bio = Text()
backgroundRural = Boolean(required=True)
preferStudentUnderRep = Short(required=True) # (0-2)
preferToolExistingKnowledge = Boolean(required=True)
okExtended = Boolean(required=True)
okTimezoneDifference = Boolean(required=True)
timezone = Integer(required=True) # +- UTC
id = Keyword(required=True)
proj_description = Text(required=True)
proj_tags = Keyword(multi=True)
numStudentsSelected = Short()
listStudentsSelected = Nested(StudentVote)
track = Keyword(required=True)
class Index:
name = "mentors_index"
settings = {
"number_of_shards": 1,
"number_of_replicas": 0,
}
def add_vote(self, student_id, choice):
self.listStudentsSelected.append(StudentVote(student_id=student_id, choice=choice))
def save(self, **kwargs):
self.numStudentsSelected = 0
return super().save(**kwargs)
class StudentSchema(Document):
"""Ignored by elastic, is here for my refrence, may be implemented later"""
id = Keyword(required=True)
name = Keyword(required=True)
rural = Boolean(required=True)
underrepresented = Boolean(required=True)
requireExtended = Boolean(required=True)
timezone = Integer(required=True)
interestCompanies = Keyword(multi=True, required=True)
interestTags = Keyword(multi=True, required=True)
if __name__ == "__main__":
from elasticsearch_dsl import connections
connections.create_connection(hosts=["10.0.3.33:9200"], timeout=20)
index_template = MentorProject._index.as_template("base")
index_template.save()