Ticket #7251: django-if-tag.2.patch
File django-if-tag.2.patch, 2.0 KB (added by , 17 years ago) |
---|
-
template/defaulttags.py
57 57 output.append(pformat(sys.modules)) 58 58 return ''.join(output) 59 59 60 class ExceptionNode(Node): 61 def __init__(self, exception): 62 self.exception = exception 63 64 def render(self, context): 65 raise self.exception 66 60 67 class FilterNode(Node): 61 68 def __init__(self, filter_expr, nodelist): 62 69 self.filter_expr, self.nodelist = filter_expr, nodelist … … 640 647 if len(bits) != 3: 641 648 raise TemplateSyntaxError, "%r takes two arguments" % bits[0] 642 649 end_tag = 'end' + bits[0] 643 nodelist_true = parser.parse(('else', end_tag)) 650 try: 651 nodelist_true = parser.parse(('else', end_tag)) 652 except Exception, e: 653 nodelist_true = NodeList([ExceptionNode(e)]) 644 654 token = parser.next_token() 645 655 if token.contents == 'else': 646 nodelist_false = parser.parse((end_tag,)) 656 try: 657 nodelist_false = parser.parse((end_tag,)) 658 except Exception, e: 659 nodelist_false = NodeList([ExceptionNode(e)]) 647 660 parser.delete_first_token() 648 661 else: 649 662 nodelist_false = NodeList() … … 761 774 boolvars.append((True, parser.compile_filter(boolvar))) 762 775 else: 763 776 boolvars.append((False, parser.compile_filter(boolpair))) 764 nodelist_true = parser.parse(('else', 'endif')) 777 try: 778 nodelist_true = parser.parse(('else', 'endif')) 779 except Exception, e: 780 nodelist_true = NodeList([ExceptionNode(e)]) 765 781 token = parser.next_token() 766 782 if token.contents == 'else': 767 nodelist_false = parser.parse(('endif',)) 783 try: 784 nodelist_false = parser.parse(('endif',)) 785 except Exception, e: 786 nodelist_false = NodeList([ExceptionNode(e)]) 768 787 parser.delete_first_token() 769 788 else: 770 789 nodelist_false = NodeList()