Author: batiste.bieler
Date: Tue Jun 16 12:32:49 2009
New Revision: 569

Modified:
    trunk/example/templates/pages/index.html
    trunk/example/templates/pages/nice.html
    trunk/pages/http.py
    trunk/pages/models.py
    trunk/pages/templatetags/pages_tags.py
    trunk/pages/utils.py

Log:
Now overriding a block with placeholder will work. Crunch a bunch of bugs  
with templates in the admin.

Modified: trunk/example/templates/pages/index.html
==============================================================================
--- trunk/example/templates/pages/index.html    (original)
+++ trunk/example/templates/pages/index.html    Tue Jun 16 12:32:49 2009
@@ -118,12 +118,15 @@
              <div id="body" class="placeholder">{% placeholder body on  
current_page with WYMEditor parsed  %}</div>
          </div>
          <div>
-            {% placeholder custom_widget_example on current_page with  
example.widgets.CustomTextarea parsed  %}
          </div>
      </div>
      {% endif %}
  {% endblock %}

+{% block override %}
+    <!-- nice.html overrideing this block to make custom-widget-example  
disapear form the admin -->
+    {% placeholder custom-widget-example on current_page with  
example.widgets.CustomTextarea parsed  %}
+{% endblock %}
  </div>

  <script type="text/javascript">

Modified: trunk/example/templates/pages/nice.html
==============================================================================
--- trunk/example/templates/pages/nice.html     (original)
+++ trunk/example/templates/pages/nice.html     Tue Jun 16 12:32:49 2009
@@ -3,6 +3,10 @@

  {% block title %}Nice template{% endblock %}

+{% block override %}
+    <!-- by overrideing this block custom-widget-example should disapear  
form the admin -->
+{% endblock %}
+
  {% block content %}{{ block.super }}
  <div style="width:70%">
      <div>fancy content
@@ -12,4 +16,9 @@
      </div>
      {% placeholder right-column with Textarea parsed as right_column %}
  </div>
+
  {% endblock %}
+
+
+
+

Modified: trunk/pages/http.py
==============================================================================
--- trunk/pages/http.py (original)
+++ trunk/pages/http.py Tue Jun 16 12:32:49 2009
@@ -60,7 +60,8 @@
          return settings.DEFAULT_PAGE_TEMPLATE
      template = request.REQUEST.get('template', None)
      if template is not None and \
-            template in dict(settings.PAGE_TEMPLATES).keys():
+            (template in dict(settings.PAGE_TEMPLATES).keys() or
+            template == settings.DEFAULT_PAGE_TEMPLATE):
          return template
      if obj is not None:
          return obj.get_template()

Modified: trunk/pages/models.py
==============================================================================
--- trunk/pages/models.py       (original)
+++ trunk/pages/models.py       Tue Jun 16 12:32:49 2009
@@ -33,7 +33,7 @@

      PAGE_LANGUAGES_KEY = "page_%d_languages"
      PAGE_URL_KEY = "page_%d_language_%s_url"
-    PAGE_TEMPLATE_KEY = "page_%d_template"
+    #PAGE_TEMPLATE_KEY = "page_%d_template"
      #PAGE_CHILDREN_KEY = "page_children_%d_%d"
      PAGE_CONTENT_DICT_KEY = "page_content_dict_%d_%s"

@@ -112,7 +112,7 @@
          """Invalidate a page and it's descendants"""

          cache.delete(self.PAGE_LANGUAGES_KEY % (self.id))
-        cache.delete(self.PAGE_TEMPLATE_KEY % (self.id))
+        #cache.delete(self.PAGE_TEMPLATE_KEY % (self.id))

          p_names = [p.name for p in get_placeholders(self.get_template())]
          if 'slug' not in p_names:
@@ -187,21 +187,15 @@
          """
          if self.template:
              return self.template
-
-        template = cache.get(self.PAGE_TEMPLATE_KEY % (self.id))
-        if template:
-            return template

-        if not template:
-            for p in self.get_ancestors(ascending=True):
-                if p.template:
-                    template = p.template
-                    break
+        template = None
+        for p in self.get_ancestors(ascending=True):
+            if p.template:
+                template = p.template
+                break

          if not template:
              template = settings.DEFAULT_PAGE_TEMPLATE
-
-        cache.set(self.PAGE_TEMPLATE_KEY % (self.id), template)

          return template


Modified: trunk/pages/templatetags/pages_tags.py
==============================================================================
--- trunk/pages/templatetags/pages_tags.py      (original)
+++ trunk/pages/templatetags/pages_tags.py      Tue Jun 16 12:32:49 2009
@@ -287,6 +287,7 @@
          self.widget = widget
          self.parsed = parsed
          self.as_varname = as_varname
+        self.found_in_block = None

      def render(self, context):
          if not 'request' in context or not self.page in context:

Modified: trunk/pages/utils.py
==============================================================================
--- trunk/pages/utils.py        (original)
+++ trunk/pages/utils.py        Tue Jun 16 12:32:49 2009
@@ -2,6 +2,7 @@
  from django.conf import settings as django_settings
  from django.template import TemplateDoesNotExist
  from django.template.loader_tags import ExtendsNode, ConstantIncludeNode
+from django.template.loader_tags import BlockNode
  from django.template import loader, Context, RequestContext
  from django.http import Http404

@@ -26,16 +27,26 @@
      except Http404:
          context = {}
      temp.render(RequestContext(request, context))
-    plist = []
-    placeholders_recursif(temp.nodelist, plist)
+    plist, blist = [], []
+    placeholders_recursif(temp.nodelist, plist, blist)
      return plist

-def placeholders_recursif(nodelist, plist):
+def placeholders_recursif(nodelist, plist, blist):
      """
      Recursively search into a template node list for PlaceholderNode node
      """
+
      for node in nodelist:
-        # Using isinstance is always a bad idea and never works properly.
+
+        # extends node
+        if hasattr(node, 'parent_name'):
+            placeholders_recursif(node.get_parent(Context()).nodelist,
+                                                        plist, blist)
+        # include node
+        elif hasattr(node, 'template'):
+            placeholders_recursif(node.template.nodelist, plist, blist)
+
+        # It's a placeholder
          if hasattr(node, 'page') and hasattr(node, 'parsed') and \
                  hasattr(node, 'as_varname') and hasattr(node, 'name'):
              already_in_plist = False
@@ -43,19 +54,29 @@
                  if p.name == node.name:
                      already_in_plist = True
              if not already_in_plist:
+                if len(blist):
+                    node.found_in_block = blist[len(blist)-1]
                  plist.append(node)
              node.render(Context())
+
          for key in ('nodelist', 'nodelist_true', 'nodelist_false'):
+            if isinstance(node, BlockNode):
+                # delete placeholders found in a block of the same name
+                for index, p in enumerate(plist):
+                    if p.found_in_block and \
+                            p.found_in_block.name == node.name \
+                            and p.found_in_block != node:
+                        del plist[index]
+                blist.append(node)
+
              if hasattr(node, key):
                  try:
-                    placeholders_recursif(getattr(node, key), plist)
+                    placeholders_recursif(getattr(node, key), plist, blist)
                  except:
                      pass
-    for node in nodelist:
-        if isinstance(node, ExtendsNode):
-            placeholders_recursif(node.get_parent(Context()).nodelist,  
plist)
-        elif isinstance(node, ConstantIncludeNode):
-            placeholders_recursif(node.template.nodelist, plist)
+            if isinstance(node, BlockNode):
+                blist.pop()
+

  def has_page_add_permission(request, page=None):
      """

--~--~---------~--~----~------------~-------~--~----~
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