def collection_get(self): """ Returns the information needed to generate a sitemap index file. See: http://www.sitemaps.org/protocol.html The response consists of a list of URLs to request the information needed to generate the sitemap linked from the sitemap index. E.g. { "sitemaps": [ "/sitemaps/w/0", "/sitemaps/a/0", "/sitemaps/i/0", "/sitemaps/i/1", "/sitemaps/i/2", "/sitemaps/i/3", "/sitemaps/i/4", "/sitemaps/i/5", ... ] } """ cache_key = _get_cache_key() etag_cache(self.request, cache_key) return get_or_create( cache_sitemap, cache_key, _get_sitemap_index)
def _get_version(self, clazz, document_type, locale_clazz, schema, adapt_schema=None): document_id = self.request.validated['id'] lang = self.request.validated['lang'] version_id = self.request.validated['version_id'] def create_response(): return self._load_version(document_id, lang, version_id, clazz, locale_clazz, schema, adapt_schema) base_cache_key = get_cache_key(document_id, lang, document_type=document_type) if not base_cache_key: raise HTTPNotFound( 'no version for document {0}'.format(document_id)) else: cache_key = '{0}-{1}'.format(base_cache_key, version_id) # set and check the etag: if the etag value provided in the # request equals the current etag, return 'NotModified' etag_cache(self.request, cache_key) return get_or_create(cache_document_version, cache_key, create_response)
def _get(self, clazz, schema, clazz_locale=None, adapt_schema=None, include_maps=False, include_areas=True, set_custom_associations=None, set_custom_fields=None, custom_cache_key=None): id = self.request.validated['id'] lang = self.request.validated.get('lang') editing_view = self.request.GET.get('e', '0') != '0' def create_response(): return self._get_in_lang( id, lang, clazz, schema, editing_view, clazz_locale, adapt_schema, include_maps, include_areas, set_custom_associations, set_custom_fields) if not editing_view: cache_key = get_cache_key(id, lang, custom_cache_key) if cache_key: # set and check the etag: if the etag value provided in the # request equals the current etag, return 'NotModified' etag_cache(self.request, cache_key) return get_or_create( cache_document_detail, cache_key, create_response) # don't cache if requesting a document for editing return create_response()
def collection_get(self): """ Returns the information needed to generate a sitemap index file. See: http://www.sitemaps.org/protocol.html The response consists of a list of URLs to request the information needed to generate the sitemap linked from the sitemap index. E.g. { "sitemaps": [ "/sitemaps/w/0", "/sitemaps/a/0", "/sitemaps/i/0", "/sitemaps/i/1", "/sitemaps/i/2", "/sitemaps/i/3", "/sitemaps/i/4", "/sitemaps/i/5", ... ] } """ cache_key = _get_cache_key() etag_cache(self.request, cache_key) return get_or_create(cache_sitemap, cache_key, _get_sitemap_index)
def collection_get(self): """ Returns a sitemap index file. See: http://www.sitemaps.org/protocol.html The response consists of a list of URLs of sitemaps. <?xml version="1.0" encoding="UTF-8"?> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemap> <loc>https://api.camptocamp.org/sitemaps.xml/w/0.xml</loc> <lastmod>2019-02-11T18:01:49.193770+00:00</lastmod> </sitemap> <sitemap> <loc>https://api.camptocamp.org/sitemaps.xml/a/0.xml</loc> <lastmod>2019-02-11T18:01:49.193770+00:00</lastmod> </sitemap> <sitemap> <loc>https://api.camptocamp.org/sitemaps.xml/i/0.xml</loc> <lastmod>2019-02-11T18:01:49.193770+00:00</lastmod> </sitemap> <sitemap> <loc>https://api.camptocamp.org/sitemaps.xml/i/1.xml</loc> <lastmod>2019-02-11T18:01:49.193770+00:00</lastmod> </sitemap> </sitemap> """ cache_key = _get_cache_key() etag_cache(self.request, cache_key) self.request.response.content_type = "text/xml" return get_or_create(cache_sitemap_xml, cache_key, _get_sitemap_index)
def _get(self, document_config, schema, clazz_locale=None, adapt_schema=None, include_maps=False, include_areas=True, set_custom_associations=None, set_custom_fields=None, custom_cache_key=None): id = self.request.validated['id'] lang = self.request.validated.get('lang') editing_view = self.request.GET.get('e', '0') != '0' cook = self.request.validated.get('cook') if cook and lang: raise HTTPBadRequest( "You can't use cook service with explicit lang query") if cook and editing_view: raise HTTPBadRequest( "You can't use cook service with edition mode") if cook: lang = cook cache = cache_document_cooked if cook else cache_document_detail def create_response(): return self._get_in_lang(id, lang, document_config.clazz, schema, editing_view, clazz_locale, adapt_schema, include_maps, include_areas, set_custom_associations, set_custom_fields, cook_locale=cook) if not editing_view: cache_key = get_cache_key( id, lang, document_type=document_config.document_type, custom_cache_key=custom_cache_key) if cache_key: # set and check the etag: if the etag value provided in the # request equals the current etag, return 'NotModified' etag_cache(self.request, cache_key) return get_or_create(cache, cache_key, create_response) # don't cache if requesting a document for editing return create_response()
def get(self): """ Returns the information needed to generate a sitemap for a given type and sitemap page number. """ doc_type = self.request.validated['doc_type'] i = self.request.validated['i'] cache_key = _get_cache_key(doc_type, i) etag_cache(self.request, cache_key) return get_or_create(cache_sitemap, cache_key, functools.partial(_get_sitemap, doc_type, i))
def get(self): """ Returns the information needed to generate a sitemap for a given type and sitemap page number. """ doc_type = self.request.validated['doc_type'] i = self.request.validated['i'] cache_key = _get_cache_key(doc_type, i) etag_cache(self.request, cache_key) return get_or_create( cache_sitemap, cache_key, functools.partial(_get_sitemap, doc_type, i))
def get(self): """ Returns a sitemap file for a given type and sitemap page number. """ doc_type = self.request.validated['doc_type'] i = self.request.validated['i'] self.request.response.content_type = "text/xml" cache_key = _get_cache_key(doc_type, i) etag_cache(self.request, cache_key) return get_or_create(cache_sitemap_xml, cache_key, functools.partial(_get_sitemap, doc_type, i))
def _get_document_info(self, clazz): document_id = self.request.validated['id'] lang = self.request.validated['lang'] def create_response(): return self._load_document_info(document_id, lang, clazz) cache_key = get_cache_key(document_id, lang) if not cache_key: raise HTTPNotFound( 'no version for document {0}'.format(document_id)) else: etag_cache(self.request, cache_key) return get_or_create( cache_document_info, cache_key, create_response)
def get(self): document_id = self.request.validated['id'] lang = self.request.validated['lang'] def create_response(): return self._get_history(document_id, lang) cache_key = get_cache_key(document_id, lang) if not cache_key: raise HTTPNotFound( 'no version for document {0}'.format(document_id)) else: # set and check the etag: if the etag value provided in the # request equals the current etag, return 'NotModified' etag_cache(self.request, cache_key) return get_or_create( cache_document_history, cache_key, create_response)
def _get_document_info(self, document_config): document_id = self.request.validated['id'] lang = self.request.validated['lang'] def create_response(): return self._load_document_info(document_id, lang, document_config.clazz) cache_key = get_cache_key(document_id, lang, document_type=document_config.document_type) if not cache_key: raise HTTPNotFound( 'no version for document {0}'.format(document_id)) else: etag_cache(self.request, cache_key) return get_or_create(cache_document_info, cache_key, create_response)
def _get_version(self, clazz, locale_clazz, schema, adapt_schema=None): document_id = self.request.validated['id'] lang = self.request.validated['lang'] version_id = self.request.validated['version_id'] def create_response(): return self._load_version( document_id, lang, version_id, clazz, locale_clazz, schema, adapt_schema) base_cache_key = get_cache_key(document_id, lang) if not base_cache_key: raise HTTPNotFound( 'no version for document {0}'.format(document_id)) else: cache_key = '{0}-{1}'.format(base_cache_key, version_id) # set and check the etag: if the etag value provided in the # request equals the current etag, return 'NotModified' etag_cache(self.request, cache_key) return get_or_create( cache_document_version, cache_key, create_response)
def get(self): document_id = self.request.validated['id'] lang = self.request.validated['lang'] def create_response(): return self._get_history(document_id, lang) # history entry point does no precise document type. cache_key = get_cache_key(document_id, lang, document_type=DOCUMENT_TYPE) if not cache_key: raise HTTPNotFound( 'no version for document {0}'.format(document_id)) else: # set and check the etag: if the etag value provided in the # request equals the current etag, return 'NotModified' etag_cache(self.request, cache_key) return get_or_create(cache_document_history, cache_key, create_response)