Ticket #4786: views_debug_py.4.diff
File views_debug_py.4.diff, 3.7 KB (added by , 16 years ago) |
---|
-
django/views/debug.py
8 8 from django.utils.html import escape 9 9 from django.http import HttpResponse, HttpResponseServerError, HttpResponseNotFound 10 10 from django.utils.encoding import smart_unicode, smart_str 11 from django.db.models.loading import get_apps 11 12 12 13 HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD|PROFANITIES_LIST') 13 14 … … 186 187 post_context = [line.strip('\n') for line in source[lineno+1:upper_bound]] 187 188 188 189 return lower_bound, pre_context, context_line, post_context 190 191 def _is_installed_app_file(self, app_module_paths, filename): 192 for path in app_module_paths: 193 if filename.startswith(path): 194 return True 195 return False 189 196 190 197 def get_traceback_frames(self): 191 198 frames = [] 192 199 tb = self.tb 200 app_module_paths=[] 201 for mod in get_apps(): 202 if mod.__name__.startswith('django.'): 203 continue 204 dirname=os.path.dirname(os.path.normpath(mod.__file__)) 205 if os.path.basename(dirname)=='models': 206 # models directory instead of app/models.py 207 dirname=os.path.dirname(dirname) 208 app_module_paths.append(dirname) 209 193 210 while tb is not None: 194 211 # support for __traceback_hide__ which is used by a few libraries 195 212 # to hide internal frames. … … 207 224 'tb': tb, 208 225 'filename': filename, 209 226 'function': function, 227 'app_code': self._is_installed_app_file(app_module_paths, filename), 210 228 'lineno': lineno + 1, 211 229 'vars': tb.tb_frame.f_locals.items(), 212 230 'id': id(tb), … … 313 331 div.context ol.context-line li span { float: right; } 314 332 div.commands { margin-left: 40px; } 315 333 div.commands a { color:black; text-decoration:none; } 334 .app-code { font-weight: bold; } 316 335 #summary { background: #ffc; } 317 336 #summary h2 { font-weight: normal; color: #666; } 318 337 #explanation { background:#eee; } … … 477 496 <ul class="traceback"> 478 497 {% for frame in frames %} 479 498 <li class="frame"> 480 <code >{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code>499 <code{% if frame.app_code %} class="app-code" {% endif %}>{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code> 481 500 482 501 {% if frame.context_line %} 483 502 <div class="context" id="c{{ frame.id }}"> 484 503 {% if frame.pre_context %} 485 504 <ol start="{{ frame.pre_context_lineno }}" class="pre-context" id="pre{{ frame.id }}">{% for line in frame.pre_context %}<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ line|escape }}</li>{% endfor %}</ol> 486 505 {% endif %} 487 <ol start="{{ frame.lineno }}" class="context-line "><li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ frame.context_line|escape }} <span>...</span></li></ol>506 <ol start="{{ frame.lineno }}" class="context-line {% if frame.app_code %} app-code {% endif %}"><li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ frame.context_line|escape }} <span>...</span></li></ol> 488 507 {% if frame.post_context %} 489 508 <ol start='{{ frame.lineno|add:"1" }}' class="post-context" id="post{{ frame.id }}">{% for line in frame.post_context %}<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ line|escape }}</li>{% endfor %}</ol> 490 509 {% endif %}