Skip to content

Commit

Permalink
Merge pull request #306 from zooniverse/UPP-fetch_settings
Browse files Browse the repository at this point in the history
implement fetch_settings to project_preferences class
  • Loading branch information
Tooyosi committed Mar 3, 2024
2 parents d9700c2 + 063998f commit d23d2b7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
32 changes: 28 additions & 4 deletions docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,8 @@ Add subject set to first workflow in project::
workflow = project.links.workflows[0]
workflow.links.subject_sets.add(subject_set)

Project owners with client credentials can update their users' project settings
(workflow_id only)::

Panoptes.connect(client_id="example", client_secret="example")
Project owners and collaborators can update their users' project settings
(workflow_id only; for use with leveling up feature)::

user = User.find("1234")
project = Project.find("1234")
Expand All @@ -307,6 +305,32 @@ already known::
settings=new_settings,
)

Project owner/collaborator can also fetch all project settings for a project::

project = Project.find("1234")

ProjectPreferences.fetch_settings(
project=project
)

Or the project settings for a particular user::

project = Project.find("1234")
user = User.find("1234")

ProjectPreferences.fetch_settings(
project=project,
user=user
)

Project settings can also be fetched with the project ID and user ID
directly if already known::

ProjectPreferences.fetch_settings(
project=project_id,
user=user_id
)

Importing iNaturalist observations to Panoptes as subjects is possible via an
API endpoint. Project owners and collaborators can use this client to send
a request to begin that import process::
Expand Down
44 changes: 44 additions & 0 deletions panoptes_client/project_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,48 @@ def save_settings(cls, project=None, user=None, settings=None):
else:
raise TypeError

@classmethod
def fetch_settings(cls, project=None, user=None):
"""
Fetch project preference settings for a particular project and user(optional).
- **user** and **project** can be either a :py:class:`.User` and
:py:class:`.Project` instance respectively, or they can be given as
IDs.
- **user** parameter is optional and only **project** is required
Examples::
ProjectPreferences.fetch_settings(Project(1234), User(1234))
ProjectPreferences.fetch_settings(1234, 1234)
ProjectPreferences.fetch_settings(Project(1234))
ProjectPreferences.fetch_settings(1234)
"""

_user_id = None
_project_id = None

if isinstance(project, Project):
_project_id = project.id
elif isinstance(project, (int, str,)):
_project_id = project
else:
raise TypeError

if isinstance(user, User):
_user_id = user.id
elif isinstance(user, (int, str,)):
_user_id = user

params = {'project_id': _project_id}

if _user_id is not None:
params['user_id'] = _user_id

return cls.http_get(
'read_settings',
params=params
)[0]


LinkResolver.register(ProjectPreferences)

0 comments on commit d23d2b7

Please sign in to comment.