Django

Code

Ticket #7239: patch_django_7239.20080530.diff

File patch_django_7239.20080530.diff, 1.9 kB (added by david, 6 months ago)

First naive implementation

  • django/templatetags/i18n.py

    old new  
    33from django.template import Node, Variable, VariableNode 
    44from django.template import TemplateSyntaxError, TokenParser, Library 
    55from django.template import TOKEN_TEXT, TOKEN_VAR 
     6from django.template.defaulttags import URLNode 
    67from django.utils import translation 
    78from django.utils.encoding import force_unicode 
    89 
     
    218219                        raise TemplateSyntaxError, "variable bindings in 'blocktrans' must be 'with value as variable'" 
    219220                    extra_context[self.tag()] = VariableNode( 
    220221                            parser.compile_filter(value)) 
     222                elif tag == 'url': 
     223                    args = [] 
     224                    kwargs = {} 
     225                    value = self.value() 
     226                    next_tag = self.tag() 
     227                    if next_tag != 'as': 
     228                        if self.tag() != 'as': 
     229                            raise TemplateSyntaxError, "variable bindings in 'blocktrans' must be 'url path.to.some_view arg1,arg2,name1=value1 as variable'" 
     230                        else: 
     231                            # can't find  way to do not duplicate code from url tag 
     232                            for arg in next_tag.split(','): 
     233                                if '=' in arg: 
     234                                    k, v = arg.split('=', 1) 
     235                                    k = k.strip() 
     236                                    kwargs[k] = parser.compile_filter(v) 
     237                                else: 
     238                                    args.append(parser.compile_filter(arg)) 
     239                    extra_context[self.tag()] = URLNode(value, args, kwargs) 
    221240                elif tag == 'count': 
    222241                    counter = parser.compile_filter(self.value()) 
    223242                    if self.tag() != 'as':