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

RegistrationError at /admin/ <class 'kurse.models.kurs'> has been registered with Moderation. #40

Closed magelan closed 13 years ago

magelan commented 13 years ago

Hi,

I installed and configured moderation according to the readme and get this Error:

RegistrationError at /admin/kurse/kurs/add/

<class 'kurse.models.kurs'> has been registered with Moderation.

I found the same error in Issues here, but could not solve it. I even complety fail to understand why this is an problem, since I am indeed registering this class with Moderation. Maybe you have an idea. Thanks for your Time.

Traceback:
----------------------------------------------------------------------
Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.2.5
Python Version: 2.6.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'moderation',
 'kurse',
 'south',
 'photologue',
 'django_filters']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')

Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in get_response
  91.                         request.path_info)
File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in resolve
  215.             for pattern in self.url_patterns:
File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in _get_url_patterns
  244.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python26\lib\site-packages\django\core\urlresolvers.py" in _get_urlconf_module
  239.             self._urlconf_module = import_module(self.urlconf_name)
File "C:\Python26\lib\site-packages\django\utils\importlib.py" in import_module
  35.     __import__(name)
File "D:\django\bildungswerk\..\bildungswerk\urls.py" in <module>
  3. from kurse.models import kurs
File "D:\django\bildungswerk\kurse\models.py" in <module>
  224. moderation.register(kurs)
File "c:\python26\lib\site-packages\django_moderation-0.2-py2.6.egg\moderation\__init__.py" in register
  175.             raise RegistrationError(msg)

Exception Type: RegistrationError at /admin/
Exception Value: <class 'kurse.models.kurs'> has been registered with Moderation.
dominno commented 13 years ago

Did you put register function in moderator.py module inside of your app ?

You should create moderator.py module inside of your app, please there registration code:

from moderation import moderation
from yourapp.models import YourModel

moderation.register(YourModel)

Next place following code in your main urls.py file:

from moderation.helpers import auto_discover
auto_discover()

Hope that this will solve your problem.

magelan commented 13 years ago

Thanks for you instant reply :-)

I get a new Error: ImportError at /admin cannot import name auto_discover

Caused by these lines in url.py:

from moderation.helpers import auto_discover auto_discover()

dominno commented 13 years ago

Could you paste your urls.py file ?

magelan commented 13 years ago

here it is:

from django.conf.urls.defaults import * from django.contrib import databrowse from kurse.models import kurs

Uncomment the next two lines to enable the admin:

from django.contrib import admin admin.autodiscover()

from moderation.helpers import auto_discover auto_discover()

urlpatterns = patterns('',

Example:

# (r'^bildungswerk/', include('bildungswerk.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
#(r'^admin/gatekeeper/', include('gatekeeper.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
    {'document_root': 'D:/django/bildungswerk/bilder'}),
(r'^photologue/', include('photologue.urls')),
(r'^filter/', 'kurse.views.chr_filter'),
(r'^alex/', 'kurse.views.kurs_list'),
(r'^form/', 'kurse.views.kurs_form'),
#(r'^databrowse/(.*)', databrowse.site.root),
(r'^new/$', 'django.views.generic.create_update.create_object', { 'model': kurs } ),

)

dominno commented 13 years ago

What version of django-moderation are you using ? are you using version from pypi ? If you can please use version from github.

magelan commented 13 years ago

oh, sorry. Formating gets changed by github

magelan commented 13 years ago

I tried "from moderation.helpers import auto_discover" and there seems to be not auto_discover in moderation.helpers

dominno commented 13 years ago

This is because you are using older version of django-moderation, please update to version from github.

magelan commented 13 years ago

I used easy_install django-moderation before, and now downloaded 0.3.1 but I'm still not quite shure what version I have installed. But the "from moderation.helpers import auto_discover" error is gone now.

Admin interface works now and moderation appears there, but as soon as I try to add a moderated object I get the old error again:

RegistrationError at /admin/kurse/kurs/add/

<class 'kurse.models.kurs'> has been registered with Moderation.

dominno commented 13 years ago

Have you removed "moderation.register(kurs)" from your models.py file ?

magelan commented 13 years ago

yes, I did.

magelan commented 13 years ago

when I change the admin.py back to: "class kursAdmin(admin.ModelAdmin)" instead of "class kursAdmin(ModerationAdmin):" I get no errors, but kurs objects are not moderated either ;-)

magelan commented 13 years ago

I removed south and did syncdb and now get a different error. AttributeError at /admin/kurse/kurs/1/ 'kurs' object has no attribute 'moderated_object'

It seems I have version 0.2, even so I downloaded and install 0.3.1: c:\python26\lib\site-packages\django_moderation-0.2-py2.6.egg\moderation\forms.py in init, line 14

How can I get the latest version?

dominno commented 13 years ago

You have wrong version on your PYTHONPATH. You need remove directory c:python26libsite-packagesdjango_moderation-0.2-py2.6.egg

Download https://github.com/dominno/django-moderation/tarball/v0.3.2

extract it and run:

python setup.py install
magelan commented 13 years ago

Thanks for not giving up. I have done that before many times with different versions and also removed the Line in easy-install.pth, but when ever I do an install it end with this message: Using c:\python26\lib\site-packages Finished processing dependencies for django-moderation==0.2 Even with the version 0.3.2 direktly from your Link. Maybe the Messages are not up to date.

dominno commented 13 years ago

You can also clone a repo and add moderation module to PYTHONPATH

git clone git://github.com/dominno/django-moderation.git
magelan commented 13 years ago

Ok tried that as well, and should have to newest Version avaliable. Error still: AttributeError at /admin/kurse/kurs/2/ 'kurs' object has no attribute 'moderated_object'

dominno commented 13 years ago

Could you paste full tracebug for this ?

magelan commented 13 years ago

http://dpaste.com/538961/

File "C:\Python26\lib\site-packages\django\contrib\admin\options.py" in wrapper

  1. return self.admin_site.admin_view(view)(_args, *_kwargs) File "C:\Python26\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  2. response = view_func(request, _args, *_kwargs) File "C:\Python26\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  3. response = view_func(request, _args, *_kwargs) File "C:\Python26\lib\site-packages\django\contrib\admin\sites.py" in inner
  4. return view(request, _args, *_kwargs) File "C:\Python26\lib\site-packages\moderation\admin.py" in change_view
  5. return super(ModerationAdmin, self).change_view(request, object_id) File "C:\Python26\lib\site-packages\django\utils\decorators.py" in _wrapper
  6. return decorator(bound_func)(_args, *_kwargs) File "C:\Python26\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  7. response = view_func(request, _args, *_kwargs) File "C:\Python26\lib\site-packages\django\utils\decorators.py" in bound_func
  8. return func(self, _args2, *_kwargs2) File "C:\Python26\lib\site-packages\django\db\transaction.py" in _commit_on_success
  9. res = func(_args, *_kw) File "C:\Python26\lib\site-packages\django\contrib\admin\options.py" in change_view
  10. form = ModelForm(instance=obj) File "C:\Python26\lib\site-packages\moderation\forms.py" in init
  11. if instance.moderated_object.moderation_status in \

Exception Type: AttributeError at /admin/kurse/kurs/2/ Exception Value: 'kurs' object has no attribute 'moderated_object'

magelan commented 13 years ago

I wonder how the moderator.py file gets executed? Is that done but

from moderation.helpers import auto_discover auto_discover()

Or do I have to import that file somewhere?

dominno commented 13 years ago

it is done by this auto_discover function

treyhunner commented 13 years ago

magelan, have you resolved your issue yet?

<class 'kurse.models.kurs'> has been registered with Moderation.

moderation.register may only be run once for each model. This is why it's typically put in moderator.py, a file which is never imported anywhere else to avoid collisions (auto_discover will import it automatically). Search all of your project's files and make sure that moderation.register is not called anywhere except in your moderator.py file. Additionally, make sure that moderator.py is not being imported anywhere in your application (just like admin.py should never be imported anywhere).

Also make sure that auto_discover is not being called anywhere else and urls.py is not being imported anywhere. Because register can only be called once, the file it is called in and all files that reference that one (indirectly through auto_discover in this case) can only be called once as well. Since urls.py is called by Django once and moderator.py, it can't be imported anywhere else.

kurs' object has no attribute 'moderated_object'

If the 'kurs' object has no attribute 'moderated_object' error you were receiving was from the command line you would need to import moderator.py or your urls file manually. For example:

from kurse import moderator

If it was not, please make sure your application is in INSTALLED_APPS in settings.py and you have a proper moderator.py file in your application that calls moderation.register for your model.

magelan commented 13 years ago

Hi,

no unfortuneatly not. I checked everything in your post, and everything was correct. I'm not aware that I changed anything, but now I get a new error. It only appears if I try to add or change an object that is supposed to be moderated.

error at /admin/kurse/kurs/1/

(10061, 'Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte')

for some reason it is in German, and says "Connection could not established, because the host Computer refused the connection"

Any other idea or something else I could try?

Full error: http://dpaste.com/539124/

treyhunner commented 13 years ago

That looks like an issue with your email configurations.

magelan commented 13 years ago

Bingo! Everything works now. Thanks a lot for you work and support.