Ticket #2539: template_01.diff
| File template_01.diff, 5.6 KB (added by , 20 years ago) |
|---|
-
template/__init__.py
60 60 from django.template.context import Context, RequestContext, ContextPopException 61 61 from django.utils.functional import curry 62 62 from django.utils.text import smart_split 63 63 64 64 65 __all__ = ('Template', 'Context', 'RequestContext', 'compile_string') 65 66 … … 223 224 self.tokens = tokens 224 225 self.tags = {} 225 226 self.filters = {} 227 226 228 for lib in builtins: 227 229 self.add_library(lib) 228 230 … … 251 253 # execute callback function for this tag and append resulting node 252 254 self.enter_command(command, token) 253 255 try: 254 compile_func = self. tags[command]256 compile_func = self. 255 257 except KeyError: 256 258 self.invalid_block_tag(token, command) 257 259 try: … … 317 319 def add_library(self, lib): 318 320 self.tags.update(lib.tags) 319 321 self.filters.update(lib.filters) 322 323 324 325 320 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 321 351 def compile_filter(self, token): 322 352 "Convenient wrapper for FilterExpression" 323 353 return FilterExpression(token, self) 324 354 325 355 def find_filter(self, filter_name): 326 if self.filters.has_key(filter_name): 327 return self.filters[filter_name] 328 else: 356 try: 357 return self.get_filters(filter_name) 358 except: 359 import traceback 360 traceback.print_exc() 329 361 raise TemplateSyntaxError, "Invalid filter: '%s'" % filter_name 362 363 364 365 330 366 331 367 class DebugParser(Parser): 332 368 def __init__(self, lexer): … … 468 504 ^"(?P<constant>%(str)s)"| 469 505 ^(?P<var>[%(var_chars)s]+)| 470 506 (?:%(filter_sep)s 471 (?P<filter_name> \w+)507 (?P<filter_name>+) 472 508 (?:%(arg_sep)s 473 509 (?: 474 510 %(i18n_open)s"(?P<i18n_arg>%(str)s)"%(i18n_close)s| … … 873 909 return func 874 910 return dec 875 911 912 876 913 def get_library(module_name): 877 914 lib = libraries.get(module_name, None) 878 915 if not lib: 879 916 try: 880 917 mod = __import__(module_name, '', '', ['']) 918 919 920 921 922 923 924 881 925 except ImportError, e: 926 927 882 928 raise InvalidTemplateLibrary, "Could not load template library from %s, %s" % (module_name, e) 883 929 try: 884 930 lib = mod.register 931 932 933 934 885 935 libraries[module_name] = lib 886 936 except AttributeError: 887 937 raise InvalidTemplateLibrary, "Template library %s does not have a variable named 'register'" % module_name -
template/defaulttags.py
686 686 for taglib in bits[1:]: 687 687 # add the library to the parser 688 688 try: 689 lib = get_library("django.templatetags.%s" % taglib.split('.')[-1]) 689 if taglib.find('.') > -1: 690 appname, module = taglib.split('.') 691 taglib = '.'.join([appname, 'templatetags', module]) 692 lib = get_library("django.templatetags.%s" % taglib) 690 693 parser.add_library(lib) 691 694 except InvalidTemplateLibrary, e: 695 696 692 697 raise TemplateSyntaxError, "'%s' is not a valid tag library: %s" % (taglib, e) 693 698 return LoadNode() 694 699 load = register.tag(load) -
templatetags/__init__.py
2 2 3 3 for a in settings.INSTALLED_APPS: 4 4 try: 5 5 6 __path__.extend(__import__(a + '.templatetags', '', '', ['']).__path__) 6 7 except ImportError: 7 8 pass