class EditUser(TemplateView): template_name = 'user/edit_user.html' @method_decorator(email_black_list_check(false_function=HttpResponse('/'))) @method_decorator(login_required) 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) @method_decorator(email_black_list_check(false_function=HttpResponse('/'))) @method_decorator(login_required) 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 get_context_data(self, **kwargs): context = super(EditUser, self).get_context_data(**kwargs) context['edit_user_form'] = self.form return context
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 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 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, *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')