def edit_profile(request, user_id): profile = get_user_profile(user_id) if profile: user_data = profile.__dict__ user_data.update(profile.user.__dict__) form = UserProfileForm(initial=user_data) else: user = get_user(user_id) form = UserProfileForm(initial=user.__dict__) if request.method == 'POST': form = UserProfileForm(request.POST, request.FILES) if form.is_valid(): user_data = {} user_data.update(form.cleaned_data) if request.FILES.get('avatar'): user_data['avatar'] = request.FILES['avatar'] else: del user_data['avatar'] create_or_update_profile(user_id, **user_data) return HttpResponseRedirect(reverse('profile', args=[user_id])) return render_to_response('user/profile_edit.html', { 'form': form, 'profile': profile, }, context_instance=RequestContext(request))
def profile(request, user_id): user = get_user(user_id) all_actions = Action.objects.filter(organizer=user) user_profile = get_user_profile(user_id) return render_to_response( 'user/profile.html', { 'user': user, 'user_profile': user_profile, 'actions': all_actions, }, context_instance=RequestContext(request))