Ticket #4786: views_debug_py.3.diff

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

Show bold filenames where file in INSTALLED_APPS

  • django/views/debug.py

     
    88from django.utils.html import escape
    99from django.http import HttpResponse, HttpResponseServerError, HttpResponseNotFound
    1010from django.utils.encoding import smart_unicode
     11from django.db.models.loading import get_apps
    1112
    1213HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD|PROFANITIES_LIST')
    1314
     
    186187        post_context = [line.strip('\n') for line in source[lineno+1:upper_bound]]
    187188
    188189        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
    189196
    190197    def get_traceback_frames(self):
    191198        frames = []
    192199        tb = self.tb
     200        app_module_paths = [os.path.normpath(os.path.dirname(mod.__file__))
     201                for mod in get_apps()
     202                if not mod.__name__.startswith('django.')]
     203       
    193204        while tb is not None:
    194205            # support for __traceback_hide__ which is used by a few libraries
    195206            # to hide internal frames.
     
    207218                    'tb': tb,
    208219                    'filename': filename,
    209220                    'function': function,
     221                    'app_code': self._is_installed_app_file(app_module_paths, filename),
    210222                    'lineno': lineno + 1,
    211223                    'vars': tb.tb_frame.f_locals.items(),
    212224                    'id': id(tb),
     
    313325    div.context ol.context-line li span { float: right; }
    314326    div.commands { margin-left: 40px; }
    315327    div.commands a { color:black; text-decoration:none; }
     328    code.app-code { font-weight: bold; }
    316329    #summary { background: #ffc; }
    317330    #summary h2 { font-weight: normal; color: #666; }
    318331    #explanation { background:#eee; }
     
    477490    <ul class="traceback">
    478491      {% for frame in frames %}
    479492        <li class="frame">
    480           <code>{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code>
     493          <code{% if frame.app_code %} class="app-code" {% endif %}>{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code>
    481494
    482495          {% if frame.context_line %}
    483496            <div class="context" id="c{{ frame.id }}">
Back to Top