Author: floguy
Date: Thu Oct 16 01:33:47 2008
New Revision: 46

Modified:
    trunk/things/options.py
    trunk/things/templatetags/things_tags.py

Log:
Workaround a django bug, and also the thing_list is much cleaner and less  
code than urlslash.

Modified: trunk/things/options.py
==============================================================================
--- trunk/things/options.py     (original)
+++ trunk/things/options.py     Thu Oct 16 01:33:47 2008
@@ -193,7 +193,7 @@

      def url(self):
          return reverse(
-            '%s_list' % self.parent.name_prefix,
+            '%s_%s_list' % (self.parent.name_prefix, self['url_name']),
              kwargs={'url_prefix': '%s/' % self['url_name']}
          )

@@ -252,9 +252,9 @@
              }
              context.update(extra_context)
              tmp_urls.extend(thing.urls(
-                prefix='%s%s' % (prefix, self.url_prefix, ),
+                prefix='%s%s' % (prefix, self.url_prefix),
                  extra_context=context,
-                name_prefix=name_prefix,
+                name_prefix='%s_%s' % (name_prefix, group['url_name']),
                  url_prefix='%s/' % group['url_name'],
              ))
          return patterns('', *tmp_urls)

Modified: trunk/things/templatetags/things_tags.py
==============================================================================
--- trunk/things/templatetags/things_tags.py    (original)
+++ trunk/things/templatetags/things_tags.py    Thu Oct 16 01:33:47 2008
@@ -1,7 +1,5 @@
  from django import template
-from django.conf import settings
-from django.core.urlresolvers import reverse, NoReverseMatch
-from django.utils.encoding import smart_str
+from django.core.urlresolvers import reverse

  register = template.Library()

@@ -49,67 +47,6 @@
      }
  register.inclusion_tag('things/search.html',  
takes_context=True)(display_search)

-def do_urlslash(parser, token):
-    bits = token.contents.split(' ')
-    if len(bits) < 2:
-        raise template.TemplateSyntaxError("'%s' takes at least one  
argument"
-                                  " (path to a view)" % bits[0])
-    viewname = bits[1]
-    args = []
-    kwargs = {}
-    asvar = None
-
-    if len(bits) > 2:
-        bits = iter(bits[2:])
-        for bit in bits:
-            if bit == 'as':
-                asvar = bits.next()
-                break
-            else:
-                for arg in bit.split(","):
-                    if '=' in arg:
-                        k, v = arg.split('=', 1)
-                        k = k.strip()
-                        kwargs[k] = parser.compile_filter(v)
-                    elif arg:
-                        args.append(parser.compile_filter(arg))
-    return URLSlashNode(viewname, args, kwargs, asvar)
-
-class URLSlashNode(template.Node):
-    def __init__(self, view_name, args, kwargs, asvar):
-        self.view_name = view_name
-        self.args = args
-        self.kwargs = kwargs
-        self.asvar = asvar
-
-    def render(self, context):
-        args = [arg.resolve(context) for arg in self.args]
-        kwargs = dict([(smart_str(k,'ascii'), v.resolve(context))
-                       for k, v in self.kwargs.items()])
-
-
-        # Try to look up the URL twice: once given the view name, and again
-        # relative to what we guess is the "main" app. If they both fail,
-        # re-raise the NoReverseMatch unless we're using the
-        # {% url ... as var %} construct in which cause return nothing.
-        url = ''
-        try:
-            args = ['%s/' % a for a in args]
-            kwargs = dict((k, '%s/' % v) for k, v in kwargs.iteritems())
-            url = reverse(self.view_name, args=args, kwargs=kwargs)
-        except NoReverseMatch:
-            project_name = settings.SETTINGS_MODULE.split('.')[0]
-            try:
-                url = reverse(project_name + '.' + self.view_name,
-                              args=args, kwargs=kwargs)
-            except NoReverseMatch:
-                if self.asvar is None:
-                    raise
-
-        if self.asvar:
-            context[self.asvar] = url
-            return ''
-        else:
-            return url
-
-register.tag('urlslash', do_urlslash)
\ No newline at end of file
+def thing_list(name_prefix, url_name):
+    return reverse(name_prefix + '_' + url_name + '_list', args=[url_name  
+ '/'])
+thing_list = register.simple_tag(thing_list)
\ No newline at end of file

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