Django

Code

Changeset 2444

Show
Ignore:
Timestamp:
02/28/06 09:52:57 (3 years ago)
Author:
adrian
Message:

Fixed #1420 -- Added copy-and-paste (pastebin-friendly) toggle for debug view. Thanks, jpaulofarias

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/views/debug.py

    r2420 r2444  
    256256      hideAll(getElementsByClassName(document, 'ol', 'pre-context')); 
    257257      hideAll(getElementsByClassName(document, 'ol', 'post-context')); 
     258      hideAll(getElementsByClassName(document, 'div', 'pastebin')); 
    258259    } 
    259260    function toggle() { 
     
    272273      var darr = String.fromCharCode(0x25bc); 
    273274      s.innerHTML = s.innerHTML == uarr ? darr : uarr; 
     275      return false; 
     276    } 
     277    function switchPastebinFriendly(link) { 
     278      s1 = "Switch to copy-and-paste view"; 
     279      s2 = "Switch back to interactive view"; 
     280      link.innerHTML = link.innerHTML == s1 ? s2 : s1; 
     281      toggle('browserTraceback', 'pastebinTraceback'); 
    274282      return false; 
    275283    } 
     
    342350<div id="traceback"> 
    343351  <h2>Traceback <span>(innermost last)</span></h2> 
    344   <ul class="traceback"> 
    345     {% for frame in frames %} 
    346       <li class="frame"> 
    347         <code>{{ frame.filename }}</code> in <code>{{ frame.function }}</code> 
    348  
    349         {% if frame.context_line %} 
    350           <div class="context" id="c{{ frame.id }}"> 
    351             {% if frame.pre_context %} 
    352               <ol start="{{ frame.pre_context_lineno|add:"1" }}" 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> 
    353             {% endif %} 
    354             <ol start="{{ frame.lineno|add:"1" }}" class="context-line"><li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ frame.context_line|escape }} <span>...</span></li></ol> 
    355             {% if frame.post_context %} 
    356               <ol start='{{ frame.lineno|add:"2" }}' 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> 
    357             {% endif %} 
    358           </div> 
    359         {% endif %} 
    360  
    361         {% if frame.vars %} 
    362           <div class="commands"> 
    363               <a href="#" onclick="return varToggle(this, '{{ frame.id }}')"><span>&#x25b6;</span> Local vars</a> 
    364           </div> 
    365           <table class="vars" id="v{{ frame.id }}"> 
    366             <thead> 
    367               <tr> 
    368                 <th>Variable</th> 
    369                 <th>Value</th> 
    370               </tr> 
    371             </thead> 
    372             <tbody> 
    373               {% for var in frame.vars|dictsort:"0" %} 
     352  <div class="commands"><a href="#" onclick="return switchPastebinFriendly(this);">Switch to copy-and-paste view</a></div> 
     353  <br/> 
     354  <div id="browserTraceback"> 
     355    <ul class="traceback"> 
     356      {% for frame in frames %} 
     357        <li class="frame"> 
     358          <code>{{ frame.filename }}</code> in <code>{{ frame.function }}</code> 
     359 
     360          {% if frame.context_line %} 
     361            <div class="context" id="c{{ frame.id }}"> 
     362              {% if frame.pre_context %} 
     363                <ol start="{{ frame.pre_context_lineno|add:"1" }}" 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> 
     364              {% endif %} 
     365              <ol start="{{ frame.lineno|add:"1" }}" class="context-line"><li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')">{{ frame.context_line|escape }} <span>...</span></li></ol> 
     366              {% if frame.post_context %} 
     367                <ol start='{{ frame.lineno|add:"2" }}' 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> 
     368              {% endif %} 
     369            </div> 
     370          {% endif %} 
     371 
     372          {% if frame.vars %} 
     373            <div class="commands"> 
     374                <a href="#" onclick="return varToggle(this, '{{ frame.id }}')"><span>&#x25b6;</span> Local vars</a> 
     375            </div> 
     376            <table class="vars" id="v{{ frame.id }}"> 
     377              <thead> 
    374378                <tr> 
    375                   <td>{{ var.0 }}</td
    376                   <td class="code"><div>{{ var.1|pprint|escape }}</div></td
     379                  <th>Variable</th
     380                  <th>Value</th
    377381                </tr> 
    378               {% endfor %} 
    379             </tbody> 
    380           </table> 
    381         {% endif %} 
    382       </li> 
    383     {% endfor %} 
    384   </ul> 
     382              </thead> 
     383              <tbody> 
     384                {% for var in frame.vars|dictsort:"0" %} 
     385                  <tr> 
     386                    <td>{{ var.0 }}</td> 
     387                    <td class="code"><div>{{ var.1|pprint|escape }}</div></td> 
     388                  </tr> 
     389                {% endfor %} 
     390              </tbody> 
     391            </table> 
     392          {% endif %} 
     393        </li> 
     394      {% endfor %} 
     395    </ul> 
     396  </div> 
     397  <div id="pastebinTraceback" class="pastebin"> 
     398    <table> 
     399      <tbody> 
     400        <tr> 
     401          <td> 
     402            <code> 
     403Traceback (most recent call last):<br/> 
     404{% for frame in frames %} 
     405  File "{{ frame.filename }}" in {{ frame.function }}<br/> 
     406  {% if frame.context_line %} 
     407    &nbsp;&nbsp;{{ frame.lineno|add:"1" }}. {{ frame.context_line|escape }}<br/> 
     408  {% endif %} 
     409{% endfor %}<br/> 
     410&nbsp;&nbsp;{{ exception_type }} at {{ request.path }}<br/> 
     411&nbsp;&nbsp;{{ exception_value|escape }}</code> 
     412          </td> 
     413        </tr> 
     414      </tbody> 
     415    </table> 
     416  </div> 
    385417</div> 
    386418