Пример #1
0
    def on_fetched_item(self, document):
        """Event handler when a single item is retrieved from database.

        It sets the item's `uri` field and removes all the fields added by the
        `Eve` framework that are not part of the NINJS standard (except for
        the HATEOAS `_links` object).

        :param dict document: fetched MongoDB document representing the item
        """
        document['uri'] = self._get_uri(document)

        for field_name in ('_id', '_etag', '_created', '_updated'):
            document.pop(field_name, None)
        if 'renditions' in document:
            for k, v in document['renditions'].items():
                if 'media' in v:
                    v['href'] = url_for_media(v['media'])
Пример #2
0
    def _process_fetched_object(self, document):
        """Does some processing on the raw document fetched from database.

        It sets the item's `uri` field and removes all the fields added by the
        `Eve` framework that are not part of the NINJS standard (except for
        the HATEOAS `_links` object).
        It also sets the URLs for all externally referenced media content.

        :param dict document: MongoDB document to process
        """
        document['uri'] = self._get_uri(document)

        for field_name in ('_id', '_etag', '_created', '_updated'):
            document.pop(field_name, None)

        if 'renditions' in document:
            for k, v in document['renditions'].items():
                if 'media' in v:
                    v['href'] = url_for_media(v['media'])