Exemple #1
0
        def load_data(old_api_cache_key=None):
            if old_api_cache_key:
                (old_api_cache_key1, old_api_cache_key2) = old_api_cache_key
            else:
                old_api_cache_key1 = None
                old_api_cache_key2 = None

            url1 = '%s/%d/%s/%d' % (self._API_ROUTE, id, lang, v1)
            not_modified1, api_cache_key1, content1 = get_with_etag(
                self.settings, url1, old_api_cache_key1)

            url2 = '%s/%d/%s/%d' % (self._API_ROUTE, id, lang, v2)
            not_modified2, api_cache_key2, content2 = get_with_etag(
                self.settings, url2, old_api_cache_key2)

            if not_modified1 and not_modified2:
                return True, (api_cache_key1, api_cache_key2), None

            # if only one of the versions has changed, and the other not,
            # a 2nd request has to be made to get the content for that
            # version again, so that the page can be rendered
            if not_modified1 and not content1:
                _, api_cache_key1, content1 = get_with_etag(
                    url1, old_api_cache_key=None)
            if not_modified2 and not content2:
                _, api_cache_key2, content2 = get_with_etag(
                    self.settings, url2, old_api_cache_key=None)

            return False, (api_cache_key1, api_cache_key2), (content1, content2)  # noqa
Exemple #2
0
        def load_data(old_api_cache_key=None):
            if old_api_cache_key:
                (old_api_cache_key1, old_api_cache_key2) = old_api_cache_key
            else:
                old_api_cache_key1 = None
                old_api_cache_key2 = None

            url1 = '%s/%d/%s/%d' % (self._API_ROUTE, id, lang, v1)
            not_modified1, api_cache_key1, content1 = get_with_etag(
                self.settings, url1, old_api_cache_key1)

            url2 = '%s/%d/%s/%d' % (self._API_ROUTE, id, lang, v2)
            not_modified2, api_cache_key2, content2 = get_with_etag(
                self.settings, url2, old_api_cache_key2)

            if not_modified1 and not_modified2:
                return True, (api_cache_key1, api_cache_key2), None

            # if only one of the versions has changed, and the other not,
            # a 2nd request has to be made to get the content for that
            # version again, so that the page can be rendered
            if not_modified1 and not content1:
                _, api_cache_key1, content1 = get_with_etag(
                    self.settings, url1, old_api_cache_key=None)
            if not_modified2 and not content2:
                _, api_cache_key2, content2 = get_with_etag(
                    self.settings, url2, old_api_cache_key=None)

            return False, (api_cache_key1, api_cache_key2), (content1, content2
                                                             )  # noqa
Exemple #3
0
    def _get_document(self, id, lang=None, old_api_cache_key=None):
        url = '%s/%d' % (self._API_ROUTE, id)
        if lang:
            url += '?l=%s' % lang
        not_modified, api_cache_key, document = get_with_etag(
            self.settings, url, old_api_cache_key)

        if not_modified:
            return not_modified, api_cache_key, None

        # Manage merged documents (redirecting to another document)
        if 'redirects_to' in document:
            is_lang_set = lang is not None and \
                          lang in document['available_langs']
            if not is_lang_set:
                lang = self._get_best_lang(document['available_langs'])
            self._redirect(document['redirects_to'], lang, None, is_lang_set)

        # When requesting a lang that does not exist yet, the API sends
        # back an empty list as 'locales'
        if not document['locales']:
            raise HTTPNotFound('Requested lang does not exist')

        # We need to pass locale data to Mako as a dedicated object to make it
        # available to the parent templates:
        locale = document['locales'][0]

        return False, api_cache_key, (document, locale)
Exemple #4
0
    def _get_document(self, id, lang=None, old_api_cache_key=None):
        url = '%s/%d' % (self._API_ROUTE, id)
        if lang:
            url += '?l=%s' % lang
        not_modified, api_cache_key, document = get_with_etag(
            self.settings, url, old_api_cache_key)

        if not_modified:
            return not_modified, api_cache_key, None

        # Manage merged documents (redirecting to another document)
        if 'redirects_to' in document:
            is_lang_set = lang is not None and \
                          lang in document['available_langs']
            if not is_lang_set:
                lang = self._get_best_lang(document['available_langs'])
            self._redirect(document['redirects_to'], lang, None, is_lang_set)

        # When requesting a lang that does not exist yet, the API sends
        # back an empty list as 'locales'
        if not document['locales']:
            raise HTTPNotFound('Requested lang does not exist')

        # We need to pass locale data to Mako as a dedicated object to make it
        # available to the parent templates:
        locale = document['locales'][0]

        return False, api_cache_key, (document, locale)
Exemple #5
0
    def _get_profile_info(self, id, lang, old_api_cache_key=None):
        url = '%s/%d/%s/info' % (self._API_ROUTE, id, lang)
        not_modified, api_cache_key, document = get_with_etag(
            self.settings, url, old_api_cache_key)

        if not_modified:
            return not_modified, api_cache_key, None

        return False, api_cache_key, (document, document['locales'])
Exemple #6
0
        def load_data(old_api_cache_key=None):
            url = 'document/%d/history/%s' % (id, lang)
            not_modified, api_cache_key, content = get_with_etag(
                self.settings, url, old_api_cache_key)

            if not_modified:
                return not_modified, api_cache_key, None

            return False, api_cache_key, (content, )
Exemple #7
0
        def load_data(old_api_cache_key=None):
            url = 'document/%d/history/%s' % (id, lang)
            not_modified, api_cache_key, content = get_with_etag(
                self.settings, url, old_api_cache_key)

            if not_modified:
                return not_modified, api_cache_key, None

            return False, api_cache_key, (content, )
Exemple #8
0
    def _get_profile_info(self, id, lang, old_api_cache_key=None):
        url = '%s/%d/%s/info' % (self._API_ROUTE, id, lang)
        not_modified, api_cache_key, document = get_with_etag(
            self.settings, url, old_api_cache_key)

        if not_modified:
            return not_modified, api_cache_key, None

        return False, api_cache_key, (document, document['locales'])
Exemple #9
0
    def _get_archived_document(
            self, id, lang, version_id, old_api_cache_key=None):
        url = '%s/%d/%s/%d' % (self._API_ROUTE, id, lang, version_id)
        not_modified, api_cache_key, content = get_with_etag(
            self.settings, url, old_api_cache_key)

        if not_modified:
            return not_modified, api_cache_key, None

        document = content['document']
        version = content['version']
        locale = document['locales'][0]

        return False, api_cache_key, (document, locale, version)
Exemple #10
0
    def _get_archived_document(self,
                               id,
                               lang,
                               version_id,
                               old_api_cache_key=None):
        url = '%s/%d/%s/%d' % (self._API_ROUTE, id, lang, version_id)
        not_modified, api_cache_key, content = get_with_etag(
            self.settings, url, old_api_cache_key)

        if not_modified:
            return not_modified, api_cache_key, None

        document = content['document']
        version = content['version']
        locale = document['locales'][0]

        return False, api_cache_key, (document, locale, version)
Exemple #11
0
 def load_data(old_api_cache_key=None):
     url = '{}/{}/{}'.format(Sitemap._API_ROUTE, doc_type, i)
     not_modified, api_cache_key, body = get_with_etag(
         self.settings, url, old_api_cache_key)
     return not_modified, api_cache_key, (body, )
Exemple #12
0
 def load_data(old_api_cache_key=None):
     not_modified, api_cache_key, body = get_with_etag(
         self.settings, Sitemap._API_ROUTE, old_api_cache_key)
     return not_modified, api_cache_key, (body, )
Exemple #13
0
 def load_data(old_api_cache_key=None):
     url = '{}/{}/{}'.format(Sitemap._API_ROUTE, doc_type, i)
     not_modified, api_cache_key, body = get_with_etag(
         self.settings, url, old_api_cache_key)
     return not_modified, api_cache_key, (body, )
Exemple #14
0
 def load_data(old_api_cache_key=None):
     not_modified, api_cache_key, body = get_with_etag(
         self.settings, Sitemap._API_ROUTE, old_api_cache_key)
     return not_modified, api_cache_key, (body, )