def save_client(self, client: VKinderClient, force_country_update=False): """ Manual UPSERT of single client in DB """ log(f'[{client.fname} {client.lname}] Saving client\'s info to DB', is_debug_msg=self.debug_mode) client_db = self.__session.query(Clients).filter( Clients.vk_id == client.vk_id).first() if not client_db: client_db = Clients() client_db.vk_id = client.vk_id client_db.fname = client.fname client_db.lname = client.lname client_db.domain = client.domain # preserve country_id and country_name, restore them in case client revisit if not client_db.id or force_country_update: client_db.country_id = client.country_id client_db.country_name = client.country_name elif client_db.id: client.country_id = client_db.country_id client.country_name = client_db.country_name client_db.city_id = client.city_id client_db.city_name = client.city_name client_db.hometown = client.hometown client_db.birth_date = client.birth_date client_db.birth_day = client.birth_day client_db.birth_month = client.birth_month client_db.birth_year = client.birth_year client_db.sex_id = client.sex_id client_db.updated = client.last_contact self.__session.add(client_db) self.__session.commit() # load new id from base if client was just created client.db_id = client_db.id client.searches = self.load_searches(client)
def do_show_search_history(self, client: VKinderClient): client.status = STATUSES['search_history_input_wait'] client.rating_filter = RATINGS['new'] searches = self.db.load_searches(client) client.searches = searches history = [] for index, searches in enumerate(searches, 1): history.append( str(index) + '. ' + PHRASES['x_x_x_from_x_to_x'].format( searches.city_name, SEXES[searches.sex_id], LOVE_STATUSES[ searches.status_id], searches.min_age, searches.max_age)) if history: keyboard = self.cmd.kb(['back', 'quit']) self.send_msg(client, '\n'.join(history), keyboard=keyboard) self.send_msg(client, PHRASES['choose_search_history_number']) else: self.send_msg(client, PHRASES['no_search_history']) self.do_propose_start_search(client)