﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
4862	Unicode changes break admin popup windows	jdetaeye@…	Adrian Holovaty	"
My application has models with a string as primary key.
With the recent unicode changes this creates invalid javascript code for the popup windows. Because of the javascript error the popup window doesn't close any more.

Invalid code:
{{{
<tr class=""row2""><th><a href=""product/"" 
   onclick=""opener.dismissRelatedLookupPopup(window, u'product'); return false;"">product</a></th>
  <td>None</td><td>None</td><td>None</td><td>(None)</td><td>(None)</td><td class=""nowrap"">July 12, 2007, 5:48 p.m.</td></tr>
}}}
Notice the ""u'product'"" part. 

Digging a bit deeper I found the lines 193-195 of the file django/contrib/admin/templatetags/admin_list.py to be the culprit.
Original code:
{{{
   result_id = smart_unicode(getattr(result, pk)) # conversion to string is needed in case of 23L (long ints)
   yield (u'<%s%s><a href=""%s""%s>%s</a></%s>' % \
            (table_tag, row_class, url, (cl.is_popup and ' onclick=""opener.dismissRelatedLookupPopup(window, %r); return false;""' 
                % result_id or ''), result_repr, table_tag))
}}}
The revised code below fixes the problem in my case, but I am unsure whether this is a generic and complete fix:
{{{
   result_id = smart_unicode(getattr(result, pk)) # conversion to string is needed in case of 23L (long ints)
   yield (u'<%s%s><a href=""%s""%s>%s</a></%s>' % \
            (table_tag, row_class, url, (cl.is_popup and u' onclick=""opener.dismissRelatedLookupPopup(window, \'%s\'); return false;""' 
                % result_id or ''), result_repr, table_tag))
}}}

"		closed	contrib.admin	dev		fixed	unicode		Accepted	1	0	0	0	0	0
