Changeset 1299
- Timestamp:
- 11/20/05 09:38:14 (3 years ago)
- Files:
-
- django/branches/new-admin/django/contrib/admin/templates/admin/template_debug.html (deleted)
- django/branches/new-admin/django/core/template/defaultfilters.py (modified) (1 diff)
- django/branches/new-admin/django/core/template/__init__.py (modified) (1 diff)
- django/branches/new-admin/django/middleware/template_debug.py (deleted)
- django/branches/new-admin/django/views/debug.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/new-admin/django/core/template/defaultfilters.py
r1288 r1299 201 201 the argument. 202 202 """ 203 print "ds:", type(value)204 203 decorated = [(resolve_variable('var.' + arg, {'var' : item}), item) for item in value] 205 204 decorated.sort() django/branches/new-admin/django/core/template/__init__.py
r1244 r1299 826 826 e.source = node.source 827 827 raise 828 except Exception, e: 829 from traceback import extract_tb, format_list, format_exception_only 828 except Exception: 830 829 from sys import exc_info 831 t,v,tb = exc_info() 832 frames = extract_tb(tb) 833 frames.pop(0) 834 wrapped = TemplateSyntaxError( 'Caught exception:\n %s' 835 % "".join(format_exception_only(t,v)).replace('\n','')) 830 wrapped = TemplateSyntaxError( 'Caught exception whilst rendering' ) 836 831 wrapped.source = node.source 837 wrapped. traceback = "".join(format_list(frames))832 wrapped.exc_info = exc_info() 838 833 raise wrapped 839 834 return result django/branches/new-admin/django/views/debug.py
r1288 r1299 7 7 from django.core.template import Template, Context 8 8 from django.utils.httpwrappers import HttpResponseServerError, HttpResponseNotFound 9 from itertools import count, izip 10 from django.utils.html import escape 9 11 10 12 HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD') 13 14 def linebreak_iter(template_source): 15 import re 16 newline_re = re.compile("^", re.M) 17 for match in newline_re.finditer(template_source): 18 yield match.start() 19 yield len(template_source) + 1 20 21 def get_template_exception_info(exc_type,exc_value,tb): 22 origin, (start, end) = exc_value.source 23 template_source = origin.reload() 24 context_lines = 10 25 line = 0 26 upto = 0 27 source_lines = [] 28 linebreaks = izip(count(0), linebreak_iter(template_source)) 29 linebreaks.next() # skip the nothing before initial line start 30 for num, next in linebreaks: 31 if start >= upto and end <= next : 32 line = num 33 before = escape(template_source[upto:start]) 34 during = escape(template_source[start:end]) 35 after = escape(template_source[end:next - 1]) 36 37 source_lines.append( (num, escape(template_source[upto:next - 1])) ) 38 upto = next 39 40 total = len(source_lines) 41 42 top = max(0, line - context_lines) 43 bottom = min(total, line + 1 + context_lines) 44 45 template_info = { 46 'message' : exc_value.args[0], 47 'source_lines' : source_lines[top:bottom], 48 'before' : before, 49 'during': during, 50 'after': after, 51 'top': top , 52 'bottom': bottom , 53 'total' : total, 54 'line' : line, 55 'name' : origin.name, 56 } 57 exc_info = hasattr(exc_value, 'exc_info') and exc_value.exc_info or (exc_type,exc_value,tb) 58 return exc_info + (template_info,) 11 59 12 60 def technical_500_response(request, exc_type, exc_value, tb): … … 15 63 the values returned from sys.exc_info() and friends. 16 64 """ 65 template_info = None 66 if settings.TEMPLATE_DEBUG and hasattr(exc_value, 'source'): 67 exc_type, exc_value, tb, template_info = get_template_exception_info(exc_type,exc_value,tb) 17 68 frames = [] 18 69 while tb is not None: … … 54 105 'request_protocol' : os.environ.get("HTTPS") == "on" and "https" or "http", 55 106 'settings' : settings_dict, 56 107 'template_info': template_info, 57 108 }) 58 109 return HttpResponseServerError(t.render(c)) … … 145 196 #requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; } 146 197 #requestinfo h3 { margin-bottom:-1em; } 198 table.source td{ font-family: monospace; white-space: pre;} 199 span.specific{background:#ffcab7;} 200 .error { background:#ffc; } 147 201 </style> 148 202 <script type="text/javascript"> … … 222 276 </table> 223 277 </div> 224 278 {%if template_info %} 279 <div id="template"> 280 <h2>Template</h2> 281 In template {{template_info.name}}, error at line {{template_info.line}} 282 <div>{{template_info.message|escape}}</div> 283 <table class="source{%if template_info.top%} cut-top{%endif%}{%ifnotequal template_info.bottom template_info.total%} cut-bottom{%endifnotequal%}"> 284 {% for source_line in template_info.source_lines %} 285 {%ifequal source_line.0 template_info.line %} 286 <tr class="error"><td>{{source_line.0}}</td> 287 <td> {{template_info.before}}<span class="specific">{{template_info.during}}</span>{{template_info.after}}</td></tr> 288 {%else%} 289 <tr><td>{{source_line.0}}</td> 290 <td> {{source_line.1}}</td></tr> 291 {%endifequal%} 292 {%endfor%} 293 </table> 294 </div> 295 {%endif%} 225 296 <div id="traceback"> 226 297 <h2>Traceback <span>(innermost last)</span></h2>
