def intern_edit_profile(request): context = RequestContext(request) session = request.session['sessionUsername'] user = User.objects.get(username=session).pk userProfile = UserProfile.objects.get(Username=user) if request.method == 'POST': form = EditProfileForm(request.POST, instance=userProfile) if form.is_valid(): form.save(); return redirect('/rango/intern_dash') else: print form.errors else: form = EditProfileForm(initial={'firstName':UserProfile.objects.filter(Username=user).get().firstName, 'lastName':UserProfile.objects.filter(Username=user).get().lastName, 'address':UserProfile.objects.filter(Username=user).get().address}) return render_to_response('intern_edit_profile.html', {'form':form},context)
def profile_view(request): user = request.user profile = UserProfile.objects.get(user=request.user) user_initial = { 'first_name':user.first_name, 'last_name':user.last_name, 'email':user.email} profile_initial = { 'website':profile.website, 'picture':profile.picture} if request.method == 'POST': userform = EditUserForm(data=request.POST, initial=user_initial) profileform = EditProfileForm(request.POST, request.FILES, initial=profile_initial) if userform.is_valid() and profileform.is_valid(): user.first_name = userform.cleaned_data['first_name'] user.last_name = userform.cleaned_data['last_name'] user.email = userform.cleaned_data['email'] user.save() profile.website = profileform.cleaned_data['website'] if 'picture' in request.FILES: profile.picture = profileform.cleaned_data['picture'] profile.save() return HttpResponseRedirect('/rango/profile') else: userform = EditUserForm(initial=user_initial) profileform = EditProfileForm(initial=profile_initial) context = { "userform": userform, "profileform": profileform} return render(request, 'registration/profile.html', context)