Ticket #6117: 6117.diff
File 6117.diff, 9.0 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/options.py
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index d0cca0a..d6ee1ee 100644
a b class ModelAdmin(BaseModelAdmin): 385 385 for formset in formsets: 386 386 formset.save() 387 387 388 # Construct the change message. TODO: Temporarily commented-out, 389 # as manipulator object doesn't exist anymore, and we don't yet 390 # have a way to get fields_added, fields_changed, fields_deleted. 388 # Construct the change message. 391 389 change_message = [] 392 #if manipulator.fields_added: 393 #change_message.append(_('Added %s.') % get_text_list(manipulator.fields_added, _('and'))) 394 #if manipulator.fields_changed: 395 #change_message.append(_('Changed %s.') % get_text_list(manipulator.fields_changed, _('and'))) 396 #if manipulator.fields_deleted: 397 #change_message.append(_('Deleted %s.') % get_text_list(manipulator.fields_deleted, _('and'))) 398 #change_message = ' '.join(change_message) 390 if form.changed_data: 391 change_message.append(_('Changed %s.') % get_text_list(form.changed_data, _('and'))) 392 393 if formsets: 394 for formset in formsets: 395 for added_object in formset.new_objects: 396 change_message.append(_('Added %s "%s".') 397 % (added_object._meta.verbose_name, added_object)) 398 for changed_object, changed_fields in formset.changed_objects: 399 change_message.append(_('Changed %s for %s "%s".') 400 % (get_text_list(changed_fields, _('and')), 401 changed_object._meta.verbose_name, 402 changed_object)) 403 for deleted_object in formset.deleted_objects: 404 change_message.append(_('Deleted %s "%s".') 405 % (deleted_object._meta.verbose_name, deleted_object)) 406 407 change_message = ' '.join(change_message) 399 408 if not change_message: 400 409 change_message = _('No fields changed.') 401 410 LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, force_unicode(new_object), CHANGE, change_message) -
django/newforms/forms.py
diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 42dacec..4c4c0e0 100644
a b class BaseForm(StrAndUnicode): 81 81 self.label_suffix = label_suffix 82 82 self.empty_permitted = empty_permitted 83 83 self._errors = None # Stores the errors after clean() has been called. 84 self._changed_data = None 84 85 85 86 # The base_fields class attribute is the *class-wide* definition of 86 87 # fields. Because a particular *instance* of the class might want to … … class BaseForm(StrAndUnicode): 256 257 if field.widget._has_changed(initial_value, data_value): 257 258 return True 258 259 return False 260 261 def _get_changed_data(self): 262 if self._changed_data is None: 263 self._changed_data = [] 264 for name, field in self.fields.items(): 265 prefixed_name = self.add_prefix(name) 266 data_value = field.widget.value_from_datadict(self.data, self.files, prefixed_name) 267 initial_value = self.initial.get(name, field.initial) 268 if field.widget._has_changed(initial_value, data_value): 269 self._changed_data.append(name) 270 return self._changed_data 271 changed_data = property(_get_changed_data) 259 272 260 273 def _get_media(self): 261 274 """ -
django/newforms/models.py
diff --git a/django/newforms/models.py b/django/newforms/models.py index f12b53d..b1332a7 100644
a b class BaseModelFormSet(BaseFormSet): 328 328 return self.save_existing_objects(commit) + self.save_new_objects(commit) 329 329 330 330 def save_existing_objects(self, commit=True): 331 self.changed_objects = [] 332 self.deleted_objects = [] 331 333 if not self.get_queryset(): 332 334 return [] 335 333 336 # Put the objects from self.get_queryset into a dict so they are easy to lookup by pk 334 337 existing_objects = {} 335 338 for obj in self.get_queryset(): … … class BaseModelFormSet(BaseFormSet): 338 341 for form in self.initial_forms: 339 342 obj = existing_objects[form.cleaned_data[self.model._meta.pk.attname]] 340 343 if self.can_delete and form.cleaned_data[DELETION_FIELD_NAME]: 344 self.deleted_objects.append(obj) 341 345 obj.delete() 342 346 else: 343 saved_instances.append(self.save_existing(form, obj, commit=commit)) 347 if form.changed_data: 348 self.changed_objects.append((obj, form.changed_data)) 349 saved_instances.append(self.save_existing(form, obj, commit=commit)) 344 350 return saved_instances 345 351 346 352 def save_new_objects(self, commit=True): 347 new_objects = []353 self.new_objects = [] 348 354 for form in self.extra_forms: 349 355 if not form.has_changed(): 350 356 continue … … class BaseModelFormSet(BaseFormSet): 353 359 # the deletion widget for add forms. 354 360 if self.can_delete and form.cleaned_data[DELETION_FIELD_NAME]: 355 361 continue 356 new_objects.append(self.save_new(form, commit=commit))357 return new_objects362 self.new_objects.append(self.save_new(form, commit=commit)) 363 return self.new_objects 358 364 359 365 def add_fields(self, form, index): 360 366 """Add a hidden field for the object's primary key.""" -
tests/modeltests/model_formsets/models.py
diff --git a/tests/modeltests/model_formsets/models.py b/tests/modeltests/model_formsets/models.py index 386cd04..e6ee82e 100644
a b but in that case we'll use it to display them in alphabetical order by name. 80 80 True 81 81 82 82 >>> formset.save() 83 [<Author: Arthur Rimbaud>, <Author: Charles Baudelaire>, <Author:Paul Verlaine>]83 [<Author: Paul Verlaine>] 84 84 85 85 >>> for author in Author.objects.order_by('name'): 86 86 ... print author.name … … deltetion, make sure we don't save that form. 125 125 True 126 126 127 127 >>> formset.save() 128 [ <Author: Arthur Rimbaud>, <Author: Charles Baudelaire>, <Author: Paul Verlaine>]128 [] 129 129 130 130 >>> for author in Author.objects.order_by('name'): 131 131 ... print author.name … … book. 199 199 True 200 200 201 201 >>> formset.save() 202 [<Book: Le s Fleurs du Mal>, <Book: LeSpleen de Paris>]202 [<Book: Le Spleen de Paris>] 203 203 204 204 As you can see, 'Le Spleen de Paris' is now a book belonging to Charles Baudelaire. 205 205 -
tests/regressiontests/forms/forms.py
diff --git a/tests/regressiontests/forms/forms.py b/tests/regressiontests/forms/forms.py index a865e91..96c871e 100644
a b initial that returns False on a boolean call needs to be treated literally. 1738 1738 >>> form.is_valid() 1739 1739 True 1740 1740 1741 >>> from django import newforms as forms 1742 >>> class Person(forms.Form): 1743 ... first_name = forms.CharField() 1744 ... last_name = forms.CharField() 1745 ... age = forms.IntegerField() 1746 ... happy = forms.BooleanField() 1747 ... resume = forms.FileField() 1748 1749 >>> p = Person() 1750 >>> p.changed_data 1751 [] 1752 1753 >>> p = Person({'first_name': 'John'}) 1754 >>> p.changed_data 1755 ['first_name'] 1756 1757 >>> p = Person({'first_name': 'John', 'last_name': 'Boothe'}) 1758 >>> p.changed_data 1759 ['first_name', 'last_name'] 1760 1761 >>> p = Person({'first_name': 'John', 'last_name': 'Boothe'}, initial={'last_name': 'Boothe'}) 1762 >>> p.changed_data 1763 ['first_name'] 1764 1765 >>> p = Person({'age': '20'}, initial={'age': 20}) 1766 >>> p.changed_data 1767 [] 1768 1769 >>> p = Person({'happy': True}, initial={'happy': False}) 1770 >>> p.changed_data 1771 ['happy'] 1772 1773 >>> p = Person({'happy': 1}, initial={'happy': True}) 1774 >>> p.changed_data 1775 [] 1776 1777 >>> p = Person({'happy': '1'}, initial={'happy': True}) 1778 >>> p.changed_data 1779 [] 1741 1780 """ -
tests/regressiontests/forms/widgets.py
diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py index 0e69602..849224d 100644
a b u'<input type="text" name="date" value="2007-09-17 12:51:34" />' 929 929 u'<input type="text" name="date" value="2007-09-17 12:51:34" />' 930 930 >>> w.render('date', datetime.datetime(2007, 9, 17, 12, 51)) 931 931 u'<input type="text" name="date" value="2007-09-17 12:51:00" />' 932 933 >>> from django import newforms as forms 934 >>> w = forms.TextInput() 935 >>> w._has_changed('John', 'John') 936 False 937 938 >>> w._has_changed('John', '') 939 True 940 941 >>> w._has_changed('', 'John') 942 True 943 944 >>> w._has_changed('', '') 945 False 946 947 # This test is for Integer Fields, which uses the TextInput for a widget. 948 >>> w._has_changed(20, '20') 949 False 950 951 >>> w = forms.CheckboxInput() 952 >>> w._has_changed(True, '1') 953 False 954 955 >>> w._has_changed(True, '0') 956 False 957 958 >>> w._has_changed(True, 0) 959 True 960 932 961 """