Django

Code

Changeset 7516

Show
Ignore:
Timestamp:
05/05/08 12:31:23 (6 days ago)
Author:
brosner
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin/django/contrib/admin/widgets.py

    r7262 r7516  
    88from django.utils.translation import ugettext as _ 
    99from django.utils.safestring import mark_safe 
     10from django.utils.encoding import force_unicode 
    1011from django.conf import settings 
    1112 
     
    136137            return [value] 
    137138        return None 
     139     
     140    def _has_changed(self, initial, data): 
     141        if initial is None: 
     142            initial = [] 
     143        if data is None: 
     144            data = [] 
     145        if len(initial) != len(data): 
     146            return True 
     147        for pk1, pk2 in zip(initial, data): 
     148            if force_unicode(pk1) != force_unicode(pk2): 
     149                return True 
     150        return False 
    138151 
    139152class RelatedFieldWidgetWrapper(object): 
  • django/branches/newforms-admin/tests/regressiontests/admin_widgets/models.py

    r7262 r7516  
    6767>>> print conditional_escape(w.render('test', [m1.pk, m2.pk], attrs={})) 
    6868<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> 
     69>>> w._has_changed(None, None) 
     70False 
     71>>> w._has_changed([], None) 
     72False 
     73>>> w._has_changed(None, [u'1']) 
     74True 
     75>>> w._has_changed([1, 2], [u'1', u'2']) 
     76False 
     77>>> w._has_changed([1, 2], [u'1']) 
     78True 
     79>>> w._has_changed([1, 2], [u'1', u'3']) 
     80True 
    6981 
    7082""" % {