diff --git a/django/contrib/admin/tests/widgets.py b/django/contrib/admin/tests/widgets.py
index 0b20441..55d845c 100644
a
|
b
|
WIDGET_TESTS = """
|
7 | 7 | >>> from django.contrib.admin.widgets import AdminFileWidget, ForeignKeyRawIdWidget |
8 | 8 | >>> from django.contrib.admin.widgets import RelatedFieldWidgetWrapper |
9 | 9 | >>> from django.contrib.admin.models import LogEntry |
| 10 | >>> from django.contrib.auth.models import User |
10 | 11 | |
11 | 12 | Calling conditional_escape on the output of widget.render will simulate what |
12 | 13 | happens in the template. This is easier than setting up a template and context |
… |
… |
HTML escaped.
|
29 | 30 | >>> print conditional_escape(w.render('test', 'test')) |
30 | 31 | Currently: <a target="_blank" href="%(MEDIA_URL)stest">test</a> <br>Change: <input type="file" name="test" /> |
31 | 32 | |
| 33 | >>> entry = LogEntry(action_flag=1) |
| 34 | >>> entry.user = User.objects.create_user("jdoe", "jdoe@example.com") |
| 35 | >>> entry.save() |
32 | 36 | >>> rel = LogEntry._meta.get_field('user').rel |
33 | 37 | >>> w = ForeignKeyRawIdWidget(rel) |
34 | | >>> print conditional_escape(w.render('test', 'test', attrs={})) |
35 | | <input type="text" name="test" value="test" class="vForeignKeyRawIdAdminField" /><a href="../../../auth/user/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a> |
| 38 | >>> print conditional_escape(w.render('test', entry.user.pk, attrs={})) |
| 39 | <input type="text" name="test" value="..." class="vForeignKeyRawIdAdminField" /><a href="../../../auth/user/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a> <strong>jdoe</strong> |
36 | 40 | |
37 | 41 | """ % { |
38 | 42 | 'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX, |
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index 26aacf7..f5c14e6 100644
a
|
b
|
Form Widget classes specific to the Django admin site.
|
4 | 4 | |
5 | 5 | from django import newforms as forms |
6 | 6 | from django.utils.datastructures import MultiValueDict |
7 | | from django.utils.text import capfirst |
| 7 | from django.utils.text import capfirst, truncate_words |
8 | 8 | from django.utils.translation import ugettext as _ |
9 | 9 | from django.utils.safestring import mark_safe |
10 | 10 | from django.conf import settings |
… |
… |
class ForeignKeyRawIdWidget(forms.TextInput):
|
100 | 100 | output.append('<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> ' % \ |
101 | 101 | (related_url, url, name)) |
102 | 102 | output.append('<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a>' % settings.ADMIN_MEDIA_PREFIX) |
| 103 | if value: |
| 104 | output.append(' <strong>%s</strong>' % \ |
| 105 | truncate_words(self.rel.to.objects.get(pk=value), 14)) |
103 | 106 | return mark_safe(u''.join(output)) |
104 | | #if self.change: # TODO |
105 | | #output.append(' <strong>TODO</strong>') |
106 | 107 | |
107 | 108 | class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): |
108 | 109 | """ |