Python django.views.decorators.cache.cache_control() Examples
The following are 10
code examples of django.views.decorators.cache.cache_control().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.views.decorators.cache
, or try the search function
.
Example #1
Source File: views.py From open-context-py with GNU General Public License v3.0 | 6 votes |
def lightbox_view(request, spatial_context=''): """ redirects requests from the legacy site 'lightbox' to the media-search view We can add URL parameter mappings to this later so that old url parameters can be mapped to the current parameters """ request = RequestNegotiation().anonymize_request(request) url = request.get_full_path() new_url = url.replace('/lightbox/', '/media-search/') param_suffix = '' if '?' in url: url_ex = url.split('?') param_suffix = '?' + url_ex[1] return redirect(new_url, permanent=True) # @cache_control(no_cache=True) # @never_cache # @vary_on_headers('Accept', 'accept', 'content-type')
Example #2
Source File: views.py From open-context-py with GNU General Public License v3.0 | 6 votes |
def index_view(request): """ Get the search context JSON-LD """ rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support template = loader.get_template('vocabularies/index.html') context = { 'base_url': base_url, 'page_title': 'Open Context: Vocabularies + Ontologies', 'act_nav': 'vocabularies', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415) # @cache_control(no_cache=True) # @never_cache
Example #3
Source File: views.py From django-healthchecks with MIT License | 5 votes |
def as_view(cls, **kwargs): view = super(NoCacheMixin, cls).as_view(**kwargs) return cache_control( private=True, no_cache=True, no_store=True, max_age=0)(view)
Example #4
Source File: decorators.py From normandy with Mozilla Public License 2.0 | 5 votes |
def api_cache_control(**kwargs): """ Adds cache headers to a view using our API cache header defaults. """ if settings.API_CACHE_ENABLED: directives = {"public": True, "max_age": settings.API_CACHE_TIME} else: directives = {"no_cache": True, "no_store": True, "must_revalidate": True} directives.update(kwargs) return cache_control(**directives)
Example #5
Source File: views.py From open-context-py with GNU General Public License v3.0 | 5 votes |
def pub_view(request): """ Get publishing overview page """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/publishing', 'site_name': settings.CANONICAL_SITENAME, 'description': 'How to publish archaeological research data '\ 'with Open Context', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('about/publishing.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - Publishing', 'act_nav': 'about', 'og': open_graph, 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415) # @cache_control(no_cache=True) # @never_cache
Example #6
Source File: views.py From open-context-py with GNU General Public License v3.0 | 5 votes |
def sponsors_view(request): """ Get the page about sponsors """ request = RequestNegotiation().anonymize_request(request) rp = RootPath() base_url = rp.get_baseurl() req_neg = RequestNegotiation('text/html') if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: # requester wanted a mimetype we DO support open_graph = { 'twitter_site': settings.TWITTER_SITE, 'type': 'website', 'url': base_url + '/about/sponsors', 'site_name': settings.CANONICAL_SITENAME, 'description': 'Sources of financial support for '\ 'Open Context and collaborative institutions providing '\ 'complementary services', 'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png', 'video': False } template = loader.get_template('about/sponsors.html') context = { 'base_url': base_url, 'page_title': 'Open Context: About - Intellectual Property', 'og': open_graph, 'act_nav': 'about', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, status=415) # @cache_control(no_cache=True) # @never_cache
Example #7
Source File: cache.py From wagtail-torchbox with MIT License | 5 votes |
def get_default_cache_control_decorator(): cache_control_kwargs = get_default_cache_control_kwargs() return cache_control(**cache_control_kwargs)
Example #8
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_cached_control_private_not_cached(self): """Responses with 'Cache-Control: private' are not cached.""" view_with_private_cache = cache_page(3)(cache_control(private=True)(hello_world_view)) request = self.factory.get('/view/') response = view_with_private_cache(request, '1') self.assertEqual(response.content, b'Hello World 1') response = view_with_private_cache(request, '2') self.assertEqual(response.content, b'Hello World 2')
Example #9
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_cached_control_private_not_cached(self): """Responses with 'Cache-Control: private' are not cached.""" view_with_private_cache = cache_page(3)(cache_control(private=True)(hello_world_view)) request = self.factory.get('/view/') response = view_with_private_cache(request, '1') self.assertEqual(response.content, b'Hello World 1') response = view_with_private_cache(request, '2') self.assertEqual(response.content, b'Hello World 2')
Example #10
Source File: views.py From open-context-py with GNU General Public License v3.0 | 4 votes |
def html_view(request, identifier): rp = RootPath() base_url = rp.get_baseurl() uri = 'http://opencontext.org/vocabularies/' + str(identifier) lequiv = LinkEquivalence() id_list = lequiv.get_identifier_list_variants(uri) lequiv = LinkEquivalence() id_s_list = lequiv.get_identifier_list_variants(uri + '/') for id_s in id_s_list: if id_s not in id_list: # add the slashed version to the list id_list.append(id_s) entity = False for test_id in id_list: ent = Entity() found = ent.dereference(test_id) if found is False: found = ent.dereference(test_id, test_id) if found: entity = ent break if entity is not False: t_vocab = TemplateVocab() t_vocab.create_template_for_entity(entity) t_vocab.make_json_for_html() req_neg = RequestNegotiation('text/html') req_neg.supported_types = ['application/ld+json', 'application/json'] if 'HTTP_ACCEPT' in request.META: req_neg.check_request_support(request.META['HTTP_ACCEPT']) if req_neg.supported: if 'json' in req_neg.use_response_type: # content negotiation requested JSON or JSON-LD json_obj = t_vocab.make_json_obj() return HttpResponse(json.dumps(json_obj, ensure_ascii=False, indent=4), content_type=req_neg.use_response_type + "; charset=utf8") else: template = loader.get_template('vocabularies/view.html') context = { 'item': t_vocab, 'base_url': base_url, 'page_title': 'Open Context: Vocabularies + Ontologies', 'act_nav': 'vocabularies', 'nav_items': settings.NAV_ITEMS } return HttpResponse(template.render(context, request)) else: # client wanted a mimetype we don't support return HttpResponse(req_neg.error_message, content_type="text/plain; charset=utf8", status=415) else: raise Http404 # @cache_control(no_cache=True) # @never_cache