My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 41: order_insertion_by field not always being checked correctly.
6 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Sep 2010


 
Reported by Gerry.Ei...@gmail.com, Jan 9, 2009
The pre_save signal handler does not check if the order_insertion_by value
has been changed. order_insertion_by is only checked when the instance is
first inserted into the DB and when the parent is changed.
Feb 1, 2009
#1 michael.martinides@gmail.com
agree. it works for me if I add after line 110 in mptt/signals.py:

       old_order = getattr(instance._default_manager.get(pk=instance.pk),
                            'order')
        order = getattr(instance, 'order')

        if parent != old_parent or order != old_order:
            setattr(instance, opts.parent_attr, old_parent)


Dec 15, 2009
#2 gregory....@gmail.com
Could the new rebuild function be called when items are updated? Like in  issue#13 
Feb 11, 2010
#6 samuel.l...@gmail.com
Don't know whether this is helpful or if this bug is going to be fixed anytime soon,
but my patch here works with any fields defined in order_insertion_by.

However, if the parent stays the same while the node should be moved to the end
(according to order_insertion_by), it is actually not moved – that seems to be a bug
in move_node()? 

        # PATCH replaces these lines:
#        old_parent = getattr(instance._default_manager.get(pk=instance.pk),
#                             opts.parent_attr)
#
#        if parent != old_parent:
        saved_instance = instance._default_manager.get(pk=instance.pk)
        old_parent = getattr(saved_instance, opts.parent_attr);
        was_changed = parent != old_parent
        if not was_changed and opts.order_insertion_by:
            for field in opts.order_insertion_by:
                if getattr(instance, field) != getattr(saved_instance, field):
                    was_changed = True
                    break
        if was_changed:
        # /PATCH

Sep 3, 2010
Project Member #7 craig.ds@gmail.com
I see 5 people starred this issue. Can someone describe a use-case for changing `order_insertion_by` after the model has been registered?

Otherwise this is likely to be closed as wontfix.
Status: Chatting
Sep 6, 2010
#9 samuel.l...@gmail.com
As far as I understand, the issue here is not changing the value of `order_insertion_by`, but the value of a field listed in `order_insertion_by`.

Use case: Suppose you have a tree of categories ordered by name. You add a category, and later change its name and save it again. Now the category's position won't be updated by mptt's `pre_save` handler, because it only checks whether the category's parent has been changed.
Sep 6, 2010
Project Member #10 craig.ds@gmail.com
Thanks Samuel, I missed that when reading this the first time
Status: Accepted
Sep 6, 2010
Project Member #11 craig.ds@gmail.com
(No comment was entered for this change.)
Labels: Milestone-Release0.4
Sep 9, 2010
Project Member #12 craig.ds@gmail.com
Initial fixes: http://github.com/django-mptt/django-mptt/commit/796e9094

 * Not sure on the best way to do this - please critique
 * not merged yet, needs cleanup. Might still do it a completely different way

Sep 12, 2010
Project Member #13 craig.ds@gmail.com
Cleaned up that branch a bit, prevented it from traversing foreign keys, and merged it.

Please test the latest from master and report any issues.
Status: Fixed

Powered by Google Project Hosting