Exemplo n.º 1
0
def update(request):
    if request.method == 'POST':
        form = ShopUserUpdateForm(request.POST, request.FILES,
                                  instance=request.user)
        profile_form = ShopUserProfileUpdateForm(request.POST,
            instance=request.user.shopuserprofile)
        if form.is_valid() and profile_form.is_valid():
            form.save()
            # profile_form.save()
            # костомизировал - подтверждение успешного изменения #
            context = {
                'title': 'Chenge personal data',
                'form': form,
                'profile_form': profile_form,
                'confirmation': 'Changed successfully'
            }
            return render(request, 'authapp/update.html', context)
    else:
        form = ShopUserUpdateForm(instance=request.user)
        profile_form = ShopUserProfileUpdateForm(
            instance=request.user.shopuserprofile)
    context = {
        'title': 'Chenge personal data',
        'form': form,
        'profile_form': profile_form,
    }
    return render(request, 'authapp/update.html', context)
Exemplo n.º 2
0
def user_profile(request):
    if request.method == 'POST':
        # instance подтягивает данные, вместо создания нового объекта
        # request.user - текущий залогиненый пользователь
        profile_form = ShopUserUpdateForm(request.POST,
                                          request.FILES,
                                          instance=request.user)
        user_profile = ShopUserProfileUpdateForm(
            request.POST, request.FILES, instance=request.user.shopuserprofile)
        if profile_form.is_valid() and user_profile.is_valid():
            profile_form.save()
            #  user_profile сохранится автоматически, так как используется @receiver в методе ниже
            # user_profile.save()  # вариант сохранения без @receiver(post_save, sender=ShopUser)
            return HttpResponseRedirect(reverse('main:index'))
    else:
        profile_form = ShopUserUpdateForm(instance=request.user)
        user_profile = ShopUserProfileUpdateForm(
            instance=request.user.shopuserprofile)
    context = {
        'page_title': 'профиль',
        'form': profile_form,
        'user_profile_form': user_profile,
    }

    return render(request, 'authapp/user_profile.html', context)
Exemplo n.º 3
0
def update(request):
    if request.method == 'POST':
        form = ShopUserUpdateForm(request.POST, request.FILES, instance=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('auth:update'))
    else:
        form = ShopUserUpdateForm(instance=request.user)

    context = {'page_title': 'редактирование',
               'form': form}
    return render(request, 'authapp/update.html', context)
Exemplo n.º 4
0
def edit(request):
    if request.method == 'POST':
        form = ShopUserUpdateForm(request.POST, request.FILES, instance=request.user)
        profile_form = ShopUserProfileEditForm(request.POST, instance=request.user.shopuserprofile)
        if form.is_valid() and profile_form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('authapp:update'))
    else:
        form = ShopUserUpdateForm(instance=request.user)
        profile_form = ShopUserProfileEditForm(instance=request.user.shopuserprofile)

    content = {
        'title': 'редактирование',
        'form': form,
        'profile_form': profile_form,
    }

    return render(request, 'authapp/update.html', content)
Exemplo n.º 5
0
def update(request):
    if request.method == 'POST':
        # в instance передаем существующий объект пользователя для редактирования
        form = ShopUserUpdateForm(request.POST,
                                  request.FILES,
                                  instance=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('auth:update'))
    else:
        form = ShopUserUpdateForm(instance=request.user)
    content = {
        'title': 'Редактирование данных',
        'form': form,
        'main_menu': main_menu(),
        'info_pages': footer_menu(),
        'basket': get_basket(request),
    }
    return render(request, 'authapp/update.html', content)
Exemplo n.º 6
0
def update(request):
    if request.method == 'POST':
        form = ShopUserUpdateForm(request.POST,
                                  request.FILES,
                                  instance=request.user)
        profile_form = ShopUserProfileUpdateForm(
            request.POST, request.FILES, instance=request.user.shopuserprofile)
        if form.is_valid() and profile_form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('auth:update'))
    else:
        form = ShopUserUpdateForm(instance=request.user)
        profile_form = ShopUserProfileUpdateForm(
            instance=request.user.shopuserprofile)
    context = {
        'title': 'профиль пользователя',
        'form': form,
        'profile_form': profile_form,
    }
    return render(request, 'authapp/update.html', context)
Exemplo n.º 7
0
def user_profile(request):
    if request.method == 'POST':
        user = ShopUserUpdateForm(request.POST,
                                  request.FILES,
                                  instance=request.user)
        user_profile = ShopUserProfileUpdateForm(
            request.POST, request.FILES, instance=request.user.shopuserprofile)
        if user.is_valid() and user_profile.is_valid():
            user.save()
            # user_profile.save()
            return HttpResponseRedirect(reverse('main:index'))
    else:
        user = ShopUserUpdateForm(instance=request.user)
        user_profile = ShopUserProfileUpdateForm(
            instance=request.user.shopuserprofile)
    context = {
        'page_title': 'профиль',
        'form': user,
        'user_profile_form': user_profile
    }
    return render(request, 'authapp/profile.html', context)
Exemplo n.º 8
0
def update(request):
    if request.method == 'POST':
        form = ShopUserUpdateForm(request.POST,
                                  request.FILES,
                                  instance=request.user)
        # она заполняется данными из связанной модели
        profile_form = ShopUserProfileEditForm(
            request.POST, instance=request.user.shopuserprofile)
        if form.is_valid() and profile_form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('auth:update'))
    else:
        form = ShopUserUpdateForm(instance=request.user)
        profile_form = ShopUserProfileEditForm(
            instance=request.user.shopuserprofile)
    content = {
        'title': 'Редактирование данных',
        'form': form,
        'profile_form': profile_form,
        'main_menu': main_menu(),
        'info_pages': footer_menu(),
        'basket': get_basket(request),
    }
    return render(request, 'authapp/update.html', content)