Ejemplo n.º 1
0
 def find_by_id(self, type_id):
     session = Session()
     try:
         habitat_type = session.query(HabitatType).filter(
             HabitatType.type_id == type_id).one()
     except:
         habitat_type = None
     finally:
         session.close()
     return habitat_type
Ejemplo n.º 2
0
 def get_species(self):
     session = Session()
     try:
         species = session.query(DbSpecies).filter(
             DbSpecies.species_id == self.species_id).one()
     except:
         species = None
     finally:
         session.close()
     return species
Ejemplo n.º 3
0
 def find(self, species_name):
     session = Session()
     try:
         species = session.query(DbSpecies).filter(
             DbSpecies.name == species_name).one()
     except:
         species = None
     finally:
         session.close()
     return species
Ejemplo n.º 4
0
Archivo: n2k.py Proyecto: leaffan/geo
 def find_by_id(self, type_id):
     session = Session()
     try:
         habitat_type = session.query(HabitatType).filter(
             HabitatType.type_id == type_id
             ).one()
     except:
         habitat_type = None
     finally:
         session.close()
     return habitat_type
Ejemplo n.º 5
0
 def get_species(self):
     session = Session()
     try:
         species = session.query(DbSpecies).filter(
             DbSpecies.species_id == self.species_id
             ).one()
     except:
         species = None
     finally:
         session.close()
     return species
Ejemplo n.º 6
0
 def find(self, species_name):
     session = Session()
     try:
         species = session.query(DbSpecies).filter(
             DbSpecies.name == species_name
             ).one()
     except:
         species = None
     finally:
         session.close()
     return species
Ejemplo n.º 7
0
 def get_associated_habitat_types(self):
     session = Session()
     try:
         species_habitat_links = session.query(HabitatTypesSpecies).filter(
             HabitatTypesSpecies.species_id == self.species_id).all()
         type_ids = [lnk.type_id for lnk in species_habitat_links]
         habitat_types = session.query(HabitatType).filter(
             HabitatType.type_id.in_(type_ids)).all()
     except:
         habitat_types = None
     finally:
         session.close()
     return habitat_types
Ejemplo n.º 8
0
 def get_typical_species(self):
     session = Session()
     try:
         habitat_species_links = session.query(HabitatTypesSpecies).filter(
             HabitatTypesSpecies.type_id == self.type_id).all()
         species_ids = [lnk.species_id for lnk in habitat_species_links]
         species = session.query(Species).filter(
             Species.species_id.in_(species_ids)).all()
     except:
         species = None
     finally:
         session.close()
     return species
Ejemplo n.º 9
0
Archivo: n2k.py Proyecto: leaffan/geo
 def get_associated_habitat_types(self):
     session = Session()
     try:
         species_habitat_links = session.query(HabitatTypesSpecies).filter(
             HabitatTypesSpecies.species_id == self.species_id
         ).all()
         type_ids = [lnk.type_id for lnk in species_habitat_links]
         habitat_types = session.query(HabitatType).filter(
             HabitatType.type_id.in_(type_ids)
             ).all()
     except:
         habitat_types = None
     finally:
         session.close()
     return habitat_types
Ejemplo n.º 10
0
Archivo: n2k.py Proyecto: leaffan/geo
 def get_typical_species(self):
     session = Session()
     try:
         habitat_species_links = session.query(HabitatTypesSpecies).filter(
             HabitatTypesSpecies.type_id == self.type_id
         ).all()
         species_ids = [lnk.species_id for lnk in habitat_species_links]
         species = session.query(Species).filter(
             Species.species_id.in_(species_ids)
             ).all()
     except:
         species = None
     finally:
         session.close()
     return species
Ejemplo n.º 11
0
 def find_by_name(self, name):
     session = Session()
     try:
         species = session.query(Species).filter(Species.name == name).one()
     except:
         # finding species
         spf = SpeciesFinder(name)
         sp_name, sp_url, sp_info = spf.find_species()
         # creating new species
         species = Species(sp_name, sp_url, sp_info)
         # adding species to database
         session.merge(species)
         session.commit()
     finally:
         session.close()
     return species
Ejemplo n.º 12
0
Archivo: n2k.py Proyecto: leaffan/geo
 def find_by_name(self, name):
     session = Session()
     try:
         species = session.query(Species).filter(
             Species.name == name
             ).one()
     except:
         # finding species
         spf = SpeciesFinder(name)
         sp_name, sp_url, sp_info = spf.find_species()
         # creating new species
         species = Species(sp_name, sp_url, sp_info)
         # adding species to database
         session.merge(species)
         session.commit()
     finally:
         session.close()
     return species