Revision: 639
Author: batiste.bieler
Date: Fri Aug 14 06:19:05 2009
Log: Try to fix the load_pages template tag
http://code.google.com/p/django-page-cms/source/detail?r=639

Modified:
  /trunk/pages/templatetags/pages_tags.py
  /trunk/pages/views.py

=======================================
--- /trunk/pages/templatetags/pages_tags.py     Fri Aug 14 01:06:31 2009
+++ /trunk/pages/templatetags/pages_tags.py     Fri Aug 14 06:19:05 2009
@@ -8,8 +8,8 @@
  import urllib

  from pages import settings
-from pages.models import Content, Page, PageAlias
-from pages.http import get_language_from_request
+from pages.models import Content, Page
+from pages.views import details

  register = template.Library()

@@ -210,16 +210,12 @@
  class LoadPagesNode(template.Node):
      """Load page node."""
      def render(self, context):
-        if (not context.has_key('lang')):
-            context['lang'] = get_language_from_request(request)
-        if (not context.has_key('pages')):
-            context['pages'] = Page.objects.navigation()
          request = context['request']
-        if (not context.has_key('current_page')):
-            alias = PageAlias.objects.from_path(request, request.path)
-            if alias:
-                context['current_page'] = alias.page
-        return ''
+        try:
+            page_dict = details(request, only_context=True)
+            context.update(page_dict)
+        except Exception, e:
+            return

  def do_load_pages(parser, token):
      """Load the navigation pages, lang, and current_page variables into the
=======================================
--- /trunk/pages/views.py       Fri Aug 14 01:06:31 2009
+++ /trunk/pages/views.py       Fri Aug 14 06:19:05 2009
@@ -27,10 +27,17 @@

      pages = Page.objects.navigation().order_by("tree_id")
      current_page = False
+    template_name = settings.DEFAULT_PAGE_TEMPLATE

      if lang is None:
          lang = get_language_from_request(request)

+    context = {
+        'path': path,
+        'pages': pages,
+        'lang': lang,
+    }
+
      if lang not in [key for (key, value) in settings.PAGE_LANGUAGES]:
          raise Http404

@@ -39,34 +46,29 @@
      elif pages:
          current_page = pages[0]

-    # if no pages has been found, we will try to find an Alias
+    # 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 not alias:
+        if alias:
+            url = alias.page.get_absolute_url(lang)
+            return HttpResponsePermanentRedirect(url)
+    else:
+        if not (request.user.is_authenticated() and request.user.is_staff)  
and \
+                current_page.calculated_status in (Page.DRAFT,  
Page.EXPIRED):
              raise Http404
-        url  = alias.page.get_absolute_url(lang)
-        return HttpResponsePermanentRedirect(url)
-
-    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:
-        return HttpResponsePermanentRedirect(
-            current_page.redirect_to.get_absolute_url(lang))
-
-    template_name = current_page.get_template()
+
+        if current_page.redirect_to:
+            return HttpResponsePermanentRedirect(
+                current_page.redirect_to.get_absolute_url(lang))
+
+        template_name = current_page.get_template()

      if request.is_ajax():
-        new_template_name = "body_%s" % template_name
-        return new_template_name, locals()
-
-    return template_name, {
-        'path': path,
-        'pages': pages,
-        'current_page': current_page,
-        'lang': lang,
-        'request': request,
-    }
+        template_name = "body_%s" % template_name
+
+    if current_page:
+        context['current_page'] = current_page
+
+    return template_name, context

  details = auto_render(details)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to