-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.py
66 lines (51 loc) · 1.86 KB
/
user.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
from flask_login import UserMixin
from app import db
class User(db.Model, UserMixin):
# Class attributes, could be inherited
id = db.Column(db.Integer, primary_key=True, unique=True) # primaryfro keys are required by SQLAlchemy
email = db.Column(db.String, unique=True)
password = db.Column(db.String(100))
name = db.Column(db.String(100))
authenticated = db.Column(db.Boolean, default=False)
calories_daily = db.Column(db.Float, default=-1)
guided = db.Column(db.Boolean, default=False)
# dietary_type = db.Column(db.String(100), default=None)
# nutrition = db.Column(db.)
words = db.Column(db.String)
bmi = db.Column(db.String)
def __init__(self, email, name, password):
self.email = email
self.password = password
self.name = name
def is_active(self):
"""True, as all users are active."""
return True
# IF YOU ENCOUNTERED SOME ERRORS, READ THE DOCUMENT FIRST ! YOU MAY FIND THINGS USEFUL!
def get_id(self):
"""Return the id to satisfy Flask-Login's requirements."""
return self.id
def is_authenticated(self):
"""Return True if the user is authenticated."""
return self.authenticated
def is_anonymous(self):
"""False, as anonymous users aren't supported."""
return False
def get_words(self):
return self.words.split(',')
def add_dietary(self, word):
self.words += ',' + word
def get_calories_daily(self):
return self.calories_daily
def get_rec(self):
"""Get recommended amount of every nutrient"""
return {'cal': 0}
def get_bmi(self):
try:
return int(self.bmi)
except ValueError:
return 0
def is_guided(self):
if not self.guided:
self.guided = True
return False
return self.guided