Mercurial > public > sg101
diff gpp/bio/views.py @ 44:08cd19c1ee50
Added a signal handler for the user model to create a UserProfile for new users.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 17 Jun 2009 00:47:33 +0000 |
parents | 74f04122295e |
children | 62eb9cbbcffc |
line wrap: on
line diff
--- a/gpp/bio/views.py Sun Jun 14 20:25:22 2009 +0000 +++ b/gpp/bio/views.py Wed Jun 17 00:47:33 2009 +0000 @@ -22,16 +22,6 @@ ####################################################################### -def get_profile(user): - try: - profile = user.get_profile() - except: - profile = UserProfile() - profile.user = user - return profile - -####################################################################### - def member_list(request, type='user', page=1): if type == 'user': users = auth.models.User.objects.all().order_by('username') @@ -54,7 +44,7 @@ @login_required def my_profile(request): - profile = get_profile(request.user) + profile = request.user.get_profile() return render_to_response('bio/view_profile.html', { 'subject': request.user, @@ -73,7 +63,7 @@ if user == request.user: return HttpResponseRedirect(reverse('bio.views.my_profile')) - profile = get_profile(user) + profile = user.get_profile() # work around MySQL's handling of Boolean hide_email = bool(profile.hide_email) @@ -93,7 +83,7 @@ if request.method == 'POST': if request.POST.get('submit_button', 'Cancel') == 'Cancel': return HttpResponseRedirect(reverse('bio.views.my_profile')) - profile = get_profile(request.user) + profile = request.user.get_profile() user_form = EditUserForm(request.POST, instance=request.user) profile_form = EditUserProfileForm(request.POST, instance=profile) if user_form.is_valid() and profile_form.is_valid(): @@ -103,7 +93,7 @@ profile.save() return HttpResponseRedirect(reverse('bio.views.my_profile')) else: - profile = get_profile(request.user) + profile = request.user.get_profile() user_form = EditUserForm(instance=request.user) profile_form = EditUserProfileForm(instance=profile) @@ -120,7 +110,7 @@ if request.method == 'POST': form = UploadAvatarForm(request.POST, request.FILES) if form.is_valid(): - profile = get_profile(request.user) + profile = request.user.get_profile() file = form.get_file() if profile.avatar.name != '': profile.avatar.delete(save=False)