From 9e3cd0125645752ffaa387d38c5b27539fea5629 Mon Sep 17 00:00:00 2001 From: Jordan Cook Date: Mon, 11 Dec 2023 18:53:22 -0600 Subject: [PATCH] Some changes for Project model needed for project search results --- HISTORY.md | 16 ++++++++++------ pyinaturalist/models/project.py | 10 ++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 564eba7f..55d59ecb 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -16,12 +16,6 @@ Add support for searching observations by observation fields, using a new `obser * `get_observation_species_counts()` ### Models -**Taxon:** -* Add `make_tree()` function to build a tree from `Taxon` objects or a `LifeList` -* Add `pprint_tree()` function to print a taxon tree on the console -* Add `Taxon.flatten()` method to return a taxon and its descendants as a flat list -* Fix initialization of `ListedTaxon.place` - **Observation:** * Add `Observation.ident_taxon_ids` dynamic property to get all identification taxon IDs (with ancestors) * Add `Observation.cumulative_ids` dynamic property to calculate agreements/total community identifications @@ -32,6 +26,16 @@ Add support for searching observations by observation fields, using a new `obser * Add `Sound` model for `Observation.sounds` * Add `Vote` model for `Observation.votes` +**Project:** +* Add `Project.last_post_at` datetime attribute +* Add `Project.observation_requirements_updated_at` datetime attribute + +**Taxon:** +* Add `make_tree()` function to build a tree from `Taxon` objects or a `LifeList` +* Add `pprint_tree()` function to print a taxon tree on the console +* Add `Taxon.flatten()` method to return a taxon and its descendants as a flat list +* Fix initialization of `ListedTaxon.place` + ### Other changes * Added support for python 3.12 diff --git a/pyinaturalist/models/project.py b/pyinaturalist/models/project.py index dda75a23..c2fcba10 100644 --- a/pyinaturalist/models/project.py +++ b/pyinaturalist/models/project.py @@ -1,5 +1,5 @@ from datetime import datetime -from typing import Dict, List +from typing import Dict, List, Optional from pyinaturalist.constants import ( INAT_BASE_URL, @@ -72,7 +72,7 @@ class ProjectUser(User): @classmethod def from_json(cls, value: JsonResponse, **kwargs) -> 'ProjectUser': """Flatten out nested values""" - user = value['user'] + user = value.get('user', {}) user['project_id'] = value['project_id'] user['project_user_id'] = value['id'] user['role'] = value['role'] @@ -99,7 +99,13 @@ class Project(BaseModel): default=None, doc='Indicates if this is an umbrella project (containing observations from other projects)', ) + last_post_at: Optional[datetime] = datetime_field( + doc='Date and time of the last project journal post' + ) location: Coordinates = coordinate_pair() + observation_requirements_updated_at: Optional[datetime] = datetime_field( + doc='Date and time of last update for observation requirements' + ) place_id: int = field(default=None, doc='Project place ID') prefers_user_trust: bool = field( default=None,