def settings(request): user = request.user if request.method == 'POST': form = ProfileForm(request.POST, instance=request.user) user_form = UserEditForm(instance=request.user, data=request.POST) if form.is_valid() and user_form.is_valid(): user.first_name = form.cleaned_data.get('first_name') user.last_name = form.cleaned_data.get('last_name') user.profile.job_title = form.cleaned_data.get('job_title') user.email = form.cleaned_data.get('email') user.profile.url = form.cleaned_data.get('url') user.profile.location = form.cleaned_data.get('location') user.profile.about = form.cleaned_data.get('about') user.save() messages.add_message(request, messages.SUCCESS, 'Your profile was successfully edited.') else: user_form = UserEditForm(instance=request.user) form = ProfileForm(instance=user, initial={ 'job_title': user.profile.job_title, 'url': user.profile.url, 'location': user.profile.location, 'about': user.profile.about, }) return render(request, 'core/settings.html', {'form': form})
def modify(request): user = request.user student = user.userinformation if request.method == "POST": user_form = UserEditForm(request.POST, instance=request.user) userinformation_form = UserInformationForm( request.POST, instance=request.user.userinformation) if user_form.is_valid() and userinformation_form.is_valid(): user.save() userinformation_form.save() return redirect('user-profile') else: user_form = UserEditForm(instance=request.user) userinformation_form = UserInformationForm( instance=request.user.userinformation) return render( request, 'user/edit.html', { 'title': '{} {}'.format(user.first_name, user.last_name), 'user_form': user_form, 'userinformation_form': userinformation_form })
def get(self, request): user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'user/user_edit_form.html', { 'user_form': user_form, 'profile_form': profile_form, })
def edit(request): form = UserEditForm(request.POST or None, request.FILES or None, instance=request.user) if form.is_valid(): form.save() return close_view(request, 'project-list') return render(request, 'edit.html', {'form': form})
def manageuser(request, username): user = get_object_or_404(User, username = username) user2 = Profile.objects.get(user = user.pk) profileform = ProfileForm(instance = user2) userform = UserEditForm(instance = user) args = {'profileform' : profileform, 'userform' : userform, 'user' : user2, 'data' : user} if request.method == 'POST': profileform = ProfileForm(request.POST, request.FILES, instance = user2) userform = UserEditForm(request.POST, instance = user) if profileform.is_valid() and userform.is_valid(): profileform.save() userform.save() args = {'profileform' : profileform, 'userform' : userform, 'user' : user2, } return redirect('/webmaster/user/'+user.username) else: print("errors : {}".format(profileform.errors.as_data())) print("errors : {}".format(userform.errors.as_data())) return render(request, 'webadmin/pages/manage/user/index.html',args)
def edit_profile(request): if request.method == 'POST': user_form = UserEditForm(data=request.POST or None, instance=request.user) profile_form = ProfileEditForm(data=request.POST or None, instance=request.user.profile, files=request.FILES or None) if user_form.is_valid and profile_form.is_valid(): user_form.save() profile_form.save() else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'edit_profile.html', { 'user_form': user_form, 'profile_form': profile_form })
def post(self, request): user_form = UserEditForm(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() return HttpResponseRedirect(reverse('footage-view'))
def post(self, request, *args, **kwargs): recaptcha_response = captchaResult( request.POST.get('g-recaptcha-response')) user = get_user_model().objects.get(pk=request.user.pk) self.form = UserEditForm(request.POST, instance=user) if self.form.is_valid(): if True: #recaptcha_response['success']: self.form.save() return redirect('/') MessageManager().makeMessage(request, message='confirm_not_robot') return redirect(str(request.path)) MessageManager().makeMessage(request, message='problem_with_save') return redirect(str(request.path))
def post(self, request, *args, id): user = get_object_or_404(UserInfo, user_id=id) form = UserEditForm(request.POST, instance=user) if not form.is_valid(): errors = {key: invalid_msg.format(value[0]) for key, value in form.errors.items()} return render(request, self.template_name, {'error': errors, 'form': form}) user = form.save(commit=False) user.updatedUser = request.user.username user.updatedTime = datetime.now() user.save() return redirect('user:user')
def get(self, request, *args, **kwargs): user = get_user_model().objects.get(pk=request.user.pk) self.form = UserEditForm(instance=user) return super(EditUser, self).get(request, *args, **kwargs)
def get(self, request, *args, id): user = get_object_or_404(UserInfo, user_id=id) form = UserEditForm(instance=user) return render(request, self.template_name, {'form': form})