@@ -66,7 +66,7 @@ class UserModel(db.Model):
66
66
timezone = db .Column (db .Enum (Timezone ))
67
67
68
68
def __init__ (self , name , username , password , email , terms_and_conditions_checked ):
69
- """Initialises userModel class with name, username, password, email, and terms_and_conditions_checked. """
69
+ """Initialises userModel class with name, username, password, email, and terms_and_conditions_checked."""
70
70
## required fields
71
71
72
72
self .name = name
@@ -123,49 +123,49 @@ def json(self):
123
123
}
124
124
125
125
def __repr__ (self ):
126
- """Returns the user's name and username. """
126
+ """Returns the user's name and username."""
127
127
return f"User name { self .name } . Username is { self .username } ."
128
128
129
129
@classmethod
130
130
def find_by_username (cls , username : str ) -> "UserModel" :
131
- """Returns the user that has the username we searched for. """
131
+ """Returns the user that has the username we searched for."""
132
132
return cls .query .filter_by (username = username ).first ()
133
133
134
134
@classmethod
135
135
def find_by_email (cls , email : str ) -> "UserModel" :
136
- """Returns the user that has the email we searched for. """
136
+ """Returns the user that has the email we searched for."""
137
137
return cls .query .filter_by (email = email ).first ()
138
138
139
139
@classmethod
140
140
def find_by_id (cls , _id : int ) -> "UserModel" :
141
- """Returns the user that has the id we searched for. """
141
+ """Returns the user that has the id we searched for."""
142
142
return cls .query .filter_by (id = _id ).first ()
143
143
144
144
@classmethod
145
145
def get_all_admins (cls , is_admin = True ):
146
- """Returns all the admins. """
146
+ """Returns all the admins."""
147
147
return cls .query .filter_by (is_admin = is_admin ).all ()
148
148
149
149
@classmethod
150
150
def is_empty (cls ) -> bool :
151
- """Returns a boolean if the Usermodel is empty or not. """
151
+ """Returns a boolean if the Usermodel is empty or not."""
152
152
return cls .query .first () is None
153
153
154
154
def set_password (self , password_plain_text : str ) -> None :
155
- """Sets user password when they create an account or when they are changing their password. """
155
+ """Sets user password when they create an account or when they are changing their password."""
156
156
self .password_hash = generate_password_hash (password_plain_text )
157
157
158
158
# checks if password is the same, using its hash
159
159
def check_password (self , password_plain_text : str ) -> bool :
160
- """Returns a boolean if password is the same as it hash or not. """
160
+ """Returns a boolean if password is the same as it hash or not."""
161
161
return check_password_hash (self .password_hash , password_plain_text )
162
162
163
163
def save_to_db (self ) -> None :
164
- """Adds a user to the database. """
164
+ """Adds a user to the database."""
165
165
db .session .add (self )
166
166
db .session .commit ()
167
167
168
168
def delete_from_db (self ) -> None :
169
- """Deletes a user from the database. """
169
+ """Deletes a user from the database."""
170
170
db .session .delete (self )
171
171
db .session .commit ()
0 commit comments