Author: adrian
Date: 2007-08-11 22:23:53 -0500 (Sat, 11 Aug 2007)
New Revision: 5862

Modified:
   django/trunk/django/views/debug.py
Log:
Fixed #5046 -- Added 'Unicode error hint' section to debug page in the case of 
a UnicodeError. Thanks, Thomas Guttler

Modified: django/trunk/django/views/debug.py
===================================================================
--- django/trunk/django/views/debug.py  2007-08-12 03:07:34 UTC (rev 5861)
+++ django/trunk/django/views/debug.py  2007-08-12 03:23:53 UTC (rev 5862)
@@ -123,10 +123,20 @@
             'function': '?',
             'lineno': '?',
         }]
+
+    unicode_hint = ''
+    if issubclass(exc_type, UnicodeError):
+        start = getattr(exc_value, 'start', None)
+        end = getattr(exc_value, 'end', None)
+        if start is not None and end is not None:
+            unicode_str = exc_value.args[1]
+            unicode_hint = smart_unicode(unicode_str[max(start-5, 
0):min(end+5, len(unicode_str))], 'ascii', errors='replace')
+
     t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template')
     c = Context({
         'exception_type': exc_type.__name__,
         'exception_value': smart_unicode(exc_value, errors='replace'),
+        'unicode_hint': unicode_hint,
         'frames': frames,
         'lastframe': frames[-1],
         'request': request,
@@ -258,6 +268,7 @@
     #explanation { background:#eee; }
     #template, #template-not-exist { background:#f6f6f6; }
     #template-not-exist ul { margin: 0 0 0 20px; }
+    #unicode-hint { background:#eee; }
     #traceback { background:#eee; }
     #requestinfo { background:#f6f6f6; padding-left:120px; }
     #summary table { border:none; background:transparent; }
@@ -358,6 +369,12 @@
     </tr>
   </table>
 </div>
+{% if unicode_hint %}
+<div id="unicode-hint">
+    <h2>Unicode error hint</h2>
+    <p>The string that could not be encoded/decoded was: <strong>{{ 
unicode_hint|escape }}</strong></p>
+</div>
+{% endif %}
 {% if template_does_not_exist %}
 <div id="template-not-exist">
     <h2>Template-loader postmortem</h2>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to