def edit(request): if request.method =="POST": form = EditUserForm(request.POST,instance = request.user) if form.is_valid(): user = form.save(instance = request.user) return HttpResponseRedirect('/home/') else: form = EditUserForm(instance = request.user ) return render(request,'account/edit.html',{'form':form})
def edit(request): if request.method == 'POST': user_form = EditUserForm(instance=request.user, data=request.POST) profile_form = ProfileEditForm( instance=request.user.profile, data=request.POST, files=request.FILES ) if user_form.is_valid and profile_form.is_valid: user_form.save() profile_form.save() messages.success(request, 'Profile updated Successfully!') else: messages.error(request, 'Error Updating your profile!') else: user_form = EditUserForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'account/edit.html', {'user_form': user_form, 'profile_form': profile_form})
def user_profile_edit(request): if request.method == 'POST': u_fm = EditUserForm(request.POST, request.FILES, instance=request.user) if u_fm.is_valid(): u_fm.save() messages.success(request, "Profile Updated Successfully !!!") return redirect('profile') else: u_fm = EditUserForm(instance=request.user) return render(request, 'account/profile/editprofile.html', {'u_form': u_fm})
def edit_user(request, query_pk): if request.method == 'POST': username = request.POST.get('username') full_name = request.POST.get('full_name') email_address = request.POST.get('email_address') password = request.POST.get('password', '') role_list = request.POST.getlist('selected_role') try: user_service = UserService() user_service.updateUser(username, full_name, email_address, password, role_list) except: return HttpResponse( 'There is some error while editing user details') if request.method == 'GET': user = User.objects.get(username=query_pk) print user.groups.all() data = { 'username': str(query_pk), 'full_name': str(user.first_name), 'email_address': str(user.email) } form = EditUserForm(data) auth_service = AuthService() choices = auth_service.getAllRole() form.fields['role'].choices = choices form.fields['selected_role'].choices = auth_service.fetch_user_role( query_pk) form.fields['username'].widget.attrs['readonly'] = True form.fields['full_name'].widget.attrs['class'] = 'form-control' form.fields['email_address'].widget.attrs['class'] = 'form-control' form.fields['full_name'].widget.attrs['class'] = 'form-control' form.fields['role'].widget.attrs['class'] = 'form-control' form.fields['selected_role'].widget.attrs['class'] = 'form-control' form.fields['username'].widget.attrs['class'] = 'form-control' form.fields['password'].widget.attrs['class'] = 'form-control' form.fields['confirm_password'].widget.attrs['class'] = 'form-control' return render(request, 'account/edituser.html', {'form': form}) href = reverse('account:user-list') return HttpResponseRedirect(href)
def settings_view(request): if request.method == 'POST': form = EditUserForm(request.POST, instance=request.user) student_form = EditStudentForm(request.POST, request.FILES, instance=request.user.student) if form.is_valid() and student_form.is_valid(): user_form = form.save() student = student_form.save(commit=False) student.user = user_form student.save() return redirect('account:settings') student_form = EditStudentForm(instance=request.user.student) form = EditUserForm(request.POST, instance=request.user) student_form.fields['studij'].widget.attrs = {'class': 'form-control'} context = { 'student_form': student_form, 'form': form, } return render(request, "account/settings.html", context)