Sorteia
Goal: allow arbitrary sorting instead of attribute-based sorting.
- 1 document per user per resource =
CustomSorting.- Allow multiple users to sort the same documents differently.
- Allow for a large number of items to be sorted.
You can use it as a route dependency to use it on your API or use it directly on your code using the raw methods from the slass Sortings.
class CustomSorting(BaseModel):
id: PyObjectId = Field(alias="_id")
created_at: datetime
updated_at: datetime
created_by: Infostar
position: int
resource_collection: str
resource_id: PyObjectId
Installation:
From repo:
pip install -e ./
From pypi:
pip install sorteia
Class Sortings
Contains the core operations used to sort the elements. Elements always filtered by the infostar user_handle and authprovider_org.
When initializing the class, pass as arguments
collection_name,aliasanddb_name.
reorder_one
Reorders a resource in the custom order by upserting a CustomSorting object. If you send -1 the position will be set as the max_position (as the last document in the collection)
Returns:
ReorderOneUpsertedOut|ReorderOneUpdatedOut
reorder_many
Reorders many resources in the custom order sent as body.
Returns:
BulkWriteResult
read_many
Returns the CustomSorting objects in the positions order.
Returns:
list[CustomSorting]
read_many_whole_object
Returns the CustomSorting object with the whole object as an attribute named resource ($lookup), in the order they were sorted.
Returns:
list[CustomSortingWithResource[T]]
read_many_entire_collection
Returns all of the objects (the ordered and not ordered as well) in the order they were sorted. The objects that have not been ordered yet (don't have a custom-sorting document associated with) will be inserted at the end of the list (sorted by the created_at date, in descending order).
Returns:
CommandCursor[Any]
delete_one
Delete a resource from the custom order using the resource_id as reference.
Returns:
DeleteResult
read_all_ordered_objects
Reads the objects in order - reads the objects that do not have the custom order and the ones who has it. It loads all of the objects into memory (not recommended).
Returns:
list[T]
Example of raw use:
# can initiate Sortings with or without alias and db_name
Sortings(
collection_name=resource, alias=org, db_name=org
).reorder_one(
creator=creator,
resource_id=body.resource_id,
position=position,
background_task=background_task,
)
Sortings(collection_name=resource).delete_one(
resource_id, creator, background_task
)
All of the Sortings class methods work the same way, by initiating a Sortings object and calling any available method.
How to use the route dependencies on an API:
1. Create the indexes that are required to perform search operations later.
from sorteia.operations import Sortings
# create search index
Sortings.create_search_indexes(
mongo_uri=DB.get_client(alias=alias).HOST,
db_name=DB.get(alias=alias).name,
)
2. Initialize the routes dependencies using the method add_sorting_resources_dependency() as seen below.
from sorteia.dependencies import sorting_resources
# include route dependencies
router = APIRouter(prefix="/api")
sorting_resources.add_sorting_resources_dependency(app)
3. Adapt your desired /GET operations to return the custom sorted documents.
from sortings.operations import Sortings
sortings = Sortings(
collection_name="collection_name", alias=org, db_name=org
)
filtering = {
"name": "testing"
}
result = sortings.read_many_entire_collection(
infostar=infostar,
offset=offset,
limit=limit,
projection=projection,
**filtering,
)
Metadata
Release files for sorteia 1.0.0.post13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sorteia-1.0.0.post13.tar.gz | 12.4 kB | Without provenance | Details for sorteia-1.0.0.post13.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sorteia-1.0.0.post13-py3-none-any.whl | Python 3 | none | any | Details for sorteia-1.0.0.post13-py3-none-any.whl |
Total release size: 26.4 kB
Release files / sorteia-1.0.0.post13.tar.gz
| Download URL | sorteia-1.0.0.post13.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b9e18c0a4c8155145bd9c919ec5d69a49929da4612e64ea0b72c2902c13f4d3
|
|
BLAKE2b-256 checksum How to use checksums |
a7d68cda0713215a78155fe28da3d9cd4933e33fbc8630d27b79af9ec4c32bf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / sorteia-1.0.0.post13-py3-none-any.whl
| Download URL | sorteia-1.0.0.post13-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
20084e1995e7330fc488631b646e063a076b3c33388d1fab4c4c08fcf9ad41bf
|
|
BLAKE2b-256 checksum How to use checksums |
7c127d3f9cca8d633980059b4b861f14986ad9ebb269c4b5f859784ccfd61d31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for sorteia 1.0.0.post13
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.