示例#1
0
文件: news.py 项目: JamesJGarner/cms
 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)
示例#2
0
 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)
示例#3
0
文件: news.py 项目: JamesJGarner/cms
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
示例#4
0
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