1 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 32 35 38 40 41 42 43 44 46 47 49 51 52 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
"""Default example views"""
"""This view get the root pages for navigation and the current page to display if there is any.
All is rendered with the current page's template.
This view use the auto_render decorator. It means that you can use the only_context extra parameter to get only the local variables of this view without rendering the template.
>>> from pages.views import details >>> context = details(request, only_context=True)
This can be usefull if you want to write your own view. You can reuse the following code without having to copy and paste it."""
'path': path, 'pages_navigation': pages_navigation, 'lang': lang, }
raise Http404
and request.user.is_staff) current_page = Page.objects.from_path(path, lang, exclude_drafts=exclude_drafts) current_page = Page.objects.published().order_by("tree_id")[0]
# if no pages has been found, we will try to find it via an Alias if not current_page: alias = PageAlias.objects.from_path(request, path, lang) if alias: url = alias.page.get_url_path(lang) return HttpResponsePermanentRedirect(url) raise Http404
if (not (request.user.is_authenticated() and request.user.is_staff) and current_page.calculated_status in (Page.DRAFT, Page.EXPIRED)): raise Http404
if current_page.redirect_to_url: return HttpResponsePermanentRedirect(current_page.redirect_to_url)
if current_page.redirect_to: return HttpResponsePermanentRedirect( current_page.redirect_to.get_url_path(lang))
template_name = current_page.get_template()
if request.is_ajax(): template_name = "body_%s" % template_name
if current_page: context['current_page'] = current_page
if settings.PAGE_EXTRA_CONTEXT: context.update(settings.PAGE_EXTRA_CONTEXT())
if delegation and current_page.delegate_to: urlconf = get_urlconf(current_page.delegate_to) result = resolve('/', urlconf) if len(result): view, args, kwargs = result kwargs['current_page'] = current_page kwargs['path'] = path kwargs['lang'] = lang kwargs['pages_navigation'] = pages_navigation return view( request, *args, **kwargs )
return template_name, context
|