_get_entities in base can care about ignore entityTypes so can be removed from event handler

This commit is contained in:
iLLiCiTiT 2020-04-20 18:54:31 +02:00
parent 5894c380cc
commit ea445cede3
2 changed files with 23 additions and 26 deletions

View file

@ -209,20 +209,36 @@ class BaseHandler(object):
return _entities
def _get_entities(self, event, session=None, ignore=None):
entities = []
selection = event['data'].get('selection')
if not selection:
return entities
if ignore is None:
ignore = []
elif isinstance(ignore, str):
ignore = [ignore]
filtered_selection = []
for entity in selection:
if entity['entityType'] not in ignore:
filtered_selection.append(entity)
if not filtered_selection:
return entities
def _get_entities(self, event, session=None):
if session is None:
session = self.session
session._local_cache.clear()
selection = event['data'].get('selection') or []
_entities = []
for entity in selection:
_entities.append(session.get(
for entity in filtered_selection:
entities.append(session.get(
self._get_entity_type(entity, session),
entity.get('entityId')
))
event['data']['entities_object'] = _entities
return _entities
return entities
def _get_entity_type(self, entity, session=None):
'''Return translated entity type tht can be used with API.'''

View file

@ -56,22 +56,3 @@ class BaseEvent(BaseHandler):
event
]
def _get_entities(
self, session, event, ignore=['socialfeed', 'socialnotification']
):
_selection = event['data'].get('entities', [])
_entities = list()
if isinstance(ignore, str):
ignore = list(ignore)
for entity in _selection:
if entity['entityType'] in ignore:
continue
_entities.append(
(
session.get(
self._get_entity_type(entity),
entity.get('entityId')
)
)
)
return _entities