def professor_edit(request, professor_id): try: if request.method == 'POST': professor = get_object_or_404(Professor, pk=professor_id) professor_form = ProfessorCreationForm(request.POST, instance=professor) profile = Profile.objects.get(pk=professor.profile.pk) profile_form = ProfileEditForm(request.POST, instance=profile) user_form = UserEditForm(request.POST, instance=profile.user) if professor_form.is_valid() and profile_form.is_valid() and user_form.is_valid(): professor_form.save() profile_form.save() user_form.save() return redirect('professor_detail', professor_id=professor_id) else: professor = get_object_or_404(Professor, pk=professor_id) professor_form = ProfessorCreationForm(instance=professor) profile = Profile.objects.get(pk=professor.profile.pk) profile_form = ProfileEditForm(instance=profile) user_form = UserEditForm(instance=profile.user) return render(request, 'school/professors/edit.html', {'section': 'professors', 'professor_form': professor_form, 'profile_form': profile_form, 'user_form': user_form}) except Exception: return redirect('professors_list')
def student_edit(request, student_id): try: if request.method == 'POST': student = get_object_or_404(Student, pk=student_id) student_form = StudentCreationForm(request.POST, instance=student) profile = Profile.objects.get(pk=student.profile.pk) profile_form = ProfileEditForm(request.POST, instance=profile) user_form = UserEditForm(request.POST, instance=profile.user) if student_form.is_valid() and profile_form.is_valid() and user_form.is_valid(): student_form.save() profile_form.save() user_form.save() return redirect('student_detail', student_id=student_id) else: student = get_object_or_404(Student, pk=student_id) student_form = StudentCreationForm(instance=student) profile = Profile.objects.get(pk=student.profile.pk) profile_form = ProfileEditForm(instance=profile) user_form = UserEditForm(instance=profile.user) return render(request, 'school/student/edit.html', {'section': 'students', 'student_form': student_form, 'profile_form': profile_form, 'user_form': user_form}) except Exception: return redirect('students_list')
def user_edit(request): user_form = UserEditForm(request.POST) profile_form = ProfileEditForm(request.POST) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() create_action(request.user,'修改了个人信息') messages.success(request,'个人信息更新成功') return user_form,profile_form else: messages.error(request,'个人信息更新失败')
def edit(request): profile = Profile.objects.filter(user=request.user).first() # POSTアクセス時(返信時)の処理 if request.method == 'POST': # ツールの編集 if 'add-usertool-form' in request.POST: toolid = request.POST['toolchoice'] tool = Tool.objects.filter(id=toolid).first() usertool = UserTool.objects.filter(tool=tool, profile=profile) if len(usertool.all()) == 0: usertool = UserTool() else: usertool = usertool.first() usertool.profile = profile usertool.tool = tool usertool.level = int(request.POST['toollevel']) usertool.save() # 班の編集 if 'add-division-form' in request.POST: divisionid = int(request.POST['divisionchoice']) division = Division.objects.filter(id=divisionid).first() profile.divisions.add(division) # ユーザーデータ編集 if 'user-edit-form' in request.POST: user_form = UserEditForm(request.POST, request.FILES, instance=request.user) user_form.save() profile_form = ProfileForm(request.POST, request.FILES, instance=request.user.profile) profile = profile_form.save(commit=True) # 自分のプロフィールにリダイレクト return redirect(to='/member/me') exist_tools = [] for usertool in profile.usertool_set.all(): exist_tools.append(usertool.tool) # GETアクセス時の処理 params = { 'add_usertool_form': UserToolForm(), 'user_form': UserEditForm(instance=request.user), 'profile_form': ProfileForm(instance=request.user.profile), 'tools': Tool.objects.all(), 'exist_tools': exist_tools, 'divisions': Division.objects.all(), 'profile': profile, } return render(request, 'member/edit.htm', params)
def edit(request): """ обработчик редактирования пользователя """ if request.method == 'POST': user_form = UserEditForm(instance=request.user, data=request.POST) profile_form = ProfileEditForm(instance=request.user.profile, data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() return HttpResponseRedirect(reverse('transfers-list')) else: user_form = UserEditForm(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 edit(request): if request.method == "POST": person = User.objects.get(id=request.user.id) user_forms = UserEditForm(request.POST, instance=person) if user_forms.is_valid(): user_forms.save(commit=False) person.first_name = request.POST.get("first_name") person.save() messages.success(request, 'Profile updated successfully') else: messages.error(request, 'Error updating your profile') else: user_forms = UserEditForm() return render(request, 'account/edit.html', {'user_forms': user_forms})
def edit_user(request): if request.method == 'POST': user_form = UserEditForm(instance=request.user, data=request.POST) if user_form.is_valid(): # validation -> UserEditForm의 clean_<name> 메서드 실행 user_form.save() # track_action(request.user, 'edited information') return redirect('shop:product_list') else: pass else: user_form = UserEditForm(instance=request.user) return render(request, 'account/edit.html', {'user_form': user_form})
def dashboard_editar_perfil(request): if request.method == 'POST': user_form = UserEditForm(instance=request.user, data=request.POST) perfil_form = PerfilEditForm(instance=request.user.perfil, data=request.POST, files=request.FILES) if user_form.is_valid() and perfil_form.is_valid(): user_form.save() perfil_form.save() return redirect('/dashboard/home') else: user_form = UserEditForm(instance=request.user) perfil_form = PerfilEditForm(instance=request.user.perfil) return render(request, 'dashboard/dashboard_editar_perfil.html', {'user_form': user_form, 'perfil_form': perfil_form})
def edit(request): if request.method == "POST": 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() else: user_form = UserEditForm(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 edit(request): if request.method == 'POST': 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() messages.success(request, 'Profile updated successfully') else: messages.error(request, 'Error updating your profile') else: user_form = UserEditForm(instance=request.user) profile = Profile.objects.get(user=request.user) profile_form = ProfileEditForm(instance=profile) return render(request, 'account/edit.html', {'user_form': user_form, 'profile_form': profile_form})
def edit(request): if request.method == 'POST': # instance 指定对象是数据库中的当前登录用户的哪一行数据对象, 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() messages.success(request, '个人信息修改成功') else: messages.error(request, '个人信息修改失败') else: user_form = UserEditForm() profile_form = ProfileEditForm() return render(request, 'account/edit.html', {'user_form': user_form, 'profile_form': profile_form})
def edit(request): if request.method == 'POST': 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() messages.success(request, "Profile updated succesfully!") else: messages.error(request, "Error: something went wrong.") else: user_form = UserEditForm(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 edit_account(request): if request.method == 'POST': try: Profile.objects.get(user=request.user) except Profile.DoesNotExist: Profile.objects.create(user=request.user) 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() messages.success(request, 'Profile updated successfully') return redirect('account') else: messages.error(request, 'Error updating profile') return render(request, 'edit_account.html')
def edit_user_info(request): if request.method == 'POST': user_edit_form = UserEditForm(instance=request.user, data=request.POST) profile_edit_form = UserProfileEditForm( instance=request.user.userprofile, data=request.POST, files=request.FILES, ) if user_edit_form.is_valid() and profile_edit_form.is_valid(): user_edit_form.save() profile_edit_form.save() else: user_edit_form = UserEditForm(instance=request.user) profile_edit_form = UserProfileEditForm( instance=request.user.userprofile) return render(request, 'account/edituserinfo.html', { 'user_edit_form': user_edit_form, 'profile_edit_form': profile_edit_form, })
def edit(request): if request.method == 'POST': 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() messages.success(request, 'Профиль обновлен') else: messages.error(request, 'Ошибка обновления профиля') else: user_form = UserEditForm(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 edit(request): if request.method == "POST": 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() messages.success(request, "Profile updated successfully") else: messages.error(request, "Error update your profile") else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) ctx = {"user_form": user_form, "profile_form": profile_form} return render(request, "account/edit.html", ctx)
def edit(request): if request.method == 'POST': 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() messages.success(request, 'Profile updated successfully') else: messages.error(request, 'Error updating your profile') else: user_form = UserEditForm(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 edit(request): if request.method == 'POST': 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() messages.success(request, 'Profile Updated Successfully') else: messages.error(request, 'Failed to upload the profile') else: user_form = UserEditForm(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(request): avatar_form = PhotoProfileForm(instance=request.user.profile) if request.method == 'POST': user_form = UserEditForm(instance=request.user, data=request.POST) profile_form = ProfileForm(instance=request.user.profile, data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() messages.success(request, 'Профиль успешно обновлен') else: messages.error(request, 'Что-то пошло не так') else: user_form = UserEditForm(instance=request.user) profile_form = ProfileForm(instance=request.user.profile) return render( request, 'account/profile.html', { 'user_form': user_form, 'profile_form': profile_form, 'avatar_form': avatar_form, })
def edit(request): try: profile = request.user.profile except ObjectDoesNotExist: profile = Profile(user=request.user) if request.method == "POST": user_form = UserEditForm(instance=request.user, data=request.POST) profile_form = ProfileEditForm(isinstance=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() else: user_form = UserEditForm(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 edit(request): context = dict() if request.method == 'POST': 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() messages.success(request, 'Profile updated successfully') else: messages.error(request, 'Error updating your profile') else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) context['user_form'] = user_form context['profile_form'] = profile_form return render(request, 'account/edit.html', context)
def edit(req): if req.method == 'POST': user_form = UserEditForm( instance=req.user, data=req.POST ) profile_form = ProfileEditForm( instance=req.user.profile, data=req.POST, files=req.FILES ) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() messages.success(req, 'It did what it did...') else: messages.error(req, 'Not good...') else: user_form = UserEditForm(instance=req.user) profile_form = ProfileEditForm(instance=req.user.profile) return render(req, 'account/edit.html', {'user_form': user_form, 'profile_form': profile_form})
def edit(request): if request.method == 'POST': 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 redirect(reverse_lazy('account:my_account')) else: return render(request, 'registration/edit.html', { 'user_form': user_form, 'profile_form': profile_form }) else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'registration/edit.html', { 'user_form': user_form, 'profile_form': profile_form })
def edit(request): if request.method == 'POST': 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() messages.success(request, "个人信息编辑成功!") # return redirect(reverse("dashboard")) else: messages.error(request, "个人信息编辑失败啦!") else: #instance=,用于指定表单实例化为某个具体的数据对象 user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) data = { "user_form": user_form, "profile_form": profile_form, } return render(request, "account/edit.html", data)
def settings(request): user = getattr(request, 'user', None) if request.method == 'POST': user_form = UserEditForm(instance=user, data=request.POST) profile_form = ProfileEditForm(instance=user, data=request.POST, files=request.FILES) if all([user_form.is_valid(), profile_form.is_valid()]): user_form.save() profile_form.save() #messages.success(request, 'Profile updated successfully') else: pass # messages.error(request, 'Error updating your profile') else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=user.profile) return render(request, 'account/edit.html', { 'user_form': user_form, 'profile_form': profile_form })
def admin_edit(request, admin_id): try: if request.method == 'POST': admin = get_object_or_404(User, pk=admin_id) user_form = UserEditForm(request.POST, instance=admin) profile = Profile.objects.get(pk=admin.profile.pk) profile_form = ProfileEditForm(request.POST, instance=profile) if profile_form.is_valid() and user_form.is_valid(): profile_form.save() user_form.save() return redirect('admin_detail', admin_id=admin_id) else: admin = get_object_or_404(User, pk=admin_id) profile = Profile.objects.get(pk=admin.profile.pk) profile_form = ProfileEditForm(instance=profile) user_form = UserEditForm(instance=admin) return render(request, 'school/admin/edit.html', {'section': 'users', 'profile_form': profile_form, 'user_form': user_form}) except Exception: return redirect('admin_detail', admin_id=admin_id)
def edit(request): #Изменение данных пользователя через личный кабинет if request.method == 'POST': 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() or profile_form.is_valid(): if user_form.is_valid(): form = user_form.save(commit=False) form.user = request.user form.save() else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'registration/edit_profile.html', { 'user_form': user_form, 'profile_form': profile_form }) if profile_form.is_valid(): print('VALIDыуцц') profile_form.save() else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'registration/edit_profile.html', { 'user_form': user_form, 'profile_form': profile_form }) return redirect(reverse_lazy('account:my_account')) else: return render(request, 'registration/edit_profile.html', { 'user_form': user_form, 'profile_form': profile_form }) else: user_form = UserEditForm(instance=request.user) profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'registration/edit_profile.html', { 'user_form': user_form, 'profile_form': profile_form })