dominno/django-moderation — Issue #53: Problem with fields_exclude and auto_approve
Author: 8ksoft
Created: 2012-01-03 15:00:37+00:00
State: open

Hi,

There is a bug with fields_exclude (¿or is not clear his function?).
I will explain with an example:

I want to avoid moderation of certain fields of a model. For example...

#models.py
class Foo(models.Model):
foo_a = models.CharField(max_length=80)
foo_b = models.IntegerField

#moderator.py
class FooModerator(GenericModerator):
auto_approve_for_superusers = True
auto_approve_for_staff = False
#Fields to exclude from object change list. Default: []
fields_exclude = ['foo_b']

moderation.register(Foo, FooModerator)

Then.. i expect that when i change field 'foo_a' the moderation will trigger for that field, not for 'foo_b'.

Tests Results:

Case 1:
As a superuser, or a user with auto_approve settings enabled, when i change only a field inside fields_exclude list, i never see the change.
That is if i edit the excluded field (foo_b field), then that field is not changed (it still have the old value). Moderation status = Approved.

Case 2 (this works ok):
As a superuser, when i change other fields and a excluded field, it works fine. That is if i edit both, the excluded field and a regular field ('foo_a' and 'foo_b'), then all the fields have the expected result.
Moderation status = Approved.

Case 3:
Idem case 1 but as a staff user and the same object instance as in case 1 (try it after case 1): The moderation works as expected, that is if i edit only the excluded field, the change can be seeing. Moderation status = Approved.

Case 4:
Idem case 1 but as a staff user and other object instance: The moderation fails with same results as in case 1. Moderation status = Pending.

Case 5:
Continue case 4. When approved, the excluded field (foo_b) is not changed causing loose of data. But.. the next time that object is edited moderation and excluded fields works again!!

I hope I have explained...
Regards,

Mario.