Ticket #6117: admin_log.4.diff

File admin_log.4.diff, 5.6 KB (added by Karen Tracey <kmtracey@…>, 17 years ago)

Fix error when adding 1st inline object, include quotes around object values like old code did (noticed during investigation of #6853)

  • django/newforms/models.py

     
    325325        return self.save_existing_objects(commit) + self.save_new_objects(commit)
    326326
    327327    def save_existing_objects(self, commit=True):
     328        self.changed_objects = []
     329        self.deleted_objects = []
    328330        if not self.get_queryset():
    329331            return []
     332
    330333        # Put the objects from self.get_queryset into a dict so they are easy to lookup by pk
    331334        existing_objects = {}
    332335        for obj in self.get_queryset():
     
    335338        for form in self.initial_forms:
    336339            obj = existing_objects[form.cleaned_data[self.model._meta.pk.attname]]
    337340            if self.can_delete and form.cleaned_data[DELETION_FIELD_NAME]:
     341                self.deleted_objects.append(obj)
    338342                obj.delete()
    339343            else:
    340                 saved_instances.append(self.save_existing(form, obj, commit=commit))
     344                if form.changed_data:
     345                    self.changed_objects.append((obj, form.changed_data))
     346                    saved_instances.append(self.save_existing(form, obj, commit=commit))
    341347        return saved_instances
    342348
    343349    def save_new_objects(self, commit=True):
    344         new_objects = []
     350        self.new_objects = []
    345351        for form in self.extra_forms:
    346352            if not form.has_changed():
    347353                continue
     
    350356            # the deletion widget for add forms.
    351357            if self.can_delete and form.cleaned_data[DELETION_FIELD_NAME]:
    352358                continue
    353             new_objects.append(self.save_new(form, commit=commit))
    354         return new_objects
     359            self.new_objects.append(self.save_new(form, commit=commit))
     360        return self.new_objects
    355361
    356362    def add_fields(self, form, index):
    357363        """Add a hidden field for the object's primary key."""
  • django/newforms/forms.py

     
    8181        self.label_suffix = label_suffix
    8282        self.empty_permitted = empty_permitted
    8383        self._errors = None # Stores the errors after clean() has been called.
     84        self._changed_data = None
    8485
    8586        # The base_fields class attribute is the *class-wide* definition of
    8687        # fields. Because a particular *instance* of the class might want to
     
    257258                #print field
    258259                return True
    259260        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)
    260273
    261274    def _get_media(self):
    262275        """
  • django/contrib/admin/options.py

     
    389389            for formset in formsets:
    390390                formset.save()
    391391
    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.                 
    395393        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)
    403412        if not change_message:
    404413            change_message = _('No fields changed.')
    405414        LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, force_unicode(new_object), CHANGE, change_message)
Back to Top