dominno / django-moderation

django-moderation is reusable application for Django framework, that allows to moderate any model objects.
BSD 3-Clause "New" or "Revised" License
269 stars 91 forks source link

Reinstate previous model instance if change approved then rejected #44

Closed swiharta closed 12 years ago

swiharta commented 12 years ago

It would be a nice feature if, in the case that you are making a change to an existing moderated model instance, on approving the change, the previous model instance got stored in ModeratedObject.changed_object, so that if you subsequently rejected the change, that previous instance could be reinstated, just swapping changed_object for the model instance.

treyhunner commented 12 years ago

You should be able to hook the post_moderation signal and use the moderated_object property to find the previous version of the object and restore it.

Here's an example of how you might do it (I have not tested this code):

def post_moderation_handler(sender, instance, status, **kwargs):
    if status == 0: # Rejected
        instance.moderated_object.changed_object.save() # Save previous version

post_moderation.connect(post_moderation_handler, dispatch_uid="post_moderation_handler")
swiharta commented 12 years ago

Thanks for the tip, Trey. I'll give it a try and report back.

dominno commented 12 years ago

@swiharta does this answer solves your problem ? This could be also solved when moderation history will be implemented. Its described in #21

swiharta commented 12 years ago

I honestly have been too busy to test Trey's suggestion, but I think it sounds like it will work fine, so I'll close this, thanks for reminding me. Looking forward to the moderation history also!

somesmart commented 11 years ago

I may be doing something incorrect, but I tested this code and it's not working for me. When I reject an object, it actually saves the new (rejected) version and displays it publicly. Without this signal, however, everything is working correctly.