sams.sets
– Internal Service for Sets¶
A set a collection of Assets. It is used as a way to organise and restrict access to the Assets it holds.
All access to the binary or metadata of assets will go through this service. There must be at least one Set configured in the system.
A single Set can be designated as the default Set. When access is requested to an asset without a set being provided, the default set will be used.
Usage¶
The Set service instance can be found under sams.sets.service
and used all:
from sams.sets import get_service
def test_sets():
sets_service = get_service()
sets_service.post([{....}])
sets_service.patch(set_id, {...})
sets_service.delete_action({...})
sets_service.find({...})
This service instance can only be used after the application has bootstrapped.
Resource Schema¶
-
class
SetsResource
(endpoint_name, app, service, endpoint_schema=None)¶ - schema =
_id
bson.objectid.ObjectIdGlobally unique id, generated automatically by the system.
state
string (sams_client.schemas.sets.SET_STATES
)The state of the Set. One of
draft
,usable
, ordisabled
.name
stringUnique name for the Set
description
stringA short description on what this set is designated for
destination_name
stringThe name of a registered StorageDestination (
sams.storage.destinations
)destination_config
dictA dictionary containing the configuration options for the specific destination used
maximum_asset_size
longThe maximum size of an Asset that can be uploaded to this Set (optional)
Service¶
-
class
SetsService
(datasource: Optional[str] = None, backend=None)¶ -
validate_patch
(original, updates)¶ Validates the Set on update
- The following additional validation is performed on Sets being updated:
Once a set has changed from
draft
state, it can never return todraft
- Once a set has changed from
draft
state,destination_name
and destination_config
cannot be changed
- Once a set has changed from
The
destination_name
must exist in aSTORAGE_DESTINATION_
config attribute
- Parameters
original – The original document from the database
updates – A dictionary with the desired attributes to update
- Raises
Superdesk.validation.ValidationError: if there are validation errors
-
on_delete
(doc)¶ Validate state on delete
Sets can only be deleted from the system if they are in the state
SET_STATES.DRAFT
.- Parameters
doc – The Set to delete
- Raises
Superdesk.validation.ValidationError: If the Set is not in
SET_STATES.DRAFT
state
-
get_max_asset_size
(set_id: bson.objectid.ObjectId) → int¶ Returns the maximum allowed size of an Asset for a Set
- Based on the configured settings, this method returns:
Set.maximum_asset_size
ifMAX_ASSET_SIZE == 0
MAX_ASSET_SIZE
ifSet.maximum_asset_size == 0
Otherwise whichever is lowest
- Parameters
set_id (bson.objectid.ObjectId) – The ID of the Set
- Returns
The configured MAX_ASSET_SIZE of Set.maximum_asset_size, whichever is lower
- Return type
-