Ticket #4713: 4713.patch
File 4713.patch, 1.8 KB (added by , 17 years ago) |
---|
-
django/template/__init__.py
642 642 """ 643 643 return Variable(path).resolve(context) 644 644 645 trans_re = re.compile(r'_\((.*)\)$') 646 645 647 class Variable(object): 646 648 """ 647 649 A template variable, resolvable against a given context. The variable may be … … 667 669 self.var = var 668 670 self.literal = None 669 671 self.lookups = None 672 self.translate = False 670 673 671 674 try: 672 675 # First try to treat this variable as a number. … … 687 690 688 691 except ValueError: 689 692 # A ValueError means that the variable isn't a number. 693 694 # Check to see if we're dealing with a translatable var: 695 translate = trans_re.match(var) 696 if translate: 697 self.translate = True 698 var = translate.group(1) 699 690 700 # If it's wrapped with quotes (single or double), then 691 701 # we're also dealing with a literal. 692 702 if var[0] in "\"'" and var[0] == var[-1]: … … 701 711 """Resolve this variable against a given context.""" 702 712 if self.lookups is not None: 703 713 # We're dealing with a variable that needs to be resolved 704 returnself._resolve_lookup(context)714 var = self._resolve_lookup(context) 705 715 else: 706 716 # We're dealing with a literal, so it's already been "resolved" 707 return self.literal 717 var = self.literal 718 if self.translate: 719 # We need to translate the variable 720 var = _(var) 721 return var 708 722 709 723 def __repr__(self): 710 724 return "<%s: %r>" % (self.__class__.__name__, self.var)