def do_takes_current_page(context, *args, **kwargs): page = get_page_from_context(context, kwargs) if not page: page = get_default_news_page() if page is None: raise template.VariableDoesNotExist("Could not determine the current page from the template context.") kwargs["page"] = page return func(context, *args, **kwargs)
def do_takes_current_page(context, *args, **kwargs): page = get_page_from_context(context, kwargs) if not page: page = get_default_news_page() if page is None: raise template.VariableDoesNotExist( "Could not determine the current page from the template context." ) kwargs["page"] = page return func(context, *args, **kwargs)
def get_page_from_context(context, kwargs): """Returns the current page based on the given template context.""" page = None # Resolve the page. if "page" in kwargs: page = kwargs["page"] elif "page" in context: page = context["page"] elif "pages" in context: pages = context["pages"] page = pages.current # Adapt the page. if isinstance(page, int): page = Page.objects.get(id=page) if page and page.content_type_id != ContentType.objects.get_for_model(NewsFeed).id: page = get_default_news_page() # All done. return page
def get_page_from_context(context, kwargs): """Returns the current page based on the given template context.""" page = None # Resolve the page. if "page" in kwargs: page = kwargs["page"] elif "page" in context: page = context["page"] elif "pages" in context: pages = context["pages"] page = pages.current # Adapt the page. if isinstance(page, int): page = Page.objects.get(id=page) if page and page.content_type_id != ContentType.objects.get_for_model( NewsFeed).id: page = get_default_news_page() # All done. return page