def enter_user(self): if not self.username.text: self.error_lbl.text = 'Username field is empty' return 0 if not self.password.text: self.error_lbl.text = 'Password field is empty' return 0 conn = sqlite3.connect('dailymap.db') cursor = conn.cursor() cursor.execute("SELECT id FROM users WHERE username=? AND password=?", (self.username.text, self.password.text)) gl.USER_ID = cursor.fetchall() conn.close() if not gl.USER_ID: self.error_lbl.text = 'Incorrect username or password' return 0 #release the variable from the list and the tuple gl.USER_ID = gl.USER_ID[0][0] # USER_ID = [(ID,)] -> (ID,) -> ID #********** to update the information when you login to the system ********** self.win_screen.current = 'application_window' #change screen display_right_corner_username( ) # shows in the right top corner after the entrance sleep_mode_display() #show your time sleep in sleep_window display_place_goals() #show your goals in thw goals_creation window display_place_plan_goals() #show yout week plan goals display_schedule() display_categories()
def register_user(self): if not self.username.text: self.error_lbl.text = 'Username field is empty' return 0 if not self.password.text: self.error_lbl.text = 'Password field is empty' return 0 if not self.confirm_password.text: self.error_lbl.text = 'Confirm password field is empty' return 0 if len(self.username.text) > 25: self.error_lbl.text = 'The username is too long' return 0 if gl.check_input(self.username.text) or gl.check_input( self.password.text): self.error_lbl.text = 'Invalid characters entered' return 0 if self.password.text != self.confirm_password.text: self.error_lbl.text = "Passwords don't match" return 0 conn = sqlite3.connect('dailymap.db') cursor = conn.cursor() cursor.execute("SELECT id FROM users WHERE username=?", [ (self.username.text) ]) # проверяем есть ли уже пользователь с таким именем res = cursor.fetchall() conn.close() if res: self.error_lbl.text = 'This name is used' return 0 #add user to the database conn = sqlite3.connect('dailymap.db') cursor = conn.cursor() cursor.executemany( "INSERT INTO users (username, password, icon) VALUES (?, ?, ?)", [(self.username.text, self.password.text, 'user.png')]) conn.commit() cursor.execute("SELECT id FROM users WHERE username=? AND password=?", (self.username.text, self.password.text)) gl.USER_ID = cursor.fetchall() gl.USER_ID = gl.USER_ID[0][0] # USER_ID = [(ID,)] -> (ID,) ->ID #*** update all tables cursor.executemany( "INSERT INTO sleeptime (user_id, bedtime, wakeup) VALUES (?, ?, ?)", [(gl.USER_ID, datetime.datetime( 2018, 1, 1, 23, 0), datetime.datetime(2018, 1, 1, 7, 0))]) conn.commit() conn.close() # ********** to update the information when you login to the system ********** self.win_screen.current = 'application_window' # change screen display_right_corner_username( ) # shows in the right top corner after the entrance sleep_mode_display() # show your time sleep in sleep_window display_place_goals() # show your goals in thw goals_creation window display_place_plan_goals() # show yout week plan goals display_schedule()
def save_time(self): hour_bedtime = int(self.bedtime.ids._hour.text) minute_bedtime = int(self.bedtime.ids._minute.text) hour_wakeup = int(self.wakeup.ids._hour.text) minute_wakeup = int(self.wakeup.ids._minute.text) bedtime=datetime.datetime(2018,1,1,hour_bedtime, minute_bedtime) wakeup = datetime.datetime(2018, 1, 1, hour_wakeup, minute_wakeup) conn = sqlite3.connect('dailymap.db', detect_types=sqlite3.PARSE_DECLTYPES) cursor = conn.cursor() cursor.execute("update sleeptime set bedtime=?, wakeup=? where user_id = ?", (bedtime, wakeup, gl.USER_ID,)) conn.commit() conn.close() sleep_mode_display() display_place_plan_goals()
def add_goal(self): conn = sqlite3.connect('dailymap.db', detect_types=sqlite3.PARSE_DECLTYPES) cursor = conn.cursor() cursor.execute("select count(*) from goals where user_id =?", (gl.USER_ID, )) pos = cursor.fetchall() pos = str(pos[0][0] + 1) title = 'New goal {}'.format(pos) cursor.execute( "insert into goals (user_id, title, icon, comments, pos) values(?,?,?,?,?)", (gl.USER_ID, title, 'book.png', 'Comments', pos)) conn.commit() conn.close() display_place_goals() display_place_plan_goals()
def delete_goal(self): global goal_id if goal_id: conn = sqlite3.connect('dailymap.db', detect_types=sqlite3.PARSE_DECLTYPES) cursor = conn.cursor() cursor.execute("select * from goals where id =? and user_id = ?", ( goal_id, gl.USER_ID, )) result = cursor.fetchall() conn.close() if result: conn = sqlite3.connect('dailymap.db', detect_types=sqlite3.PARSE_DECLTYPES) cursor = conn.cursor() cursor.execute( "select * from goals_plan_daily where goal_id =?", (goal_id, )) in_goals_plan = cursor.fetchall() if in_goals_plan: conn = sqlite3.connect( 'dailymap.db', detect_types=sqlite3.PARSE_DECLTYPES) cursor = conn.cursor() cursor.execute( "insert into goals_archive (goal_id, user_id, title, icon, comments) values (?,?,?,?,?)", (goal_id, gl.USER_ID, result[0][2], result[0][3], result[0][4])) conn.commit() conn.close() conn = sqlite3.connect('dailymap.db', detect_types=sqlite3.PARSE_DECLTYPES) cursor = conn.cursor() cursor.execute("delete from goals where id =? and user_id = ?", ( goal_id, gl.USER_ID, )) conn.commit() conn.close() display_place_goals() display_place_plan_goals() self.clear_info()
def change_goal(self): title = self.ids._title_info.text comments = self.ids._comments_info.text conn = sqlite3.connect('dailymap.db', detect_types=sqlite3.PARSE_DECLTYPES) cursor = conn.cursor() cursor.execute("select count(*) from goals where user_id=?", (gl.USER_ID, )) amount_of_goals = cursor.fetchall() conn.close() new_pos = None if self.ids._pos_info.text: new_pos = int(self.ids._pos_info.text) if 1 <= int( self.ids._pos_info.text) <= amount_of_goals[0][0] else None global goal_id if title and comments and new_pos and goal_id: conn = sqlite3.connect('dailymap.db', detect_types=sqlite3.PARSE_DECLTYPES) cursor = conn.cursor() cursor.execute("select pos from goals where id=?", (goal_id, )) last_pos = cursor.fetchall() last_pos = last_pos[0][0] if last_pos > new_pos: cursor.execute( "select id from goals where pos>=? and pos<? and user_id=?", ( new_pos, last_pos, gl.USER_ID, )) result = cursor.fetchall() for value in result: cursor.execute( "update goals set pos = pos + 1 where id=? and user_id = ?", ( value[0], gl.USER_ID, )) conn.commit() #cursor.execute("update goals set pos = pos + 1 where id=(select id from goals where ? >= pos < ? and user_id = ?)",(new_pos, last_pos, gl.USER_ID,)) elif last_pos < new_pos: cursor.execute( "select id from goals where pos > ? and pos<=? and user_id=?", ( last_pos, new_pos, gl.USER_ID, )) result = cursor.fetchall() for value in result: cursor.execute( "update goals set pos = pos - 1 where id=? and user_id = ?", ( value[0], gl.USER_ID, )) conn.commit() cursor.execute( "update goals set title=?, comments=?, pos=? where id = ?", (title, comments, new_pos, goal_id)) conn.commit() conn.close() display_place_goals() display_place_plan_goals() self.clear_info()