def register(request): registered = False if request.user.is_authenticated(): return HttpResponseRedirect('/') if request.method == 'POST': user_form = UserForm(request.POST) profile_form = UserProfileForm(request.POST, request.FILES) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user = user_form.save(commit=False) user.save() g=Group.objects.get(name="student") g.user_set.add(user) profile = profile_form.save(commit=False) profile.user = user profile.save() registered = True return HttpResponseRedirect('/') else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'userpro/register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered':registered})
def editprofile(request): edit = False try: user_obj = User.Objects.get(user=request.user) except: user_obj = None if request.method == 'POST': profile_form = UserProfileForm(data=request.POST, instance = request.user.userprofile) user = request.user if profile_form.is_valid(): profile = profile_form.save(commit=False) profile.user=request.user profile.save() edit = True return HttpResponseRedirect('/') else: print profile_form.errors else: profile_form=UserProfileForm() return render(request, 'userpro/useredit.html', {'profile_form':profile_form})
def editstudentprofile(request): if request.method == 'POST': form = editStudentProfile(request.POST, instance = request.user) profile_form = UserProfileForm(data=request.POST, instance = request.user) if form.is_valid() and profile_form.is_valid(): form.save() profile = profile_form.save(commit=False) profile.save() return HttpResponseRedirect("/") else: print form.errors() and profile_form.errors() else: form = editStudentProfile() detail = UserProfileForm() return render(request, 'registration/student_profile_edit.html', {'form':form, 'detail': detail})