Skip to content

Commit

Permalink
Add arguments for API query parameters when fetching all Dandisets
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Feb 29, 2024
1 parent c99385d commit b4ccbee
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions dandi/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,63 @@ def get_dandiset(
return d.for_version(version_id)
return d

def get_dandisets(self) -> Iterator[RemoteDandiset]:
def get_dandisets(
self,
*,
draft: bool | None = None,
embargoed: bool | None = None,
empty: bool | None = None,
mine: bool | None = None,
order: str | None = None,
search: str | None = None,
) -> Iterator[RemoteDandiset]:
"""
Returns a generator of all Dandisets on the server. For each Dandiset,
the `RemoteDandiset`'s version is set to the most recent published
version if there is one, otherwise to the draft version.
"""
for data in self.paginate("/dandisets/"):
.. versionchanged:: 0.61.0
``draft``, ``embargoed``, ``empty``, ``mine``, ``order``, and
``search`` parameters added
:param draft:
If true, Dandisets that have only draft versions (i.e., that
haven't yet been published) will be included in the results
(default true)
:param embargoed:
If true, embargoed Dandisets will be included in the results
(default false)
:param empty:
If true, empty Dandisets will be included in the results (default
true)
:param mine:
If true, only Dandisets owned by the authenticated user will be
retrieved (default false)
:param order:
The field to sort the results by. The accepted field names are
``"id"``, ``"name"``, ``"modified"``, and ``"size"``. Prepend a
hyphen to the field name to reverse the sort order.
:param search:
A search string to filter the returned Dandisets by. The string is
searched for in the metadata of Dandiset versions.
"""
for data in self.paginate(

Check warning on line 603 in dandi/dandiapi.py

View check run for this annotation

Codecov / codecov/patch

dandi/dandiapi.py#L603

Added line #L603 was not covered by tests
"/dandisets/",
params={
"draft": draft,
"embargoed": embargoed,
"empty": empty,
"ordering": order,
"search": search,
"user": "me" if mine else None,
},
):
yield RemoteDandiset.from_data(self, data)

def create_dandiset(self, name: str, metadata: dict[str, Any]) -> RemoteDandiset:
Expand Down

0 comments on commit b4ccbee

Please sign in to comment.