I'm using the tutorial at this link to do my lazy-registration, and I'm trying to combine it with django-registration.
The tutorial at the lazy-registration link simply needs to call one command to re-parent the events saved:
def on_registration_complete(self, request):
Wishlist.reparent_all_my_session_objects(request.session, request.user)
return HttpResponseRedirect('/')
def on_login_complete(self, request, user, openid=None):
Wishlist.reparent_all_my_session_objects(request.session, request.user)
return HttpResponseRedirect('/')
How do I do a post-hook with django-registration to call reparent_all_my_session_objects()
command after the user logs in or registers? Do I need to create my own auth by copying from django.contrib.auth?
Need to create your own signal receivers on registration and login.
# Handle the signal sent by user_login
from registration.signals import user_login, user_registered
from events.models import Event
from django.contrib.auth import authenticate, login
# Use the signal sent after the login wrapper
def user_login_handler(sender, **kwargs):
"""signal intercept for user_login"""
request = kwargs['request']
Event.reparent_all_my_session_objects(request.session, request.user)
def user_registered_handler(sender, **kwargs):
"""signal intercept for user_registered"""
request = kwargs['request']
# Authenticate user, so that a User model (instead of AnonymousUser) is assigned to Event
# Registration form validates password1==password2
new_user = authenticate(username=request.POST['username'], password=request.POST['password1'])
login(request, new_user)
Event.reparent_all_my_session_objects(request.session, new_user)
user_login.connect(user_login_handler)
user_registered.connect(user_registered_handler)