forked from czaber/kotik-konik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
118 lines (95 loc) · 3.61 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
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, DateTime
from sqlalchemy.orm import relationship
import datetime
engine = create_engine('sqlite:///kotik.db', echo=True)
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
uid = Column(Integer, primary_key=True)
firstname = Column(String, nullable=False)
lastname = Column(String, nullable=False)
nickname = Column(String, nullable=False)
email = Column(String, nullable=False, unique=True)
quiz_points = Column(Integer, default=0)
avatar = Column(String)
university = Column(String)
faculty = Column(String)
year_of_study = Column(Integer)
github_username = Column(String)
reddit_username = Column(String)
linux_distribution = Column(String)
known_technologies = Column(String)
wants_to_learn = Column(String)
given_answers = relationship("GivenAnswer")
willingness_to_attend_meetings = Column(String)
active = Column(Boolean, nullable=False, default=False)
def __init__(self, firstname, lastname, nickname, email):
self.firstname = firstname
self.lastname = lastname
self.nickname = nickname
self.email = email
def get_profile_progress_in_percents(self):
profile_points = 10
total_profile_points = 85
if self.avatar:
profile_points += 10
if self.university:
profile_points += 5
if self.faculty:
profile_points += 5
if self.year_of_study:
profile_points += 5
if self.github_username:
profile_points += 15
if self.reddit_username:
profile_points += 15
if self.linux_distribution:
profile_points += 10
if self.known_technologies:
profile_points += 5
if self.wants_to_learn:
profile_points += 5
return 100.0 * profile_points/total_profile_points
def __repr__(self):
fullname = "%s %s" % (self.firstname, self.lastname)
return "<User('%s', '%s', '%s')>" % (fullname, self.nickname, self.email)
class Question(Base):
__tablename__ = 'questions'
id = Column(Integer, primary_key=True)
question = Column(String, nullable=False)
answers = relationship("Answer")
def __init__(self, question):
self.question = question
def __repr__(self):
return "<Question('%i', '%s')>" % (self.id, self.question)
class Answer(Base):
__tablename__ = 'answers'
id = Column(Integer, primary_key=True)
answer = Column(String, nullable=False)
correct = Column(Boolean, nullable=False, default=False)
question_id = Column(Integer, ForeignKey('questions.id'))
given_answers = relationship("GivenAnswer")
def __init__(self, answer, correct):
self.answer = answer
self.correct = correct
def __repr__(self):
return "<Answer('%i', '%i')>" % (self.id, self.question_id)
class GivenAnswer(Base):
__tablename__ = 'givenanswers'
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('users.uid'))
answer_id = Column(Integer, ForeignKey('answers.id'))
datetime = Column(DateTime, default=datetime.datetime.now)
def __init__(self, answer_id):
self.answer_id = answer_id
def __repr__(self):
return "<GivenAnswer('%i', '%i')>" % (self.id, self.answer_id)
users_table = User.__table__
questions_table = Question.__table__
answers_table = Answer.__table__
given_answers_table = GivenAnswer.__table__
metadata = Base.metadata
if __name__ == "__main__":
metadata.create_all(engine)