Django

Code

Ticket #6117 (closed: fixed)

Opened 8 months ago

Last modified 3 months ago

newforms-admin change history needs to be implemented

Reported by: Karen Tracey <kmtracey@gmail.com> Assigned to: brosner
Milestone: Component: Admin interface
Version: newforms-admin Keywords: change history nfa-blocker
Cc: hv@tbz-pariv.de Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

Description

This code in newforms-admin/django/contrib/admin/options.py save_change needs to be replaced with a real implementation:

        # Construct the change message. TODO: Temporarily commented-out,
        # as manipulator object doesn't exist anymore, and we don't yet
        # have a way to get fields_added, fields_changed, fields_deleted.
        change_message = []
        #if manipulator.fields_added:
            #change_message.append(_('Added %s.') % get_text_list(manipulator.fields_added, _('and')))
        #if manipulator.fields_changed:
            #change_message.append(_('Changed %s.') % get_text_list(manipulator.fields_changed, _('and')))
        #if manipulator.fields_deleted:
            #change_message.append(_('Deleted %s.') % get_text_list(manipulator.fields_deleted, _('and')))
        #change_message = ' '.join(change_message)
        if not change_message:
            change_message = _('No fields changed.')
        LogEntry.objects.log_action(request.user.id, ContentType.objects.get_for_model(model).id, pk_value, force_unicode(new_object), CHANGE, change_message)

Until then all the history for changes made using newforms-admin displays "No fields changed."

Attachments

admin_log.diff (2.6 kB) - added by Alex on 03/17/08 16:34:06.
This should work, brosner has said this should probably be in modelforms, I'm not familliar enough to work on those, however someone can use this work.
admin_log.2.diff (2.6 kB) - added by Alex on 03/17/08 16:48:05.
Made it a bit more efficient
admin_log.3.diff (5.5 kB) - added by Karen Tracey <kmtracey@gmail.com> on 03/19/08 15:18:51.
admin_log.4.diff (5.6 kB) - added by Karen Tracey <kmtracey@gmail.com> on 03/24/08 11:32:19.
Fix error when adding 1st inline object, include quotes around object values like old code did (noticed during investigation of #6853)
admin_changed.diff (8.5 kB) - added by Alex on 04/04/08 15:57:01.
Added some tests, there may be some test failures, I can't tell right now
admin_changed.2.diff (8.0 kB) - added by Alex on 04/04/08 15:57:45.
Added some tests, there may be some test failures, I can't tell right now
6117.diff (9.0 kB) - added by Alex on 04/06/08 15:34:02.
This fixes the test failures from the previous patch

Change History

12/04/07 14:07:06 changed by Karen Tracey <kmtracey@gmail.com>

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

12/07/07 18:08:00 changed by brosner

  • keywords changed from change history to change history nfa-blocker.
  • stage changed from Unreviewed to Accepted.

This should be completed before merging since it will completely break the compatibility with the trunk admin.

02/28/08 03:23:30 changed by guettli

  • cc set to hv@tbz-pariv.de.

FYI:

I wrote a small method (form_changed()) which compares the initial values of a form with cleaned_data. It returns True if the form was changed.

http://www.djangosnippets.org/snippets/621/

May something like this can be used to implement the change history.

03/17/08 16:34:06 changed by Alex

  • attachment admin_log.diff added.

This should work, brosner has said this should probably be in modelforms, I'm not familliar enough to work on those, however someone can use this work.

03/17/08 16:48:05 changed by Alex

  • attachment admin_log.2.diff added.

Made it a bit more efficient

03/17/08 17:09:17 changed by Alex

  • owner changed from nobody to Alex.
  • status changed from new to assigned.
  • has_patch set to 1.

03/19/08 15:18:09 changed by Karen Tracey <kmtracey@gmail.com>

I don't believe either of the existing patches covers logging changes to inline-edited objects. I'll attach what I have working that covers the inline-edited objects as well. Sorry I don't have more time to spend on this but maybe what I have will be useful in some way.

First, it makes the form responsible for reporting what has changed (I updated the logic I had originally used months ago to mirror what is currently in BaseForm's has_changed -- if this goes forward that logic should probably be consolidated in one place rather than being duplicated as I left it in the patch) via a changed_data property. This is something that could potentially be documented for general form users.

Similarly BaseModelFormSet is where the tracking of new/changed/deleted inline-edited objects goes. The formset stuff is not as clean as the single form case -- the information is generated as a side-effect of saving, which seems a bit iffy. Possibly the logic for determining what has been added/changed/deleted should be made independent of save -- save could then just use what added/changed/deleted information is reported by this split-out routine.

One thing this patch does that I really like is it suppresses saving of non-changed inline-edited objects. Thus if you've got upwards of a hundred inline-edited objects and tweak just one (typical for my particular use), you don't have to save all hundred or so, which seems like a win.

03/19/08 15:18:51 changed by Karen Tracey <kmtracey@gmail.com>

  • attachment admin_log.3.diff added.

03/24/08 11:32:19 changed by Karen Tracey <kmtracey@gmail.com>

  • attachment admin_log.4.diff added.

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

03/25/08 15:22:53 changed by Matthijs Kooijman <matthijs@stdin.nl>

Perhaps #4102 (which aims to keep track of changed fields with the model itself) could be of use here?

03/26/08 23:45:29 changed by brosner

  • needs_tests set to 1.

Karen's patch is looking perfect. I can't see anything it is missing. Is there something I am? Otherwise just needs some tests and its RFC.

03/26/08 23:48:02 changed by brosner

Once again I don't fully read what Karen types ;) For purposes of inclusion of getting LogEntry working the patch is looking perfect.

04/04/08 15:57:01 changed by Alex

  • attachment admin_changed.diff added.

Added some tests, there may be some test failures, I can't tell right now

04/04/08 15:57:45 changed by Alex

  • attachment admin_changed.2.diff added.

Added some tests, there may be some test failures, I can't tell right now

04/06/08 15:34:02 changed by Alex

  • attachment 6117.diff added.

This fixes the test failures from the previous patch

04/06/08 23:53:53 changed by brosner

  • owner changed from Alex to brosner.
  • status changed from assigned to new.

Stealing this ticket. I am going to work on finishing this up and getting it committed.

04/06/08 23:54:17 changed by brosner

  • status changed from new to assigned.

Oh and thanks for all your work Alex!

04/29/08 00:45:46 changed by brosner

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [7507]) newforms-admin: Fixed #6117 -- Implemented change history for the admin. This includes the ability to track changes on a newform. Model formsets now only return the changed/new objects saved. A big thanks to Karen Tracey and Alex Gaynor.


Add/Change #6117 (newforms-admin change history needs to be implemented)




Change Properties
Action