def _get_current_page(context): """ Fetch the current page. """ request = _get_request(context) # This is a load-on-demand attribute, to allow calling the template tags outside the standard view. # When the current page is not specified, do auto-detection. if not hasattr(request, '_current_fluent_page'): try: # First start with something you can control, # and likely want to mimic from the standard view. current_page = context['page'] except KeyError: try: # Then try looking up environmental properties. current_page = UrlNode.objects.get_for_path(request.path) except UrlNode.DoesNotExist as e: # Be descriptive. This saves precious developer time. raise UrlNode.DoesNotExist("Could not detect current page.\n" "- " + str(e) + "\n" "- No context variable named 'page' found.") if not isinstance(current_page, UrlNode): raise UrlNode.DoesNotExist("The 'page' context variable is not a valid page") prefill_parent_site(current_page) request._current_fluent_page = current_page return request._current_fluent_page # is a UrlNode
def _call_url_view(self, plugin, sub_path, match): """ Call the extra URLpattern view. """ # Check that there wasn't a fetch in the fallback language, # perform some service for the user if this is the case. if _is_accidental_fallback(self.object, self.language_code): self.object.set_current_language(self.language_code) return HttpResponsePermanentRedirect( self.object.default_url.rstrip('/') + sub_path) # Avoid additional lookup in templatetags self.request._current_fluent_page = self.object prefill_parent_site(self.object) # Get view response response = plugin.get_view_response(self.request, self.object, match.func, match.args, match.kwargs) if response is None: raise RuntimeError( "The view '{0}' didn't return an HttpResponse object.".format( match.url_name)) return response
def _call_node_view(self, plugin): """ Call the regular view. """ # Check that there wasn't a fetch in the fallback language, # perform some service for the user if this is the case. if _is_accidental_fallback(self.object, self.language_code): self.object.set_current_language(self.language_code) return HttpResponsePermanentRedirect(self.object.default_url) # Store the current page. This is used in the `app_reverse()` code, # and also avoids additional lookup in templatetags. # NOTE: django-fluent-blogs actually reads this variable too (should use CurrentPageMixin now) self.request._current_fluent_page = self.object prefill_parent_site(self.object) # Let page type plugin handle the request. response = plugin.get_response(self.request, self.object) if response is None: # Avoid automatic fallback to 404 page in this dispatcher. raise ValueError( "The method '{0}.get_response()' didn't return an HttpResponse object." .format(plugin.__class__.__name__)) return response
def _call_url_view(self, plugin, sub_path, match): """ Call the extra URLpattern view. """ # Check that there wasn't a fetch in the fallback language, # perform some service for the user if this is the case. if _is_accidental_fallback(self.object, self.language_code): self.object.set_current_language(self.language_code) return HttpResponsePermanentRedirect(self.object.default_url.rstrip('/') + sub_path) # Avoid additional lookup in templatetags self.request._current_fluent_page = self.object prefill_parent_site(self.object) # Get view response response = plugin.get_view_response(self.request, self.object, match.func, match.args, match.kwargs) if response is None: raise RuntimeError("The view '{0}' didn't return an HttpResponse object.".format(match.url_name)) return response
def _call_node_view(self, plugin): """ Call the regular view. """ # Check that there wasn't a fetch in the fallback language, # perform some service for the user if this is the case. if _is_accidental_fallback(self.object, self.language_code): self.object.set_current_language(self.language_code) return HttpResponsePermanentRedirect(self.object.default_url) # Store the current page. This is used in the `app_reverse()` code, # and also avoids additional lookup in templatetags. # NOTE: django-fluent-blogs actually reads this variable too (should use CurrentPageMixin now) self.request._current_fluent_page = self.object prefill_parent_site(self.object) # Let page type plugin handle the request. response = plugin.get_response(self.request, self.object) if response is None: # Avoid automatic fallback to 404 page in this dispatcher. raise ValueError("The method '{0}.get_response()' didn't return an HttpResponse object.".format(plugin.__class__.__name__)) return response