swimlane.core.adapters.record module¶
- class swimlane.core.adapters.record.RecordAdapter(app)[source]¶
Bases:
AppResolver
Handles retrieval and creation of Swimlane Record resources
- bulk_create(*records)[source]¶
Create and validate multiple records in associated app
- Parameters:
*records (dict) – One or more dicts of new record field names and values
Notes
Requires Swimlane 2.15+
Validates like
create()
, but only sends a single request to create all provided fields, and does not return the newly created recordsAny validation failures on any of the records will abort the batch creation, not creating any new records
Does not return the newly created records
Examples
Create 3 new records with single request
app.records.bulk_create( {'Field 1': 'value 1', ...}, {'Field 1': 'value 2', ...}, {'Field 1': 'value 3', ...} )
- Raises:
swimlane.exceptions.UnknownField – If any field in any new record cannot be found
swimlane.exceptions.ValidationError – If any field in any new record fails validation
TypeError – If no dict of fields was provided, or any provided argument is not a dict
- bulk_delete(*filters_or_records_or_ids)[source]¶
Shortcut to bulk delete records
New in version 2.17.0.
- Parameters:
*filters_or_records_or_ids (tuple) or (Record) – Either a list of Records, a list of filters, a list of recordIds, or a list of both records and recordIds.
Notes
Requires Swimlane 2.17+
Examples
# Bulk delete records by filter app.records.bulk_delete( ('Field_1', 'equals', value1), ('Field_2', 'equals', value2) ) # Bulk delete by record instances record1 = app.records.get(tracking_id='APP-1') record2 = app.records.get(tracking_id='APP-2') record3 = app.records.get(tracking_id='APP-3') app.records.bulk_delete(record1, record2, record3) # Bulk delete by record ids app.records.bulk_delete("adtDzpdDRv9zM8C4o", "aHlAFdBBjE020Jrzb", "aAR67lIcEnLknaURw", values={"Field Name": "New Value"}) # Bulk delete by mixing record instances and record ids record1 = app.records.get(tracking_id='APP-1') app.records.bulk_delete(record1, "aHlAFdBBjE020Jrzb", "aAR67lIcEnLknaURw", values={"Field Name": "New Value"})
- Returns:
Bulk Modify Job ID
- Return type:
string
- bulk_modify(*filters_or_records_or_ids, **kwargs)[source]¶
Shortcut to bulk modify records
New in version 2.17.0.
- Parameters:
*filters_or_records_or_ids (tuple), (Record), or (string) – a list of Records, a list of recordIds, a list of filters, or a list of both records and recordIds.
- Keyword Arguments:
values (dict) – Dictionary of one or more ‘field_name’: ‘new_value’ pairs to update
Notes
Requires Swimlane 2.17+
Examples
# Bulk update records by filter app.records.bulk_modify( # Query filters ('Field_1', 'equals', value1), ('Field_2', 'equals', value2), ... # New values for records values={ "Field_3": value3, "Field_4": value4, ... } ) # Bulk update records record1 = app.records.get(tracking_id='APP-1') record2 = app.records.get(tracking_id='APP-2') record3 = app.records.get(tracking_id='APP-3') app.records.bulk_modify(record1, record2, record3, values={"Field_Name": 'new value'}) # Using recordIds app.records.bulk_modify("adtDzpdDRv9zM8C4o", "aHlAFdBBjE020Jrzb", "aAR67lIcEnLknaURw", values={"Field Name": "New Value"}) # Bulk modify by mixing record instances and record ids record1 = app.records.get(tracking_id='APP-1') app.records.bulk_modify(record1, "aHlAFdBBjE020Jrzb", "aAR67lIcEnLknaURw", values={"Field Name": "New Value"})
- Returns:
Bulk Modify Job ID
- Return type:
string
- create(**fields)[source]¶
Create and return a new record in associated app and return the newly created Record instance
- Parameters:
**fields – Field names and values to be validated and sent to server with create request
Notes
Keyword arguments should be field names with their respective python values
Field values are validated before sending create request to server
Examples
Create a new record on an app with simple field names
record = app.records.create( field_a='Some Value', someOtherField=100, ... )
Create a new record on an app with complex field names
record = app.records.create(**{ 'Field 1': 'Field 1 Value', 'Field 2': 100, ... })
- Returns:
Newly created Record instance with data as returned from API response
- Return type:
- Raises:
swimlane.exceptions.UnknownField – If any fields are provided that are not available on target app
swimlane.exceptions.ValidationError – If any field fails validation before creation
- get(key, value)[source]¶
Get a single record by id
Supports resource cache
Changed in version 2.17.0: Added option to retrieve record by tracking_id
- Keyword Arguments:
- Returns:
Matching Record instance returned from API
- Return type:
- Raises:
TypeError – No id argument provided
ValueError – The lookup value is empty or None
- search(*filters, filter_type='And', **kwargs)[source]¶
Shortcut to generate a new temporary search report using provided filters and return the resulting records
- Parameters:
*filters (tuple) – Zero or more filter tuples of (field_name, operator, field_value)
- Keyword Arguments:
keywords (list(str)) – List of strings of keywords to use in report search
limit (int) – Set maximum number of returned Records, defaults to Report.default_limit. Set to 0 to return all records
page_size – Set maximum number of returned Records per page, defaults to 1000. Set to 0 to return all records
sort – Tuple of (field_name, order) by which results will be sorted
columns (list(str)) – List of strings of field names to populate in the resulting records. Defaults to all available fields
Notes
Uses a temporary Report instance with a random name to facilitate search. Records are normally paginated, but are returned as a single list here, potentially causing performance issues with large searches.
All provided filters are AND’ed together
Filter operators and sort orders are available as constants in swimlane.core.search
Examples
# Return records matching all filters with default limit and page size from swimlane.core import search records = app.records.search( ('field_name', 'equals', 'field_value'), ('other_field', search.NOT_EQ, 'value') )
# Run keyword search with multiple keywords records = app.records.search(keywords=['example', 'test'])
# Return all records from app records = app.records.search(limit=0)
# Populate only the specified field and sort results records = app.records.search(columns=['field_name'], sort=('field_name', 'ascending'))