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 =
_idbson.objectid.ObjectIdGlobally unique id, generated automatically by the system.
statestring (sams_client.schemas.sets.SET_STATES)The state of the Set. One of
draft,usable, ordisabled.namestringUnique name for the Set
descriptionstringA short description on what this set is designated for
destination_namestringThe name of a registered StorageDestination (
sams.storage.destinations)destination_configdictA dictionary containing the configuration options for the specific destination used
maximum_asset_sizelongThe 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
draftstate, it can never return todraft- Once a set has changed from
draftstate,destination_nameand destination_configcannot be changed
- Once a set has changed from
The
destination_namemust 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.DRAFTstate
-
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_sizeifMAX_ASSET_SIZE == 0MAX_ASSET_SIZEifSet.maximum_asset_size == 0Otherwise 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
-