Claim dataset

from LOGS import LOGS
from LOGS.Entities import DatasetOrder, DatasetRequestParameter, ProjectRequestParameter

# Connect to LOGS
logs = LOGS()

# For sake of simplicity in this example we use the newest unclaimed dataset
dataset = logs.datasets(
    DatasetRequestParameter(isClaimed=False, orderBy=DatasetOrder.ACQUISITION_DATE_DESC)

if not dataset:
    raise Exception("There are no unclaimed datasets in this LOGS instance")

# To claim a data you need to set the claimed property
dataset.claimed = True

# The state of a claimed dataset also implyes that a dataset is assigned to
# at least one project and a sample. The dataset also needs to have at least
# one operator.
# For the sake of simplicity in this example we use the first (with lowest logs-id)
# project and sample.
project = logs.projects().first()
if not project:
    raise Exception("There are no projects in this LOGS instance")

sample = logs.samples().first()
if not sample:
    raise Exception("There are no samples in this LOGS instance")

# We only set a project if no project is already assigned to this dataset
if not dataset.projects:
    dataset.projects = [logs.projects(ProjectRequestParameter()).first()]

# We only set a sample if no sample is already assigned to this dataset
if not dataset.sample:
    dataset.sample = sample

# As operator we set the currently active user (this is defined by the API-key used)
dataset.operators = [logs.currentUser]

# The above modifications a still local. We can push them to the logs instance
# using the logs.update method.