diff --git a/arkindex_worker/worker/entity.py b/arkindex_worker/worker/entity.py index d587433c94125eecd0f9634186f613e4e6a00042..057457cffc346e79e204531711054336c50846dc 100644 --- a/arkindex_worker/worker/entity.py +++ b/arkindex_worker/worker/entity.py @@ -174,3 +174,52 @@ class EntityMixin(object): f"Couldn't save created transcription entity in local cache: {e}" ) return transcription_ent + + def list_transcription_entities( + self, + transcription: str, + page: int = None, + page_size: int = None, + worker_version=None, + ): + """ + List transcriptions on entities + This method not work with the cache + + :param transcription str: UUID of the existing transcription. + :param page int: A page number within the paginated result set. + :param page_size int: Number of results to return per page. + :param worker_version str or bool: Restrict to entities created by a worker version with this UUID. Set to False to look for manually created transcriptions. + """ + params = {} + assert transcription and isinstance( + transcription, str + ), "transcription shouldn't be null and should be of type str" + + if page is not None: + assert page and isinstance( + page, int + ), "page shouldn't be null and should be of type integer" + params[page] = page + + if page_size is not None: + assert page_size and isinstance( + page_size, int + ), "page_size shouldn't be null and should be of type integer" + params[page_size] = page_size + + if worker_version is not None: + assert isinstance( + worker_version, (str, bool) + ), "worker_version should be of type str or bool" + + if isinstance(worker_version, bool): + assert ( + worker_version is False + ), "if of type bool, worker_version can only be set to False" + params["worker_version"] = self.worker_version_id + + transcription_ent = self.api_client.paginate( + "ListTranscriptionEntities", id=transcription, **params + ) + return transcription_ent