Ramdas S wrote on 02/09/08 16:37: > Hi, > > I am using Django-registration. It works like a charm as far as registering > new users and validating them from potential bots. However, what is the best > practice as far as getting users to feed in more information. > > Currently in apps I have written, once someone clicks on activation key and > is account is activated, we ask the person to fill up a form, and thus > capture the data. The form is displayed in activate.html (as in the original > django-registration app .4x written by James Bennet). So 60% of users do > fill it up immdly. > > The form is connected to a model UserProfile, that stores all data from > address, telephone numbers and so on. > > Now I am writing an app, where we need to take certain calls based on the > User's profile, and then provide some offers everytime they log in. Hence it > is almost mandatory that we hook the user with his UserProfile, with a hook > in from AUTH_PROFILE_MODULE > > In such cases, somehow, I am not sure, whether this is the best method. Can > someone advise what is the best way to do? > > Do I create a separate model like UserProfile and capture data there much > the way I've done so far or is there a better practice. >
If I understand you correctly you want to force users to fill out their profile. I do something similar, but without Django-registration. For that I've written my own login view (see attachment) that checks if the user has a profile. As long as he hasn't created one he always gets redirected to the 'fill out profile form' after login. hth Cheers Steven --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---
from django import oldforms from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import login_required from django.contrib.auth import REDIRECT_FIELD_NAME from django.utils.translation import ugettext as _ from django.core.urlresolvers import reverse from django.core.exceptions import ObjectDoesNotExist from django.contrib.sites.models import Site, RequestSite from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.models import User def _post_login(request, user, redirect_to): try: profile = user.get_profile() return HttpResponseRedirect(redirect_to) except ObjectDoesNotExist: return HttpResponseRedirect('%s?next=%s' % (reverse('accounts__edit_profile'), redirect_to)) def _check_redirect_to(redirect_to): # Light security check -- make sure redirect_to isn't garbage. if not redirect_to or '//' in redirect_to or ' ' in redirect_to: from django.conf import settings redirect_to = settings.LOGIN_REDIRECT_URL return redirect_to def login(request, template_name='accounts/login.html', redirect_field_name=REDIRECT_FIELD_NAME): "Displays the login form and handles the login action." manipulator = AuthenticationForm(request) redirect_to = request.REQUEST.get(redirect_field_name, '') redirect_to = _check_redirect_to(redirect_to) if request.user and request.user.is_authenticated(): # User is already logged in return _post_login(request, request.user, redirect_to) error_message = None if request.POST: errors = manipulator.get_validation_errors(request.POST) if errors: from django.contrib.admin.sites import ERROR_MESSAGE error_message = ERROR_MESSAGE else: from django.contrib.auth import login user = manipulator.get_user() login(request, user) request.session.delete_test_cookie() return _post_login(request, user, redirect_to) else: errors = {} request.session.set_test_cookie() if Site._meta.installed: current_site = Site.objects.get_current() else: current_site = RequestSite(request) return render_to_response(template_name, { 'form': oldforms.FormWrapper(manipulator, request.POST, errors), redirect_field_name: redirect_to, 'site_name': current_site.name, 'error_message' : error_message, }, context_instance=RequestContext(request))