1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

newforms-admin: Applied the same _has_changed treatment to the ManyToManyRawIdWidget from [7515] since it acts similar with the underlying data.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7516 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Brian Rosner 2008-05-05 17:31:23 +00:00
parent 6b6778ac46
commit be31882eee
2 changed files with 25 additions and 0 deletions

View File

@ -7,6 +7,7 @@ from django.utils.datastructures import MultiValueDict
from django.utils.text import capfirst, truncate_words from django.utils.text import capfirst, truncate_words
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode
from django.conf import settings from django.conf import settings
class FilteredSelectMultiple(forms.SelectMultiple): class FilteredSelectMultiple(forms.SelectMultiple):
@ -136,6 +137,18 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
return [value] return [value]
return None return None
def _has_changed(self, initial, data):
if initial is None:
initial = []
if data is None:
data = []
if len(initial) != len(data):
return True
for pk1, pk2 in zip(initial, data):
if force_unicode(pk1) != force_unicode(pk2):
return True
return False
class RelatedFieldWidgetWrapper(object): class RelatedFieldWidgetWrapper(object):
""" """
This class is a wrapper whose __call__() method mimics the interface of a This class is a wrapper whose __call__() method mimics the interface of a

View File

@ -66,6 +66,18 @@ Currently: <a target="_blank" href="%(MEDIA_URL)stest">test</a> <br />Change: <i
>>> w = ManyToManyRawIdWidget(rel) >>> w = ManyToManyRawIdWidget(rel)
>>> print conditional_escape(w.render('test', [m1.pk, m2.pk], attrs={})) >>> print conditional_escape(w.render('test', [m1.pk, m2.pk], attrs={}))
<input type="text" name="test" value="1,2" class="vManyToManyRawIdAdminField" /><a href="../../../admin_widgets/member/" 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> <input type="text" name="test" value="1,2" class="vManyToManyRawIdAdminField" /><a href="../../../admin_widgets/member/" 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>
>>> w._has_changed(None, None)
False
>>> w._has_changed([], None)
False
>>> w._has_changed(None, [u'1'])
True
>>> w._has_changed([1, 2], [u'1', u'2'])
False
>>> w._has_changed([1, 2], [u'1'])
True
>>> w._has_changed([1, 2], [u'1', u'3'])
True
""" % { """ % {
'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX, 'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,