Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
do not initiate session if not necessary. relates to #264 and #253.
Browse files Browse the repository at this point in the history
but I want this static class method to go and I should write an instance method in the place.
  • Loading branch information
mfrasca committed Jan 8, 2016
1 parent 0ce2351 commit fc9bd75
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions bauble/plugins/garden/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,28 +724,29 @@ def species_str(self, authors=False, markup=False):
logger.warning(msg)
self.__warned_about_id_qual = True

# copy the species so we don't affect the original
session = db.Session()
species = session.merge(self.species) # , dont_load=True)

# generate the string
if self.id_qual in ('aff.', 'cf.'):
if self.id_qual_rank == 'infrasp':
species.sp = '%s %s' % (species.sp, self.id_qual)
elif self.id_qual_rank:
setattr(species, self.id_qual_rank,
'%s %s' % (self.id_qual,
getattr(species, self.id_qual_rank)))
sp_str = Species.str(species, authors, markup)
elif self.id_qual:
sp_str = '%s(%s)' % (Species.str(species, authors, markup),
self.id_qual)
if self.id_qual:
# copy the species so we don't affect the original
session = db.Session()
species = session.merge(self.species) # , dont_load=True)

# generate the string
if self.id_qual in ('aff.', 'cf.'):
if self.id_qual_rank == 'infrasp':
species.sp = '%s %s' % (species.sp, self.id_qual)
elif self.id_qual_rank:
setattr(species, self.id_qual_rank,
'%s %s' % (self.id_qual,
getattr(species, self.id_qual_rank)))
sp_str = Species.str(species, authors, markup)
elif self.id_qual:
sp_str = '%s(%s)' % (Species.str(species, authors, markup),
self.id_qual)
# clean up and return the string
del species
session.close()
else:
sp_str = Species.str(species, authors, markup)
sp_str = Species.str(self.species, authors, markup)

# clean up and return the string
del species
session.close()
self.__cached_species_str[(markup, authors)] = sp_str
return sp_str

Expand Down

0 comments on commit fc9bd75

Please sign in to comment.