views:

45

answers:

1

Hey there, Now im working this base on dmitko tutorial on extending django-registration post, all went out fine, just the i can't received the user_registered signal properly.

forms.py

from django import forms
from registration.forms import RegistrationForm
from models import UserProfile

class UserProfileForm(RegistrationForm):
   fullname = forms.CharField(max_length=200)
   address = forms.CharField(max_length=200)

urls.py

    from django.conf.urls.defaults import *
    from registration.views import register
    from forms import UserProfileForm
    import regbackend
    urlpatterns = patterns('',
      url(r'^accounts/register/$', register, {'backend': 'registration.backends.default.DefaultBackend','form_class': UserProfileForm}, name='registration_register'),
 (r'^accounts/', include('registration.backends.default.urls')),
    )

regbackend.py

from forms import UserProfileForm
from models import UserProfile

def user_created(sender, user, request, **kwargs):
   form = UserProfileForm(request.POST)
   data = UserProfile(user=user)
   data.fullname = form.cleaned_data["fullname"]
   data.address = form.cleaned_data["address"]
   print "USER CREATED SIGNALS!"
   data.save()

from registration.signals import user_registered
user_registered.connect(user_created)  
print "REGBACKEND!"

I can get all them working fine but I can't get my signal to connect properly to my user_created method. The print method are just a way for me to check the codes. Can't get user_created to print "USER CREATED SIGNALS!".

Any thoughts??

+1  A: 

Signal's listener must be initiated before calling the signal - try to import ragbackend.py in models.py before registering a signal - if it will start working you have the clue about solution.

Also do not use print, use python built-in logging module instead. You could also run debugging session with ie. ipdb to see if the signal is received and if the user is created, ot you could write simple unit-test or doctest to verify that.

bx2
Thanks bx2. The import regbackend works fine. Found the problem.It seems that i added django-registration as pluggable app on my project instead installing it using pip,easy-install or setup.py install. Installing the app using those fixed the problem. The problem documented at http://docs.b-list.org/django-registration/0.8/faq.html#troubleshooting helps.
diehell
That's great - if you think that my answer helped you somehow, feel free to mark it as correct one (green tick under the points to the left).
bx2