core.bones.randomslice
¶
Module Contents¶
Classes¶
Simulates the orderby=random from SQL. |
- class core.bones.randomslice.RandomSliceBone(*, visible=False, readOnly=True, slices=2, sliceSize=0.5, **kwargs)¶
Bases:
viur.core.bones.base.BaseBone
Simulates the orderby=random from SQL. If you sort by this bone, the query will return a random set of elements from that query.
- type = randomslice¶
- serialize(skel: SkeletonInstance, name: str, parentIndexed: bool) bool ¶
Serializes this bone into something we can write into the datastore.
This time, we just ignore whatever is set on this bone and write a randomly chosen float [0..1) as value for this bone.
- Parameters
name – The property-name this bone has in its Skeleton (not the description!)
- buildDBSort(name: str, skel: viur.core.skeleton.SkeletonInstance, dbFilter: viur.core.db.Query, rawFilter: Dict) Optional[viur.core.db.Query] ¶
Same as buildDBFilter, but this time its not about filtering the results, but by sorting them. Again: rawFilter is controlled by the client, so you must expect and safely handle malformed data!
This function is somewhat special as it doesn’t just change in which order the selected Elements are being returned - but also changes which Elements are beeing returned (=> a random selection)
- Parameters
name – The property-name this bone has in its Skeleton (not the description!)
skel – The
viur.core.skeleton.Skeleton
instance this bone is part ofdbFilter – The current
viur.core.db.Query
instance the filters should be applied torawFilter – The dictionary of filters the client wants to have applied
- Returns
The modified
viur.core.db.Query
- calculateInternalMultiQueryLimit(query: viur.core.db.Query, targetAmount: int) int ¶
Tells
viur.core.db.Query
How much entries should be fetched in each subquery.- Parameters
targetAmount – How many entries shall be returned from db.Query
- Returns
The amount of elements db.Query should fetch on each subquery
- customMultiQueryMerge(dbFilter: viur.core.db.Query, result: List[viur.core.db.Entity], targetAmount: int) List[viur.core.db.Entity] ¶
Randomly returns ‘targetAmount’ elements from ‘result’
- Parameters
dbFilter – The db.Query calling this function
result – The list of results for each subquery we’ve run
targetAmount – How many results should be returned from db.Query
- Returns
list of elements which should be returned from db.Query