Ticket #6117: admin_log.3.diff
File admin_log.3.diff, 5.5 KB (added by , 17 years ago) |
---|
-
django/newforms/models.py
327 327 def save_existing_objects(self, commit=True): 328 328 if not self.get_queryset(): 329 329 return [] 330 self.changed_objects = [] 331 self.deleted_objects = [] 330 332 # Put the objects from self.get_queryset into a dict so they are easy to lookup by pk 331 333 existing_objects = {} 332 334 for obj in self.get_queryset(): … … 335 337 for form in self.initial_forms: 336 338 obj = existing_objects[form.cleaned_data[self.model._meta.pk.attname]] 337 339 if self.can_delete and form.cleaned_data[DELETION_FIELD_NAME]: 340 self.deleted_objects.append(obj) 338 341 obj.delete() 339 342 else: 340 saved_instances.append(self.save_existing(form, obj, commit=commit)) 343 if form.changed_data: 344 self.changed_objects.append((obj, form.changed_data)) 345 saved_instances.append(self.save_existing(form, obj, commit=commit)) 341 346 return saved_instances 342 347 343 348 def save_new_objects(self, commit=True): 344 new_objects = []349 self.new_objects = [] 345 350 for form in self.extra_forms: 346 351 if not form.has_changed(): 347 352 continue … … 350 355 # the deletion widget for add forms. 351 356 if self.can_delete and form.cleaned_data[DELETION_FIELD_NAME]: 352 357 continue 353 new_objects.append(self.save_new(form, commit=commit))354 return new_objects358 self.new_objects.append(self.save_new(form, commit=commit)) 359 return self.new_objects 355 360 356 361 def add_fields(self, form, index): 357 362 """Add a hidden field for the object's primary key.""" -
django/newforms/forms.py
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 … … 257 258 #print field 258 259 return True 259 260 return False 261 262 def _get_changed_data(self): 263 if self._changed_data is None: 264 self._changed_data = [] 265 for name, field in self.fields.items(): 266 prefixed_name = self.add_prefix(name) 267 data_value = field.widget.value_from_datadict(self.data, self.files, prefixed_name) 268 initial_value = self.initial.get(name, field.initial) 269 if field.widget._has_changed(initial_value, data_value): 270 self._changed_data.append(name) 271 return self._changed_data 272 changed_data = property(_get_changed_data) 260 273 261 274 def _get_media(self): 262 275 """ -
django/contrib/admin/options.py
389 389 for formset in formsets: 390 390 formset.save() 391 391 392 # Construct the change message. TODO: Temporarily commented-out, 393 # as manipulator object doesn't exist anymore, and we don't yet 394 # have a way to get fields_added, fields_changed, fields_deleted. 392 # Construct the change message. 395 393 change_message = [] 396 #if manipulator.fields_added: 397 #change_message.append(_('Added %s.') % get_text_list(manipulator.fields_added, _('and'))) 398 #if manipulator.fields_changed: 399 #change_message.append(_('Changed %s.') % get_text_list(manipulator.fields_changed, _('and'))) 400 #if manipulator.fields_deleted: 401 #change_message.append(_('Deleted %s.') % get_text_list(manipulator.fields_deleted, _('and'))) 402 #change_message = ' '.join(change_message) 394 if form.changed_data: 395 change_message.append(_('Changed %s.') % get_text_list(form.changed_data, _('and'))) 396 397 if formsets: 398 for formset in formsets: 399 for added_object in formset.new_objects: 400 change_message.append(_('Added %s %s.') 401 % (added_object._meta.verbose_name, added_object)) 402 for changed_object, changed_fields in formset.changed_objects: 403 change_message.append(_('Changed %s for %s %s.') 404 % (get_text_list(changed_fields, _('and')), 405 changed_object._meta.verbose_name, 406 changed_object)) 407 for deleted_object in formset.deleted_objects: 408 change_message.append(_('Deleted %s %s.') 409 % (deleted_object._meta.verbose_name, deleted_object)) 410 411 change_message = ' '.join(change_message) 403 412 if not change_message: 404 413 change_message = _('No fields changed.') 405 414 LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, force_unicode(new_object), CHANGE, change_message)