コード例 #1
0
 def login_screen(self):    
     username = self.view.login_screen_view()
     self.user = PokeDao.fetch_user(username)
     #If user does not exist, show error.. this isn't set up 100% properly. but overlooking because it's not pertinent to the purpose of the assignment
     if type(self.user) == str:
         self.view.login_error_view(self.user)
     #Else go get the pokemon associated with the user
     else:
         self.user.pokemon = PokeDao.fetch_user_pokemon(self.user.id)
         self.poke_portal()
コード例 #2
0
 def delete_pokemon(self):
     #First check if they have any pokemon
     if len(self.user.pokemon) == 0 :
         self.view.user_has_no_pokemon_view()
     else:
         pokemon_to_delete = self.view.delete_pokemon_view(self.user.pokemon)
         #get the user_relation unique link of the particular pokemon to be deleted
         deleting_id = self.user.pokemon[pokemon_to_delete].user_pokemon_relation_id
         #Delete from db
         PokeDao.delete_pokemon(deleting_id)
         #delete from user entity
         self.user.pokemon.remove(self.user.pokemon[pokemon_to_delete])
         self.view.delete_succes_view()
     self.poke_portal()
コード例 #3
0
 def add_pre_existing_pokemon(self, new_pokemon):
     #adding to the relation table
     new_list_of_pokemon = PokeDao.add_existing_pokemon(new_pokemon.pokedex_id, self.user.id)
     #add to user entity
     self.user.pokemon = new_list_of_pokemon
     self.view.add_success_view()
     self.poke_portal()
コード例 #4
0
 def add_undiscovered_pokemon(self,new_pokemon):
     new_pokemon = PokeDao.add_new_pokemon(new_pokemon, self.user.id)
     #string type means the pokemon wasn't found with the api call
     if type(new_pokemon) == str:
         self.view.pokemon_add_del_error_view()
     else:
         self.user.pokemon.append(new_pokemon)
         self.view.add_success_view()
     self.poke_portal()
コード例 #5
0
 def add_pokemon_first_step(self):
     #First get name of pokemon from user
     pokemon_to_add = self.view.add_pokemon_view()
     #Then check if the pokemon has already been documented by another user in the db
     existence = PokeDao.check_existence_of_pokemon_in_sql(pokemon_to_add)
     #If it doesn't exist, fetch from poke api
     if existence == False:
         self.add_undiscovered_pokemon(pokemon_to_add)
     #Else it does exist, go to the sql command instead
     else:
         self.add_pre_existing_pokemon(existence[1])
コード例 #6
0
 def create_user(self):
     new_user = self.view.new_user_view()
     new_user_entity = PokeDao.add_user(new_user)
     self.user = new_user_entity
     self.poke_portal()
コード例 #7
0
 def view_by_habitat(self):
     habitat_of_interest = self.view.habitat_search_view(self.user.pokemon)
     sql_pull = PokeDao.lookup_user_pokemon(habitat_of_interest, self.user.id)
コード例 #8
0
    def view_by_species(self):
        species_of_interest = self.view.species_search_view(self.user.pokemon)
        sql_pull = PokeDao.lookup_user_pokemon(self.user.pokemon[species_of_interest].species_id)
        self.view.search_output(sql_pull)

        self.poke_portal()