Package: kabaret.flow-entities
kabaret.flow_entitiesAkabaret.flowextension providing searchable large collections of entities, stored in a mongodb.Create your EntitiesEntities are a queryable collection of objects.In order to define an entity, you must inherit
theEntityclass and add somePropertyin it:fromkabaret.flow_entities.entitiesimportEntity,PropertyclassAsset(Entity):asset_type=Property()asset_family=Property()status=Property()You can also add classic relations likeParamandChildand build a whole branch
inside your entity. But keep in mind that theProperyrelations will be the only ones
usable in your queries.Once you have an Entity defined, you must use it in anEntityCollection:fromkabaret.flow_entities.entitiesimportEntityCollection,CreateEntitiesAction,DeleteEntitiesActionclassAssets(EntityCollection):# Those actions are provided for convenience,# you will probably want to define your owns:create_assets=flow.Child(CreateEntitiesAction)delete_assets=flow.Child(DeleteEntitiesAction)@classmethoddefmapped_type(cls):# This tells which entity is show in# this collection:returnAssetWhen using theAssetscollection in your flow, the users will see a
table with "Asset Type", "Asset Family" and "Status" columns.This table is more efficient than akabaret.flow.Mapand can retrieve thousands of items
in a fraction of seconds.Still, theEntityCollectionclass inheritskabaret.flow.DynamicMapso you can use all the classic
customization points (columns(),_fill_row_style(), etc...).Filter your EntitiesTheEntityCollection.query_filter()method can be overidden to return a mongodb filter and
restrict the list of displayed entities. You can for example decide to show only the Assets
with a "WIP" status:classAssets(EntityCollection):create_assets=flow.Child(CreateEntitiesAction)delete_assets=flow.Child(DeleteEntitiesAction)@classmethoddefmapped_type(cls):returnAssetdefquery_filter(self):"""Listing only assets with a WIP status"""return{"status":"WIP"}Now you can add someActionandParamon your collection to control
the returned value ofquery_filter().Note that only thePropertyrelations of your entity can be used
in the filter !The query filter must be a valid argument for a mongodbcollection.find()call. Here is some documentation about it:https://docs.mongodb.com/manual/tutorial/query-documents/Multiple Entity ViewsTheEntityCollection.collection_name()method can be overidden to point
to another entity collection. This is usefull if you want to display some
entities with a different query filter in different place of your flow.Here is an example of showing only unfinished tasks assigned to the
current user from a collection of tasks managed in anadminsection of the
project:classMyTodo(EntityCollection):@classmethoddefmapped_type(cls):# be sure to match the source# collection here:returnAwesomeTaskdefcollection_name(self):returnself.root().project().admin.all_tasks.collection_name()defquery_filter(self):return{"assignee":getpass.getuser(),"status":{"$in":["NYS","WIP"]},}MongoDB ConnectionThe entities are stored as documents in collections of amongodb.In order for yourEntityCollectionto connect to the database, you
must add anEntityStoresomewhere in your project and implement aget_entity_store()method on your project's root.A classic aproach is to use anadmingroup in your project:fromkabaret.flow_entities.storeimportEntityStoreclassAdmin(flow.Object):entity_store=flow.Child(EntityStore)classAwesomePipeline(flow.Object):admin=flow.Child(Admin)defget_entity_store(self):returnself.admin.entity_storeTheEntityStorehas anuriparam that you will need to
set before showing or creating entity. The default value connects to a local mongodb database using the default port and options. Contact your beloved IT support team and ask them the value to use for production.Here is a detailed documentation of the URI syntaxe:https://docs.mongodb.com/manual/reference/connection-string/DemoSeekabaret.flow_entities.demofor more demo code.Create a project with the typekabaret.flow_entities.demo.EntitiesDemoto see it in action.