Beispiel #1
0
class CTXVEventRegistry(CTXPropRegistry):
    """In charge of binding a vevent information to context entities.
    """

    __datatype__ = 'vevent'  #: default datatype name

    def __init__(self, *args, **kwargs):

        super(CTXVEventRegistry, self).__init__(*args, **kwargs)

        self.manager = VEventManager()

    def _get_docs(self, ids, query, *args, **kwargs):

        result = []

        docs = self.manager.values(sources=ids, query=query)

        ctx_id_field = self._ctx_id_field()

        if ids is not None:
            ids = set(ids)

        for doc in docs:
            entity_id = doc[VEventManager.SOURCE]
            if ids is None or entity_id in ids:
                doc[ctx_id_field] = entity_id
                result.append(doc)

        return result

    def _get(self, ids, query, *args, **kwargs):

        return self._get_docs(
            ids=ids, query=query, *args, **kwargs
        )

    def _delete(self, ids, query, *args, **kwargs):

        result = self._get_docs(ids=ids, query=query)

        self.manager.remove_by_source(sources=ids, query=query)

        return result

    def ids(self, query=None):

        return self.manager.whois(query=query)