1 9 11 15 16 17 18 19 20 22 23 27 29 30 32 34 35 36 37 38 44 47 58 60 62 63 64 66 67 68 69 70 71 72 73 74 76 77 79 84 87 88 90 92 93 94 95 98 101 102 105 107 109 112 113 116 117 118 |
"""Page CMS functions related to the ``request`` object."""
"""Build a ``request`` mock that can be used for testing.""" 'REQUEST_METHOD': 'GET', 'SERVER_NAME': 'test', 'SERVER_PORT': '8000', 'HTTP_HOST': 'testhost', }) # Apply request middleware # LocaleMiddleware should never be applied a second time because # it would broke the current real request language
"""Cannot return context dictionary because a view returned an ``HttpResponse`` when a (template_name, context) tuple was expected."""
""" This view decorator automatically calls the ``render_to_response`` shortcut. A view that use this decorator should return a tuple of this form : (template name, context) instead of a ``HttpRequest`` object. """ # return only context dictionary or response return response context_instance=RequestContext(request))
""" Provide the pages variables to the decorated view. """ path = kwargs.pop('path', None) lang = kwargs.pop('lang', None) if path or lang: from pages.views import details response = details(request, path=path, lang=lang, only_context=True, delegation=False) context = response kwargs.update(context) return view(request, *args, **kwargs)
"""Return the page's slug and relative path.""" path = path[:-1] lang = path.split("/")[0] path = path[(len(lang) + 1):]
""" Gets a valid template from different sources or falls back to the default template. """ return settings.DEFAULT_PAGE_TEMPLATE (template in dict(page_templates).keys() or template == settings.DEFAULT_PAGE_TEMPLATE): return page.get_template()
"""Return the most obvious language according the request.""" return language
else: return settings.PAGE_DEFAULT_LANGUAGE
|