def publish_version(dandiset_id: int) -> None: with GirderClient(authenticate=True) as client: dandiset = Dandiset.objects.get(pk=dandiset_id) with client.dandiset_lock(dandiset.identifier): version = Version.from_girder(dandiset, client) for girder_file in client.files_in_folder( dandiset.draft_folder_id): Asset.from_girder(version, girder_file, client)
def publish_version(dandiset_id: int, user_id) -> None: dandiset = Dandiset.objects.get(pk=dandiset_id) try: with GirderClient(authenticate=True) as client: with client.dandiset_lock(dandiset.identifier): version = Version.from_girder(dandiset, client) for girder_file in client.files_in_folder(dandiset.draft_folder_id): Asset.from_girder(version, girder_file, client) finally: # The draft was locked in django by the publish action # We need to unlock it now dandiset.draft_version.unlock(User.objects.get(id=user_id))
def paths(self, request, **kwargs): """ Return the unique files/directories that directly reside under the specified path. The specified path must be a folder (must end with a slash). """ path_prefix: str = self.request.query_params.get('path_prefix') or '/' # Enforce trailing slash path_prefix = f'{path_prefix}/' if path_prefix[-1] != '/' else path_prefix qs = self.get_queryset().filter(path__startswith=path_prefix).values() return Response(Asset.get_path(path_prefix, qs))
def stats_view(self): dandiset_count = Dandiset.objects.count() published_dandiset_count = Dandiset.published_count() user_count = User.objects.count() size = Asset.total_size() return Response( { 'dandiset_count': dandiset_count, 'published_dandiset_count': published_dandiset_count, 'user_count': user_count, 'size': size, } )
def test_asset_get_path(path, qs, expected): assert expected == Asset.get_path(path, qs)
def test_asset_from_girder(version, girder_file, mock_girder_client): asset = Asset.from_girder(version, girder_file, mock_girder_client) assert asset