Esempio n. 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)
Esempio n. 2
0
    def __init__(self, *args, **kwargs):

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

        self.manager = VEventManager()
Esempio n. 3
0
# (at your option) any later version.
#
# Canopsis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Canopsis.  If not, see <http://www.gnu.org/licenses/>.
# ---------------------------------

from canopsis.common.ws import route
from canopsis.vevent.manager import VEventManager
from canopsis.common.middleware import Middleware

vem = VEventManager(
    storage=Middleware.get_middleware_by_uri(VEventManager.VEVENT_COLL_URL))

DEFAULT_ROUTE = 'vevent'  #: route specifics to vevents document


def exports(ws):
    @route(ws.application.get, name=DEFAULT_ROUTE)
    def get_by_uids(ids,
                    limit=0,
                    skip=0,
                    sort=None,
                    projection=None,
                    with_count=False):
        """Get documents by uids.

        :param list ids: list of document ids.