views:

57

answers:

3

I have a function:

def create(sender, **kw):
  [...]

Which should be called when the user_activated signal from django-registration is called.

I connect the signal and the function using this:

from registration.signals import user_activated
[...]
post_save.connect(create, sender=user_activated, dispatch_uid="users-atactivation-signal")

But the function isn't called when a user clicks on the activation link, which he got by email.

What do I miss here.

A: 

user_activated is itself is a Signal. So you have to send itself, with parameters. It requires 2 arguments apart from sender, i.e. user, request

user_activated.send(sender=Foo, user=request.user, request=request)

Foo is the backend class used to activate the user.

simplyharsh
Call me stupid, but I don't get it. I thought I have to connect the signal with a function to call. If I do what you said, Foo would be "user_activated", right? But then where do I put the function to call?I might have a big missunderstanding of signals work, maybe you can help me out?
Kai
A: 

Is the code that connects the signal-handling method to that signal definitely being loaded? (You can test with a print statment immediately after it). You can make sure you load your signal handlers for a given app by importing them from that app's __init__.py:

from nameofapp.nameoffilewithhandlersinit import *

PS. is that a typo in the dispatch_uid, or a deliberate name?

stevejalim
A: 

A function like this:

def create(sender, user, request, **kwarg):
[...]

and a connect call like this:

user_activated.connect(create)

does the job. I have these in my signals.py file.

Kai