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

Commit

Permalink
count Sources (with the problem that the source field is really a lin…
Browse files Browse the repository at this point in the history
…k to a

source_details object, and the link can be broken at two places), and close again #235.
  • Loading branch information
mfrasca committed Dec 25, 2015
1 parent 2d5f28a commit 4fe13df
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 23 deletions.
11 changes: 8 additions & 3 deletions bauble/plugins/garden/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,15 @@ def retrieve(cls, session, keys):
return None

def top_level_count(self):
sd = self.source and self.source.source_detail
return {(1, 'Accessions'): 1,
(2, 'Plantings'): len(self.plants),
(3, 'Living plants'): sum(p.quantity for p in self.plants),
(4, 'Locations'): set([p.location.id for p in self.plants])}
(2, 'Species'): set([self.species.id]),
(3, 'Genera'): set([self.species.genus.id]),
(4, 'Families'): set([self.species.genus.family.id]),
(5, 'Plantings'): len(self.plants),
(6, 'Living plants'): sum(p.quantity for p in self.plants),
(7, 'Locations'): set([p.location.id for p in self.plants]),
(8, 'Sources'): set(sd and [sd.id] or [])}


from bauble.plugins.garden.plant import Plant, PlantEditor
Expand Down
4 changes: 3 additions & 1 deletion bauble/plugins/garden/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ def top_level_count(self):
(5, 'Species'): set(s.id for s in species),
(6, 'Genera'): set(g.id for g in genera),
(7, 'Families'): set(g.family.id for g in genera),
}
(8, 'Sources'): set([a.source.source_detail.id
for a in accessions
if a.source and a.source.source_detail])}


def mergevalues(value1, value2, formatter):
Expand Down
11 changes: 9 additions & 2 deletions bauble/plugins/garden/plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,16 @@ def retrieve(cls, session, keys):
return None

def top_level_count(self):
sd = self.accession.source and self.accession.source.source_detail
return {(1, 'Plantings'): 1,
(2, 'Living plants'): self.quantity,
(3, 'Locations'): set([self.location.id])}
(2, 'Accessions'): set([self.accession.id]),
(3, 'Species'): set([self.accession.species.id]),
(4, 'Genera'): set([self.accession.species.genus.id]),
(5, 'Families'): set([self.accession.species.genus.family.id]),
(6, 'Living plants'): self.quantity,
(7, 'Locations'): set([self.location.id]),
(8, 'Sources'): set(sd and [sd.id] or []),
}


from bauble.plugins.garden.accession import Accession
Expand Down
2 changes: 1 addition & 1 deletion bauble/plugins/garden/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def source_detail_remove_callback(details):


class Source(db.Base):
"""
"""connected 1-1 to Accession, this class adds fields to Accession
"""
__tablename__ = 'source'
sources_code = Column(Unicode(32))
Expand Down
16 changes: 10 additions & 6 deletions bauble/plugins/plants/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,20 @@ def correct_field_names(cls, keys):
del keys[exchange]

def top_level_count(self):
return {(1, 'Families'): 1} # NOPE - this has to wait
species = [s for g in self.genera for s in g.species]
genera = set(g for g in self.genera if g.species)
species = [s for g in genera for s in g.species]
accessions = [a for s in species for a in s.accessions]
plants = [p for a in accessions for p in a.plants]
return {(1, 'Families'): 1,
(2, 'Genera'): len(self.genera),
(3, 'Species'): len(species),
return {(1, 'Families'): set([self.id]),
(2, 'Genera'): genera,
(3, 'Species'): set(species),
(4, 'Accessions'): len(accessions),
(5, 'Plantings'): len(plants),
(6, 'Living plants'): sum(p.quantity for p in plants)}
(6, 'Living plants'): sum(p.quantity for p in plants),
(7, 'Locations'): set(p.location.id for p in plants),
(8, 'Sources'): set([a.source.source_detail.id
for a in accessions
if a.source and a.source.source_detail])}


## defining the latin alias to the class.
Expand Down
16 changes: 10 additions & 6 deletions bauble/plugins/plants/genus.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,16 @@ def compute_serializable_fields(cls, session, keys):
def top_level_count(self):
accessions = [a for s in self.species for a in s.accessions]
plants = [p for a in accessions for p in a.plants]
return {(1, 'Genera'): 1,
(2, 'Species'): len(self.species),
(3, 'Accessions'): len(accessions),
(4, 'Plantings'): len(plants),
(5, 'Living plants'): sum(p.quantity for p in plants),
(6, 'Locations'): set(p.location.id for p in plants)}
return {(1, 'Genera'): set([self.id]),
(2, 'Families'): set([self.family.id]),
(3, 'Species'): len(self.species),
(4, 'Accessions'): len(accessions),
(5, 'Plantings'): len(plants),
(6, 'Living plants'): sum(p.quantity for p in plants),
(7, 'Locations'): set(p.location.id for p in plants),
(8, 'Sources'): set([a.source.source_detail.id
for a in accessions
if a.source and a.source.source_detail])}


class GenusNote(db.Base):
Expand Down
13 changes: 9 additions & 4 deletions bauble/plugins/plants/species_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,15 @@ def compute_serializable_fields(cls, session, keys):
def top_level_count(self):
plants = [p for a in self.accessions for p in a.plants]
return {(1, 'Species'): 1,
(2, 'Accessions'): len(self.accessions),
(3, 'Plantings'): len(plants),
(4, 'Living plants'): sum(p.quantity for p in plants),
(5, 'Locations'): set(p.location.id for p in plants)}
(2, 'Genera'): set([self.genus.id]),
(3, 'Families'): set([self.genus.family.id]),
(4, 'Accessions'): len(self.accessions),
(5, 'Plantings'): len(plants),
(6, 'Living plants'): sum(p.quantity for p in plants),
(7, 'Locations'): set(p.location.id for p in plants),
(8, 'Sources'): set([a.source.source_detail.id
for a in self.accessions
if a.source and a.source.source_detail])}


class SpeciesNote(db.Base, db.Serializable):
Expand Down

0 comments on commit 4fe13df

Please sign in to comment.