Ejemplo n.º 1
0
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')
Ejemplo n.º 2
0
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')
Ejemplo n.º 3
0
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
        })
Ejemplo n.º 4
0
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,'个人信息更新失败')
Ejemplo n.º 5
0
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})
Ejemplo n.º 6
0
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})
Ejemplo n.º 7
0
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})
Ejemplo n.º 8
0
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})
Ejemplo n.º 9
0
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(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})
Ejemplo n.º 11
0
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})
Ejemplo n.º 12
0
def editForm(request):
    #edit = get_object_or_404(UserProfileInfo, id=id)
    if request.method == 'POST':
        edit_user = UserEditForm(data=request.POST or None,
                                 instance=request.user)
        edit_profile = ProfileEditForm(data=request.POST,
                                       files=request.FILES,
                                       instance=request.user.UserProfileInfo)
        if edit_user.is_valid() and edit_profile.is_valid():
            edit_form.save()
            edit_profile.save()
            return redirect('/')

    else:
        edit_user = UserEditForm()
        edit_profile = ProfileEditForm()
    context = {'edit_user': edit_user, 'edit_profile': edit_profile}
    return render(request, 'account/editform.html', context)
Ejemplo n.º 13
0
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,
    })
Ejemplo n.º 14
0
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
    })
Ejemplo n.º 15
0
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
    })
Ejemplo n.º 16
0
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')
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
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})
Ejemplo n.º 19
0
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
    })
Ejemplo n.º 20
0
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
    })
Ejemplo n.º 21
0
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,
        })
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
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
        })
Ejemplo n.º 24
0
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)
Ejemplo n.º 25
0
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})
Ejemplo n.º 26
0
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
    })
Ejemplo n.º 27
0
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)