Skip to content

Commit

Permalink
Add conservation status, establishment means, and wikipedia descripti…
Browse files Browse the repository at this point in the history
…on + url to DbTaxon model
  • Loading branch information
JWCook committed Jul 3, 2024
1 parent 7b1a911 commit 8a9350a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pyinaturalist_convert/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,22 @@ class DbTaxon:
id: int = sa_field(Integer, primary_key=True)
ancestor_ids: str = sa_field(String, default=None)
child_ids: str = sa_field(String, default=None)
conservation_status: str = sa_field(String, default=None)
establishment_means: str = sa_field(String, default=None)
iconic_taxon_id: int = sa_field(Integer, default=0)
is_active: bool = sa_field(Boolean, default=None)
leaf_taxa_count: int = sa_field(Integer, default=0)
observations_count: int = sa_field(Integer, default=0)
observations_count_rg: int = sa_field(Integer, default=0)
name: str = sa_field(String, default=None, index=True)
parent_id: int = sa_field(ForeignKey('taxon.id'), default=None, index=True)
partial: int = sa_field(Boolean, default=False)
partial: bool = sa_field(Boolean, default=False)
photo_urls: str = sa_field(String, default=None)
preferred_common_name: str = sa_field(String, default=None)
rank: str = sa_field(String, default=None)
reference_url: str = sa_field(String, default=None)
wikipedia_summary: str = sa_field(String, default=None)
wikipedia_url: str = sa_field(String, default=None)

@classmethod
def from_model(cls, taxon: Taxon) -> 'DbTaxon':
Expand All @@ -195,6 +199,8 @@ def from_model(cls, taxon: Taxon) -> 'DbTaxon':
id=taxon.id,
ancestor_ids=_join_list(taxon.ancestor_ids),
child_ids=_join_list(taxon.child_ids),
conservation_status=taxon.conservation_status,
establishment_means=taxon.establishment_means,
iconic_taxon_id=taxon.iconic_taxon_id,
is_active=taxon.is_active,
leaf_taxa_count=taxon.complete_species_count,
Expand All @@ -206,6 +212,8 @@ def from_model(cls, taxon: Taxon) -> 'DbTaxon':
rank=taxon.rank,
reference_url=taxon.reference_url,
photo_urls=photo_urls,
wikipedia_summary=taxon.wikipedia_summary,
wikipedia_url=taxon.wikipedia_url,
)

def to_model(self) -> Taxon:
Expand All @@ -214,6 +222,8 @@ def to_model(self) -> Taxon:
id=self.id,
ancestors=_get_taxa(self.ancestor_ids),
children=_get_taxa(self.child_ids),
conservation_status=self.conservation_status,
establishment_means=self.establishment_means,
default_photo=photos[0] if photos else None,
iconic_taxon_id=self.iconic_taxon_id,
is_active=self.is_active,
Expand All @@ -226,6 +236,8 @@ def to_model(self) -> Taxon:
rank=self.rank,
reference_url=self.reference_url,
taxon_photos=photos,
wikipedia_summary=self.wikipedia_summary,
wikipedia_url=self.wikipedia_url,
)

def update(self, taxon: Taxon):
Expand Down

0 comments on commit 8a9350a

Please sign in to comment.