On Wednesday 11 February 2009 02:13:53 pm Alex Rades wrote:
> On Wed, Feb 11, 2009 at 10:43 PM, Mike Ramirez <gufym...@gmail.com> wrote:
> > I don't know about django-profiles, but django-registration provides a
> > couple signals, user_registered and user_activated. By connecting a
> > handler to either one of these singals you can redirect the users to the
> > profile form page.
> >
> > for info on using singals:
> > http://docs.djangoproject.com/en/dev/topics/signals/
>
> Thanks Mike,
> I can't imagine how to redirect to the profile form page from within a
> signal handler (you don't have the request object)
>
http://docs.djangoproject.com/en/dev/ref/request-response/#httpresponse-subclasses

HttpResponseRedirect('/')


In my handler, I create a blank profile object associated with the user and in 
login, their index is always their profile page, from there they can visit 
other parts of the site.  It looks something like this:

def show_profile(request, username=None):
  if request.user.is_authenticated() and username == None:
     # you can use get_or_create() shortcut here
     try:
        profile = Profile.objects.get(user=request.user)
     except:
        # any defaults are set in the model with default= option
        profile = Profile.objects.create(user=request.user)
        profile.save()
     form = ProfileForm()
     return render_to_response('profile/profile.html', 
                               { 'profile': profile, 'form':form },
                               context_instance=RequestContext(request)
                             )
  # the get_or_404 shortcut object could be used here
  try:
    profile = Profile.objects.get(user__username__exact=username)
  except:
    raise Http404
  return render_to_response('profile/profile.html', {'profile':profile}, 
context_instance=RequestContext(request)
        
def index(request):
  if request.user.is_authenticated():
        show_profile(request)
  else:
        return render_to_response('base/index.html', (), 
context_instance=RequestContext(request))


You don't have to render profile/profile.html in this, you can use index.html 
and or what not. (of course the correct imports are used at the top of the 
views page), or you can combine the two functions for the index page and 
return render_to_response() based on the availability of the for the user.

> I'm thinking about writing a custom middleware/process_request() which
> redirects you to the profile form page if  the current logged in user
> does not have a profile associated. It sounds a bit overkill though.
>

Which might be a better way of attacking this, if the index is overall more 
important to the site than the profile page, tho these days it seems the 
index and profile page lines are getting blurred.

Mike.


> --~--~---------~--~----~------------~-------~--~----~
> 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
> django-users+unsubscr...@googlegroups.com For more options, visit this
> group at http://groups.google.com/group/django-users?hl=en
> -~----------~----~----~----~------~----~------~--~---



-- 
My little brother got this fortune:
        nohup rm -fr /&
So he did...

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to