def _store_template_info(self, sender, **kwargs): if not self.enabled: return template, context = kwargs['template'], kwargs['context'] # Skip templates that we are generating through the debug toolbar. if (isinstance(template.name, six.string_types) and template.name.startswith('debug_toolbar/')): return context_list = [] for context_layer in context.dicts: temp_layer = {} if hasattr(context_layer, 'items'): for key, value in context_layer.items(): # Replace any request elements - they have a large # unicode representation and the request data is # already made available from the Request Vars panel. if isinstance(value, http.HttpRequest): temp_layer[key] = '<<request>>' # Replace the debugging sql_queries element. The SQL # data is already made available from the SQL panel. elif key == 'sql_queries' and isinstance(value, list): temp_layer[key] = '<<sql_queries>>' # Replace LANGUAGES, which is available in i18n context processor elif key == 'LANGUAGES' and isinstance(value, tuple): temp_layer[key] = '<<languages>>' # QuerySet would trigger the database: user can run the query from SQL Panel elif isinstance(value, (QuerySet, RawQuerySet)): model_name = "%s.%s" % ( value.model._meta.app_label, value.model.__name__) temp_layer[key] = '<<%s of %s>>' % ( value.__class__.__name__.lower(), model_name) else: try: recording(False) pformat(value) # this MAY trigger a db query except SQLQueryTriggered: temp_layer[key] = '<<triggers database query>>' except UnicodeEncodeError: temp_layer[key] = '<<unicode encode error>>' except Exception: temp_layer[key] = '<<unhandled exception>>' else: temp_layer[key] = value finally: recording(True) try: context_list.append(pformat(temp_layer)) except UnicodeEncodeError: pass kwargs['context'] = [force_text(item) for item in context_list] self.templates.append(kwargs)
def _store_template_info(self, sender, **kwargs): t = kwargs['template'] if t.name and t.name.startswith('debug_toolbar/'): return # skip templates that we are generating through the debug toolbar. context_data = kwargs['context'] context_list = [] for context_layer in context_data.dicts: temp_layer = {} if hasattr(context_layer, 'items'): for key, value in context_layer.items(): # Replace any request elements - they have a large # unicode representation and the request data is # already made available from the Request Vars panel. if isinstance(value, http.HttpRequest): temp_layer[key] = '<<request>>' # Replace the debugging sql_queries element. The SQL # data is already made available from the SQL panel. elif key == 'sql_queries' and isinstance(value, list): temp_layer[key] = '<<sql_queries>>' # Replace LANGUAGES, which is available in i18n context processor elif key == 'LANGUAGES' and isinstance(value, tuple): temp_layer[key] = '<<languages>>' # QuerySet would trigger the database: user can run the query from SQL Panel elif isinstance(value, (QuerySet, RawQuerySet)): model_name = "%s.%s" % ( value.model._meta.app_label, value.model.__name__) temp_layer[key] = '<<%s of %s>>' % ( value.__class__.__name__.lower(), model_name) else: try: recording(False) pformat(value) # this MAY trigger a db query except SQLQueryTriggered: temp_layer[key] = '<<triggers database query>>' except UnicodeEncodeError: temp_layer[key] = '<<unicode encode error>>' except Exception: temp_layer[key] = '<<unhandled exception>>' else: temp_layer[key] = value finally: recording(True) try: context_list.append(pformat(temp_layer)) except UnicodeEncodeError: pass kwargs['context'] = [force_text(item) for item in context_list] self.templates.append(kwargs)
def _store_template_info(self, sender, **kwargs): t = kwargs['template'] if t.name and t.name.startswith('debug_toolbar/'): return # skip templates that we are generating through the debug toolbar. context_data = kwargs['context'] context_list = [] for context_layer in context_data.dicts: temp_layer = {} if hasattr(context_layer, 'items'): for key, value in context_layer.items(): # Replace any request elements - they have a large # unicode representation and the request data is # already made available from the Request Vars panel. if isinstance(value, http.HttpRequest): temp_layer[key] = '<<request>>' # Replace the debugging sql_queries element. The SQL # data is already made available from the SQL panel. elif key == 'sql_queries' and isinstance(value, list): temp_layer[key] = '<<sql_queries>>' # Replace LANGUAGES, which is available in i18n context processor elif key == 'LANGUAGES' and isinstance(value, tuple): temp_layer[key] = '<<languages>>' # QuerySet would trigger the database: user can run the query from SQL Panel elif isinstance(value, QuerySet): model_name = "%s.%s" % (value.model._meta.app_label, value.model.__name__) temp_layer[key] = '<<queryset of %s>>' % model_name else: try: recording(False) value="[KA Lite: Disabling pretty printing for efficiency]"#pformat(value) # this MAY trigger a db query except SQLQueryTriggered: temp_layer[key] = '<<triggers database query>>' except UnicodeEncodeError: temp_layer[key] = '<<unicode encode error>>' else: temp_layer[key] = value finally: recording(True) try: context_list.append(pformat(temp_layer)) except UnicodeEncodeError: pass kwargs['context'] = context_list self.templates.append(kwargs)
def _store_template_info(self, sender, **kwargs): t = kwargs.get('template') if t: name = t.name else: name = kwargs['filename'] if name and name.startswith('debug_toolbar/'): return # skip templates that we are generating through the debug toolbar. context_data = kwargs.get('context') if context_data is None: context_data = self.context else: self.context = context_data #context_data can be either a dict or a context data object context_list = [] context_data_dicts = [context_data or {}] if context_data and hasattr(context_data, 'dicts'): context_data_dicts = context_data.dicts for context_layer in context_data_dicts: temp_layer = {} if hasattr(context_layer, 'items'): for key, value in context_layer.items(): # Replace any request elements - they have a large # unicode representation and the request data is # already made available from the Request Vars panel. if isinstance(value, http.HttpRequest): temp_layer[key] = '<<request>>' # Replace the debugging sql_queries element. The SQL # data is already made available from the SQL panel. elif key == 'sql_queries' and isinstance(value, list): temp_layer[key] = '<<sql_queries>>' # Replace LANGUAGES, which is available in i18n context processor elif key == 'LANGUAGES' and isinstance(value, tuple): temp_layer[key] = '<<languages>>' # QuerySet would trigger the database: user can run the query from SQL Panel elif isinstance(value, QuerySet): model_name = "%s.%s" % (value.model._meta.app_label, value.model.__name__) temp_layer[key] = '<<queryset of %s>>' % model_name else: try: recording(False) pformat(value) # this MAY trigger a db query except SQLQueryTriggered: temp_layer[key] = '<<triggers database query>>' except UnicodeEncodeError: temp_layer[key] = ('UnicodeEncodeError when ' 'parsing %r. Type: %s' % (key, type(value))) else: temp_layer[key] = value finally: recording(True) try: context_list.append(pformat(temp_layer)) except UnicodeEncodeError: raise pass kwargs['context'] = context_list self.templates.append(kwargs)