def print_variables(self, context): """ Print a set of variables """ text = [] for name, expr in self.variables: # Some extended resolving, to handle unknown variables data = '' try: if isinstance(expr.var, Variable): data = expr.var.resolve(context) else: data = expr.resolve(context) # could return TEMPLATE_STRING_IF_INVALID except VariableDoesNotExist as e: # Failed to resolve, display exception inline keys = [] for scope in context: keys += scope.iterkeys() keys = sorted(set(keys)) # Remove duplicates, e.g. csrf_token return ERROR_TYPE_BLOCK.format(style=PRE_ALERT_STYLE, error=escape(u"Variable '{0}' not found! Available context variables are:\n\n{1}".format(expr, u', '.join(keys)))) else: # Regular format textdata = linebreaksbr(pformat_django_context_html(data)) # At top level, prefix class name if it's a longer result if isinstance(data, (bool,int,basestring,float, Promise)): text.append(BASIC_TYPE_BLOCK.format(style=PRE_STYLE, name=name, value=textdata)) else: text.append(OBJECT_TYPE_BLOCK.format(style=PRE_STYLE, name=name, type=data.__class__.__name__, value=textdata)) return u''.join(text)
def print_context(self, context): """ Print the entire template context """ text = [CONTEXT_TITLE] for i, context_scope in enumerate(context): dump1 = linebreaksbr(pformat_django_context_html(context_scope)) dump2 = pformat_dict_summary_html(context_scope) # Collapse long objects by default (e.g. request, LANGUAGES and sql_queries) if len(context_scope) <= 3 and dump1.count('<br />') > 20: (dump1, dump2) = (dump2, dump1) text.append( CONTEXT_BLOCK.format(style=PRE_STYLE, num=i, dump1=dump1, dump2=dump2)) return u''.join(text)
def print_variables(self, context): """ Print a set of variables """ text = [] for name, expr in self.variables: # Some extended resolving, to handle unknown variables data = '' try: if isinstance(expr.var, Variable): data = expr.var.resolve(context) else: data = expr.resolve( context) # could return TEMPLATE_STRING_IF_INVALID except VariableDoesNotExist as e: # Failed to resolve, display exception inline keys = [] for scope in context: keys += scope.keys() keys = sorted(set(keys)) # Remove duplicates, e.g. csrf_token return ERROR_TYPE_BLOCK.format( style=PRE_ALERT_STYLE, error=escape( u"Variable '{0}' not found! Available context variables are:\n\n{1}" .format(expr, u', '.join(keys)))) else: # Regular format textdata = linebreaksbr(pformat_django_context_html(data)) # At top level, prefix class name if it's a longer result if isinstance(data, SHORT_NAME_TYPES): text.append( BASIC_TYPE_BLOCK.format(style=PRE_STYLE, name=name, value=textdata)) else: text.append( OBJECT_TYPE_BLOCK.format(style=PRE_STYLE, name=name, type=data.__class__.__name__, value=textdata)) return u''.join(text)
def print_context(self, context): """ Print the entire template context """ text = [CONTEXT_TITLE] for i, context_scope in enumerate(context): dump1 = linebreaksbr(pformat_django_context_html(context_scope)) dump2 = pformat_dict_summary_html(context_scope) # Collapse long objects by default (e.g. request, LANGUAGES and sql_queries) if len(context_scope.keys()) <= 3 and dump1.count('<br />') > 20: (dump1, dump2) = (dump2, dump1) text.append(CONTEXT_BLOCK.format( style=PRE_STYLE, num=i, dump1=dump1, dump2=dump2 )) return u''.join(text)