I've been running into a problem that seems very similar to http://code.djangoproject.com/ticket/170, although I see that that issue was fixed so I am betting the bug is on my end somewhere. Unfortunately, I'm a little green w.r.t. unicode issues so I'm hoping someone else can correct my misconceptions.
My app's templatetags/navigation.py file is enclosed. If you look for the string ".title()" you can see where the title() method on my Page objects is getting called. Unless I change that method to encode its result as ascii or utf-8, I get the exception. Can anyone explain what's going on? I suspect problems with mixing utf-8 and ascii encoded strings, but I'm really out of my depth here. Many thanks in advance. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---
from django import template # from static.models import Page from static import Page register = template.Library() class Home: '''A fake page that gets us an initial Home menu''' def children(self): return [] def get_absolute_url(self): return '/' def title(self): return 'Home' class NavigationNode(template.Node): @classmethod def _menu_items(self, root, pages, depth): if depth == 0: return '' items = [] items.append( ' <li class="self"><a href="%s">%s Home</a></li>' % ( root.get_absolute_url(), root.title())) for i in range(len(pages)): p = pages[i] c = p.children() classes = [] if c: classes.append('submenu') if i == len(pages) - 1: classes.append('last') items.append( ' <li %s><a href="%s">%s</a>\n%s</li>' % ( len(classes) and ('class="' + ' '.join(classes) + '"') or '', p.get_absolute_url(), p.title(), self._menu_items(root, p.children(),depth-1))) return ' <ul>\n%s</ul>\n' % ''.join(items) def render(self, ctx): result = '<ul>\n' first = 'first-' for top in [Home()] + Page.roots(): children = top.children() if children: leaf = '' # increase depth to create multilevel menus menu_items = self._menu_items(top, children, depth=1) else: menu_items = '' leaf = '-leaf' result += '<li class="%smenu%s">' % (first, leaf) result += '<a href="%s">%s</a>\n' % (top.get_absolute_url(), top.title()) result += menu_items result += '</li>' return result + '</ul>\n' def navigation_tree(parser, token): return NavigationNode() register.tag(navigation_tree)
-- Dave Abrahams Boost Consulting www.boost-consulting.com