Code

Ticket #4786: views_debug_py.3.diff

File views_debug_py.3.diff, 2.4 KB (added by kevin, 6 years ago)

Show bold filenames where file in INSTALLED_APPS

Line 
1Index: django/views/debug.py
2===================================================================
3--- django/views/debug.py       (revision 8471)
4+++ django/views/debug.py       (working copy)
5@@ -8,6 +8,7 @@
6 from django.utils.html import escape
7 from django.http import HttpResponse, HttpResponseServerError, HttpResponseNotFound
8 from django.utils.encoding import smart_unicode
9+from django.db.models.loading import get_apps
10 
11 HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD|PROFANITIES_LIST')
12 
13@@ -186,10 +187,20 @@
14         post_context = [line.strip('\n') for line in source[lineno+1:upper_bound]]
15 
16         return lower_bound, pre_context, context_line, post_context
17+       
18+    def _is_installed_app_file(self, app_module_paths, filename):
19+        for path in app_module_paths:
20+            if filename.startswith(path):
21+                return True
22+        return False
23 
24     def get_traceback_frames(self):
25         frames = []
26         tb = self.tb
27+        app_module_paths = [os.path.normpath(os.path.dirname(mod.__file__))
28+                for mod in get_apps()
29+                if not mod.__name__.startswith('django.')]
30+       
31         while tb is not None:
32             # support for __traceback_hide__ which is used by a few libraries
33             # to hide internal frames.
34@@ -207,6 +218,7 @@
35                     'tb': tb,
36                     'filename': filename,
37                     'function': function,
38+                    'app_code': self._is_installed_app_file(app_module_paths, filename),
39                     'lineno': lineno + 1,
40                     'vars': tb.tb_frame.f_locals.items(),
41                     'id': id(tb),
42@@ -313,6 +325,7 @@
43     div.context ol.context-line li span { float: right; }
44     div.commands { margin-left: 40px; }
45     div.commands a { color:black; text-decoration:none; }
46+    code.app-code { font-weight: bold; }
47     #summary { background: #ffc; }
48     #summary h2 { font-weight: normal; color: #666; }
49     #explanation { background:#eee; }
50@@ -477,7 +490,7 @@
51     <ul class="traceback">
52       {% for frame in frames %}
53         <li class="frame">
54-          <code>{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code>
55+          <code{% if frame.app_code %} class="app-code" {% endif %}>{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code>
56 
57           {% if frame.context_line %}
58             <div class="context" id="c{{ frame.id }}">