Exemple #1
0
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(data=request.POST,
                               files=request.FILES,
                               instance=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('users:profile'))
    else:
        form = UserProfileForm(instance=request.user)
    content = {
        'title': 'GeekShop - Личный кабинет',
        'form': form,
        'baskets': Basket.objects.filter(user=request.user)
    }
    return render(request, 'authapp/profile.html', content)
Exemple #2
0
def profile(request):
    user = request.user
    if request.method == 'POST':
        form = UserProfileForm(data=request.POST,
                               files=request.FILES,
                               instance=user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('auth:profile'))
    else:
        form = UserProfileForm(instance=user)
    context = {
        'form': form,
        'baskets': Basket.objects.filter(user=user),
    }
    return render(request, 'authapp/profile.html', context)
Exemple #3
0
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(data=request.POST,
                               files=request.FILES,
                               instance=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("authapp:profile"))
    else:
        form = UserProfileForm(instance=request.user)

    baskets = Basket.objects.filter(user=request.user)

    context = {
        "form": form,
        "baskets": baskets,
    }
    return render(request, 'authapp/profile.html', context)
Exemple #4
0
    def post(self, request, *args, **kwargs):
        user = User.objects.get(pk=self.request.user.pk)
        edit_form = UserProfileForm(data=request.POST,
                                    files=request.FILES,
                                    instance=user)
        profile_form = UserProfileEditForm(data=request.POST,
                                           files=request.FILES,
                                           instance=user.userprofile)

        if edit_form.is_valid() and profile_form.is_valid():
            edit_form.save()
            user.userprofile.save()
            return HttpResponseRedirect(self.success_url)

        return render(request, self.template_name, {
            'form': edit_form,
            'profile_form': profile_form,
        })
Exemple #5
0
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(data=request.POST, files=request.FILES, instance=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('auth:profile'))
    else:
        form = UserProfileForm(instance=request.user)
    baskets = Basket.objects.filter(user=request.user)
    context = {
        'form': form,
        'baskets': baskets,
        'total_quantity': sum(basket.quantity for basket in baskets),
        'total_sum': sum(basket.sum() for basket in baskets),

     }

    return render(request, 'authapp/profile.html', context)
Exemple #6
0
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(data=request.POST, files=request.FILES, instance=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('auth:profile'))
            # return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
        else:
            messages.error(request, 'Введены данные не корректно')
            return render(request, 'authapp/login.html')
    else:
        form = UserProfileForm(instance=request.user)

    baskets = Basket.objects.filter(user=request.user)
    context = {
        'form': form,
        'baskets': baskets,
    }
    return render(request, 'authapp/profile.html', context)
def profile(request):
    if request.method == "POST":
        form = UserProfileForm(data=request.POST,
                               files=request.FILES,
                               instance=request.user)
        if form.is_valid():
            form.save()
            messages.success(request, "Данные успешно сохраненны!")
            return HttpResponseRedirect(reverse("auth:profile"))
        else:
            print(form.errors)
    else:
        form = UserProfileForm(instance=request.user)
    context = {
        "title": "GeekShop - Профиль",
        "form": form,
        "baskets": Basket.objects.filter(user=request.user),
    }
    return render(request, "authapp/profile.html", context)
Exemple #8
0
def edit(request):
    if request.method == 'POST':
        profile_form = UserProfileForm(request.POST,
                                       request.FILES,
                                       instance=request.user)
        ext_profile_form = UserProfileEditForm(
            request.POST, instance=request.user.userprofile)
        if profile_form.is_valid() and ext_profile_form.is_valid():
            profile_form.save()
            return HttpResponseRedirect(reverse('auth:edit'))
    else:
        profile_form = UserProfileForm(instance=request.user)
        ext_profile_form = UserProfileEditForm(
            instance=request.user.userprofile)
    context = {
        'title': 'Редактрирование дополнительных данных',
        'profile_form': profile_form,
        'ext_profile_form': ext_profile_form
    }
    return render(request, 'authapp/edit.html', context)
Exemple #9
0
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(data=request.POST,
                               files=request.FILES,
                               instance=request.user)
        profile_form = UserProfileEditForm(data=request.POST,
                                           instance=request.user.userprofile)
        if form.is_valid() and profile_form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('authapp:profile'))
    else:
        form = UserProfileForm(instance=request.user)
        profile_form = UserProfileEditForm(instance=request.user.userprofile)
    baskets = Basket.objects.filter(user=request.user)
    context = {
        'title': 'Профиль',
        'form': form,
        'profile_form': profile_form,
        'baskets': baskets,
    }
    return render(request, 'authapp/profile.html', context)
Exemple #10
0
def edit(request):
    title = 'редактирование'
    if request.method == 'POST':
        edit_form = UserProfileForm(request.POST,
                                    request.FILES,
                                    instance=request.user)
        profile_form = ShopUserProfileEditForm(
            request.POST, instance=request.user.shopuserprofile)
        if edit_form.is_valid() and profile_form.is_valid():
            edit_form.save()
            return HttpResponseRedirect(reverse('authapp:edit'))
    else:
        edit_form = UserProfileForm(instance=request.user)
        profile_form = ShopUserProfileEditForm(
            instance=request.user.shopuserprofile)
    content = {
        'title': title,
        'edit_form': edit_form,
        'profile_form': profile_form
    }
    return render(request, 'authapp/edit.html', content)
Exemple #11
0
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(data=request.POST,
                               files=request.FILES,
                               instance=request.user)
        profile_form = ShopUserProfileForm(
            data=request.POST, instance=request.user.shopuserprofile)
        if form.is_valid() and profile_form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('users:profile'))
    else:
        form = UserProfileForm(instance=request.user)
        profile_form = ShopUserProfileForm(
            instance=request.user.shopuserprofile)

    context = {
        'title': 'GeekShop - Личный кабинет',
        'form': form,
        'profile_form': profile_form
    }
    return render(request, 'authapp/profile.html', context)
def profile(request):
    user = request.user
    if request.method == 'POST':
        user_form = UserProfileForm(data=request.POST,
                                    files=request.FILES,
                                    instance=user)
        user_profile_form = UserProfileEditForm(data=request.POST,
                                                files=request.FILES,
                                                instance=user.userprofile)
        if user_form.is_valid() and user_profile_form.is_valid():
            with transaction.atomic():
                user_form.save()
            return HttpResponseRedirect(reverse('auth:profile'))
    else:
        user_form = UserProfileForm(instance=user)
        user_profile_form = UserProfileEditForm(instance=user.userprofile)
    context = {
        'user_form': user_form,
        'user_profile_form': user_profile_form,
        'baskets': Basket.objects.filter(user=user),
    }
    return render(request, 'authapp/profile.html', context)
Exemple #13
0
def register(request):

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():

            user = user_form.save(
            )  #here we grab the form and saves to the database
            user.set_password(user.password)  #here we hashe the password
            user.save()  #here we save the hashed password to the database
            #add the custom user attributes we created to user
            profile = profile_form.save(
                commit=False
            )  #we dont want to commit to the database yet bc it might have collisions and overwrite the user
            profile.user = user  #sets a one to one relationship
            #check if picture was provided (or any type of file actually)
            if 'profile_pic' in request.FILES:
                profile.profile_pic = request.FILES['profile_pic']

            profile.save()

            registered = True

        else:
            print(user_form.erros, profile_form.erros)
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request, 'authapp/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
Exemple #14
0
def profile(request):
    if request.method == 'POST':
        print('POST')
        form = UserProfileForm(request.POST,
                               request.FILES,
                               instance=request.user)
        if form.is_valid():
            print('Form valid')
            form.save()
            # profile_form.save()
            return HttpResponseRedirect(reverse('authapp:profile'))
    else:
        user_get = ValAuth.objects.get(pk=request.user.pk)
        ic(user_get)

        form = UserProfileForm(instance=request.user)

    context = {
        'form': form
        # 'year': date.year,
        # 'device': device,
    }
    return render(request, 'authapp/profile.html', context)
Exemple #15
0
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(data=request.POST,
                               files=request.FILES,
                               instance=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('authapp:profile'))
    else:
        form = UserProfileForm(instance=request.user)

    # total_quantity = 0
    # for basket in Basket.objects.filter(user=request.user):
    #     total_quantity += basket.quantity
    #
    # total_sum = 0
    # for basket in Basket.objects.filter(user=request.user):
    #     total_sum += basket.sum()
    # baskets = Basket.objects.filter(user=request.user) !!!Всю логику вынести в модули
    context = {
        'form': form,
        'baskets': Basket.objects.filter(user=request.user),
    }
    return render(request, 'authapp/profile.html', context)
Exemple #16
0
def profile(request):
    if request.method == "POST":
        form = UserProfileForm(data=request.POST, files=request.FILES, instance=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('auth:profile'))

    else:
        form = UserProfileForm(instance=request.user)



    context = {
        'title': 'профиль',
        'style_link': 'css/profile.css',

        'carts': Cart.objects.filter(user=request.user),

        'carts_total_price': count_total_price(request),

        'form': form
    }

    return render(request, 'authapp/profile.html', context)
Exemple #17
0
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(data=request.POST,
                               files=request.FILES,
                               instance=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('users:profile'))
    else:
        form = UserProfileForm(instance=request.user)

    # baskets = Basket.objects.filter(user=request.user)

    # total_quantity = sum(basket.quantity for basket in baskets)
    # total_sum = sum(basket.sum() for basket in baskets)
    context = {
        'title': 'GeekShop - Личный кабинет',
        'form': form,
        'baskets': Basket.objects.filter(user=request.user)
        # 'total_quantity': total_quantity,
        # 'total_sum': total_sum
    }

    return render(request, 'authapp/profile.html', context)