sams.factory
– System Application Factory¶
Service¶
-
class
SamsService
(datasource: Optional[str] = None, backend=None)¶ Sams Service
Base service for all endpoints, defines the basic implementation for CRUD functionality. This version differs from Superdesk.services.Service to provide validation on internal usage
-
create
(docs, **kwargs)¶
-
delete
(lookup)¶
-
delete_action
(lookup=None)¶
-
delete_docs
(docs)¶
-
delete_from_mongo
(lookup: Dict[str, Any])¶ Delete items from mongo only
New in version 2.4.0.
Warning
on_delete
andon_deleted
is NOT called with this action- Parameters
lookup (dict) – User mongo query syntax
:raises SuperdeskApiError.forbiddenError if search is enabled for this resource
-
delete_ids_from_mongo
(ids)¶
-
find
(where, **kwargs)¶ Find items in service collection using mongo query.
- Parameters
where (dict) –
-
find_and_modify
(query, update, **kwargs)¶
-
find_one
(req, **lookup)¶
-
get
(req, lookup)¶
-
get_all
()¶
-
get_by_id
(item_id: Union[bson.objectid.ObjectId, str], field='_id')¶ Helper function to retrieve a document by id
- Parameters
item_id (bson.objectid.ObjectId) – ID for the document
field – field to use when searching for the document (defaults to ‘_id’)
- Returns
document found in the system
-
get_from_mongo
(req, lookup, projection=None)¶
Subclass should override if the resource handled by the service has intrinsic privileges.
- Parameters
kwargs – should have properties which help in authorizing the request
- Returns
False
if unauthorized and True if authorized
-
on_create
(docs)¶
-
on_created
(docs)¶
-
on_delete
(doc)¶
-
on_deleted
(doc)¶
-
on_fetched
(doc)¶
-
on_fetched_item
(doc)¶
-
on_replace
(document, original)¶
-
on_replaced
(document, original)¶
-
on_update
(updates, original)¶
-
on_updated
(updates, original)¶
-
patch
(item_id, updates)¶ Update an existing document for the specific resource
- Parameters
item_id (bson.ObjectId) – ID for the document
updates – Dictionary containing the desired attributes to update
- Returns
dictionary containing the updated attributes of the document
-
post
(docs, **kwargs)¶ Create new documents for the specific resource
- Parameters
docs – An array of documents to create
kwargs – dictionary containing the keyword arguments
- Returns
list of generated IDs for the new documents
-
put
(id, document)¶
-
replace
(id, document, original)¶
-
search
(source)¶ Search using search backend.
- Parameters
source – query source param
-
system_update
(id, updates, original, **kwargs)¶
-
update
(id, updates, original)¶
-
validate_patch
(original, updates)¶ Validates the document upon update
The validation performed in this step is provided by Eve/Cerberus using the defined schema for the resource.
- 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
-
validate_post
(doc)¶ Validates the document upon creation
The validation performed in this step is provided by Eve/Cerberus using the defined schema for the resource.
- Parameters
doc – The provided document to validate
- Raises
Superdesk.validation.ValidationError – If there are validation errors
-