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)
Beispiel #2
0
 def on_country_name_choose(self, country_id: str, client: VKinderClient):
     result = None
     try:
         country_id = int(country_id)
         if 0 < country_id <= len(client.found_countries):
             result = country_id
     except ValueError:
         pass
     if result:
         client.country_id = client.found_countries[result - 1].id
         client.country_name = client.found_countries[result - 1].title
         self.db.save_client(client, force_country_update=True)
         self.send_msg(
             client,
             PHRASES['you_chosen_country_x'].format(client.country_name))
         self.do_start_search_creating(client)
     else:
         self.send_msg(client, PHRASES['no_such_country_in_list'])