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 90 forks source link

(Auto-)Approve doesn't work #51

Closed Tyrdall closed 10 years ago

Tyrdall commented 12 years ago

I've just made the basic installation including moderators.py:

from moderation import moderation from database.models import ContactPerson

moderation.register(ContactPerson)

also urls.py improvement:

from django.contrib import admin from moderation.helpers import auto_discover

auto_discover() admin.autodiscover()

That's it. If I change an object, a moderated object is created. I can also reject it. But if I try to approve it, the status is still "Pending". It also has the mark "Auto-approved: Superuser" and the changes are auto-approved actually, but the status doesn't change. If I try to debug I can see that here:

https://github.com/dominno/django-moderation/blob/master/src/moderation/models.py#L162

self.moderation_status is 1 self.changed_object.moderated_object.moderation_status is 2

Can you help me? Thanks in advance. p.s.: Awesome tool!

dominno commented 12 years ago

How are you testing this ? using django admin ? or you are calling automoderate helper in your own code ?

dominno commented 12 years ago

I tested this using admin and it working. Also there is a test for that here https://github.com/dominno/django-moderation/blob/master/src/moderation/tests/unit/models.py#L224 and its passing.

If you are using this in admin then your admin class needs to inherit from ModerationAdmin

from moderation.admin import ModerationAdmin

class ExampleUserProfileAdmin(ModerationAdmin):
    pass

admin.site.register(ExampleUserProfile, ExampleUserProfileAdmin)
Tyrdall commented 12 years ago

I tested in django admin, right. I've tried it using inherit from ModerationAdmin, but it was the same problem. Also when using ModerationAdmin on an admin model, the custom admin fields like exclude and stuff aren't working anymore, so I called automoderate in my custom save_model function.

dominno commented 12 years ago

and what is the output of automoderate(obj, request.user) ? it returns status code

Could you try run this test and tell me if it pass ?

manage.py test moderation.AutoModerateTestCase.test_auto_approve_helper_status_approved

dominno commented 12 years ago

Could you also show me your settings.py

dominno commented 12 years ago

As what kind of user do you test it in admin ? superuser ? normal user ?

Tyrdall commented 12 years ago

Sorry, for the late response. I can't test it in admin anymore, cause I needed to write my own little moderation tool, due to urgency, sorry. I ran the test case. Error output was: django.db.utils.DatabaseError: (1146, "Table 'test_database.tmp_data' doesn't exist")

All I can say that here: https://github.com/dominno/django-moderation/blob/master/src/moderation/models.py#L164 In your _moderate-function the status output was "Approved". But in the frontend it remained "Pending".

I tested as an admin.

tiuma commented 12 years ago

I also note that this issue happens when you have a DateField or DateTimeField with auto_now=True. But there is a workaround for this, just put the field in 'fields_exlcude' from moderator.py.

I hope this comment help...

dulacp commented 10 years ago

I was struggling with this kind of issue, that I resolved in #91. Because the changed_by property wasn't set, the approve/reject method was never called.

Maybe it will fix this very old issue ^^

dominno commented 10 years ago

@dulaccc thanks for solving this one