Commits

Anonymous committed 58d164e

My caching was cached - and that makes a lot of intresting bugs.
Listing and ordering bugs fixed too

Comments (0)

Files changed (6)

eagproject/eagadmin/models/pages.py

 # pages at the beginning, parse it,
 # construct tree and forget datastore
 
-def _caching(func):
-    """ Caching decorator (Only for request lifetime)
-
-        Chache key only depends on first arg
-    """
-    cache = {}
-    def newfunc(*args):
-        if not args: return func(*args)
-        key = getattr(args[0], 'key', lambda: str(args[0]))()
-        if not key in cache:
-            cache[key] = func(*args)
-        return cache[key]
-    return newfunc
-
 def _draft_filter(func):
     """ Decorator prevents acsesing draft pages """
     def newfunc(*args, **kwargs):
         return [p for p in ret if not p.draft]
     return newfunc
 
-@_caching
 def get_root():
     root = Page.all().filter('level =', 0).get()
     if root:
     return get_descendants(page)
 
 @_draft_filter
-@_caching
 def get_children(page):
     return Page.all().filter('top =', page.key()).order('order')
 
 @_draft_filter
-@_caching
 def get_prev(page):
     return Page.all() \
             .filter('top =', page.top.key()) \
             .filter('order =', page.order - 1)
 
 @_draft_filter
-@_caching
 def get_next(page):
     return Page.all() \
             .filter('top =', page.top.key()) \
             .filter('order =', page.order + 1)
 
 @_draft_filter
-@_caching
 def get_by_slug(slug=''):
     if slug:
         return Page.all().filter('slug =', slug).get()
     return pages
 
 @_draft_filter
-@_caching
 def get_breadcrumb(page):
     tops = []
     top = page
         if level > prev_level:
             tops.append(prev_page), orders.append(0)
         elif level < prev_level:
-            tops.pop(), orders.pop()
+            # It can go up more than one step
+            for i in range(prev_level - level):
+                tops.pop(), orders.pop()
 
         page.top = tops[-1]
         page.level = level

eagproject/eagadmin/templatetags/eagsite.py

         item = self.item.resolve(context)
         current = template.Variable('current').resolve(context)
         breadcrumb = template.Variable('breadcrumb').resolve(context)
-        lis = []
         try:
             items = pages.get_descendants(item, self.depth)
         except AttributeError:
         return self.output(items, current, breadcrumb)
 
     def output(self, items, current, breadcrumb):
-        level = items[0].level
+        first = items[0]
+        level = first.level
         out = []
         for p in items:
             if level < p.level:
                 out.append('<ul>')
             if level > p.level:
-                out.append('</ul>')
+                out.append('</ul>' * (level - p.level))
 
             cl = ''
             if p == current:
             params = (p.get_absolute_url(), target, p.menu_title)
             out.append('<a href="%s"%s>%s</a>' % params)
             level = p.level
+        out.append('</ul>' * (level - first.level))
         return ''.join(out)
 
 def list_menu(parser, token):

eagproject/settings.py.sample

     'django.middleware.common.CommonMiddleware',
 )
 
-ROOT_URLCONF = 'dproject.urls'
+ROOT_URLCONF = 'eagproject.urls'
 
 SITE_ROOT = os.path.dirname(__file__)
 

eagproject/templates/eagadmin/new.html

 {% endblock %}
 {% block body_end %}
   <script type="text/javascript" charset="utf-8"
-    src="eag-static/js/pageinfo.js"></script>
+    src="{{ MEDIA_URL }}eag-static/js/pageinfo.js"></script>
 {% endblock %}

eagproject/templates/eagsite/page.html

   {% eagsite_get_page "secret" as secret_page %}
   {% if secret_page %}
     <a href="{{ secret_page.get_absolute_url }}">{{ secret_page.menu_title }}</a>
-    <br/>
-    <br/>
   {% endif %}
   {% for page in breadcrumb|slice:"2:" %}
     {{ page.menu_title }} -&gt;
 from google.appengine.ext.webapp import util
 from django.core.handlers.wsgi import WSGIHandler
 
-os.environ['DJANGO_SETTINGS_MODULE'] = 'dproject.settings'
-sys.path.append(os.path.join(os.path.dirname(__file__), 'dproject'))
+os.environ['DJANGO_SETTINGS_MODULE'] = 'eagproject.settings'
+sys.path.append(os.path.join(os.path.dirname(__file__), 'eagproject'))
 from django.conf import settings
 settings._target = None