def load_template(self, template_name, template_dirs=None): # IMPORTANT NOTE: We load the template, using the original loaders. # call compile, but still return the original, # unmodified result. This causes the django to call # load_template again for every include node where of # course the validation may fail. (incomplete HTML # tree, maybe only javascript, etc...) # Load template template, origin = self.find_template(template_name, template_dirs) # Compile template as a test (could raise CompileException), throw away the compiled result. try: # Don't compile template when a parent frame was a 'render' method. Than it's probably a # runtime call from an IncludeNode or ExtendsNode. import inspect if not any(i[3] in ('render', 'do_include') for i in inspect.getouterframes(inspect.currentframe())): # Precompile command print 'compiling %s' % template_name execute_precompile_command() compile(template, loader = lambda path: self.find_template(path)[0], path=template_name, options=get_options_for_path(origin.name) + _OVERRIDE_OPTIONS_FOR_VALIDATION ) except Exception, e: # Print exception on console print '---' print 'Template: %s' % template_name print e print '-' import traceback traceback.print_exc() print '---' raise e
def load_template(self, template_name, template_dirs=None): template, origin = self.find_template(template_name, template_dirs) # Precompile command execute_precompile_command() # Compile template template, context = compile(template, path=template_name, loader = lambda path: self.find_template(path)[0], options=get_options_for_path(origin.name) + self.options, context_class=self.context_class) # Turn into Template object template = get_template_from_string(template, origin, template_name) # Return result return template, None
def load_template(self, template_name, template_dirs=None): template, origin = self.find_template(template_name, template_dirs) # Precompile command execute_precompile_command() print 'compiling %s' % template_name # Compile template template, context = compile( template, path=template_name, loader=lambda path: self.find_template(path)[0], options=get_options_for_path(origin.name) + self.options, context_class=self.context_class) # Turn into Template object template = get_template_from_string(template, origin, template_name) # Return result return template, None
def load_template(self, template_name, template_dirs=None): # IMPORTANT NOTE: We load the template, using the original loaders. # call compile, but still return the original, # unmodified result. This causes the django to call # load_template again for every include node where of # course the validation may fail. (incomplete HTML # tree, maybe only javascript, etc...) # Load template template, origin = self.find_template(template_name, template_dirs) # Compile template as a test (could raise CompileException), throw away the compiled result. try: # Don't compile template when a parent frame was a 'render' method. Than it's probably a # runtime call from an IncludeNode or ExtendsNode. import inspect if not any( i[3] in ('render', 'do_include') for i in inspect.getouterframes(inspect.currentframe())): # Precompile command print 'compiling %s' % template_name execute_precompile_command() compile(template, loader=lambda path: self.find_template(path)[0], path=template_name, options=get_options_for_path(origin.name) + _OVERRIDE_OPTIONS_FOR_VALIDATION) except Exception, e: # Print exception on console print '---' print 'Template: %s' % template_name print e print '-' import traceback traceback.print_exc() print '---' raise e
def handle(self, *args, **options): all_templates = options['all_templates'] interactive = options['interactive'] self.insert_debug_symbols = options['insert_debug_symbols'] # Default verbosity self.verbosity = int(options.get('verbosity', 1)) # Colors? self.boring = bool(options.get('boring')) # All languages by default languages = [l[0] for l in settings.LANGUAGES] if options['languages'] is None: options['languages'] = languages self._errors = [] if languages.sort() != options['languages'].sort(): print self.colored('Warning: all template languages are deleted while we won\'t generate them again.', 'white', 'on_red') # Delete previously compiled templates and media files # (This is to be sure that no template loaders were configured to # load files from this cache.) if all_templates: if not interactive or raw_input('\nDelete all files in template cache directory: %s? [y/N] ' % settings.TEMPLATE_CACHE_DIR).lower() == 'y': for root, dirs, files in os.walk(settings.TEMPLATE_CACHE_DIR): for f in files: if not f[0] == '.': # Skip hidden files path = os.path.join(root, f) if self.verbosity >= 1: print ('Deleting old template: %s' % path) os.remove(path) if not interactive or raw_input('\nDelete all files in media cache directory %s? [y/N] ' % settings.MEDIA_CACHE_DIR).lower() == 'y': for root, dirs, files in os.walk(settings.MEDIA_CACHE_DIR): for f in files: if not f[0] == '.': # Skip hidden files path = os.path.join(root, f) if self.verbosity >= 1: print ('Deleting old media file: %s' % path) os.remove(path) # Build compile queue queue = self._build_compile_queue(options['languages'], all_templates) # Precompile command execute_precompile_command() # Compile queue for i in range(0, len(queue)): lang = queue[i][0] with language(lang): if self.verbosity >= 2: print self.colored('%i / %i |' % (i+1, len(queue)), 'yellow'), print self.colored('(%s)' % lang, 'yellow'), print self.colored(queue[i][1], 'green') self._compile_template(*queue[i]) # Show all errors once again. print u'\n*** %i Files processed, %i compile errors ***' % (len(queue), len(self._errors)) # Build media compile queue media_queue = self._build_compile_media_queue(options['languages']) # Compile media queue self._errors = [] for i in range(0, len(media_queue)): lang = media_queue[i][0] with language(lang): if self.verbosity >= 2: print self.colored('%i / %i |' % (i+1, len(media_queue)), 'yellow'), print self.colored('(%s)' % lang, 'yellow'), print self.colored(','.join(media_queue[i][1]), 'green') self._compile_media(*media_queue[i]) # Show all errors once again. print u'\n*** %i Media files processed, %i compile errors ***' % (len(media_queue), len(self._errors)) # Ring bell :) print '\x07'
def real_handle(self, *args, **options): all_templates = options['all_templates'] single_template = options['single_template'] interactive = options['interactive'] self.insert_debug_symbols = options['insert_debug_symbols'] # Default verbosity self.verbosity = int(options.get('verbosity', 1)) # Colors? self.boring = bool(options.get('boring')) # All languages by default languages = [l[0] for l in settings.LANGUAGES] if options['languages'] is None: options['languages'] = languages self._errors = [] if languages.sort() != options['languages'].sort(): print self.colored( 'Warning: all template languages are deleted while we won\'t generate them again.', 'white', 'on_red') # Delete previously compiled templates and media files # (This is to be sure that no template loaders were configured to # load files from this cache.) if all_templates: if not interactive or raw_input( '\nDelete all files in template cache directory: %s? [y/N] ' % settings.TEMPLATE_CACHE_DIR).lower() in ('y', 'yes'): for root, dirs, files in os.walk(settings.TEMPLATE_CACHE_DIR): for f in files: if not f[0] == '.': # Skip hidden files path = os.path.join(root, f) if self.verbosity >= 1: print('Deleting old template: %s' % path) os.remove(path) if not interactive or raw_input( '\nDelete all files in media cache directory %s? [y/N] ' % settings.MEDIA_CACHE_DIR).lower() in ('y', 'yes'): for root, dirs, files in os.walk(settings.MEDIA_CACHE_DIR): for f in files: if not f[0] == '.': # Skip hidden files path = os.path.join(root, f) if self.verbosity >= 1: print('Deleting old media file: %s' % path) os.remove(path) # Build compile queue queue = self._build_compile_queue(options['languages'], all_templates, single_template) # Precompile command execute_precompile_command() # Compile queue for i in range(0, len(queue)): lang = queue[i][0] with language(lang): if self.verbosity >= 2: print self.colored('%i / %i |' % (i + 1, len(queue)), 'yellow'), print self.colored('(%s)' % lang, 'yellow'), print self.colored(queue[i][1], 'green') self._compile_template(*queue[i]) # Show all errors once again. print u'\n*** %i Files processed, %i compile errors ***' % ( len(queue), len(self._errors)) # Build media compile queue media_queue = self._build_compile_media_queue(options['languages']) # Compile media queue self._errors = [] for i in range(0, len(media_queue)): lang = media_queue[i][0] with language(lang): if self.verbosity >= 2: print self.colored('%i / %i |' % (i + 1, len(media_queue)), 'yellow'), print self.colored('(%s)' % lang, 'yellow'), print self.colored(','.join(media_queue[i][1]), 'green') self._compile_media(*media_queue[i]) # Show all errors once again. print u'\n*** %i Media files processed, %i compile errors ***' % ( len(media_queue), len(self._errors)) # Ring bell :) print '\x07'