def post(self, request, *args, **kwargs): user_form = UserProfileForm(data=request.POST, files=request.FILES, instance=request.user) profile_form = UserProfileEditForm(data=request.POST, instance=request.user.userprofile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() return HttpResponseRedirect(reverse('authapp:profile', args=[request.user.pk])) else: return super(ProfileView, self).get(request, *args, **kwargs)
def profile1(request): form = UserProfileForm(instance=request.user) context = { 'form': form # 'year': date.year, # 'device': device, } return render(request, 'authapp/profile.html', context)
def profile(request): title = 'редактирование' if request.method == 'POST': edit_form = UserProfileForm(data=request.POST, files=request.FILES, instance=request.user) profile_form = UserProfileEditForm(data=request.POST, files=request.FILES, instance=request.user.userprofile) if edit_form.is_valid() and profile_form.is_valid(): edit_form.save() return HttpResponseRedirect(reverse('auth:profile')) else: edit_form = UserProfileForm(data=request.POST, files=request.FILES, instance=request.user) profile_form = UserProfileEditForm(data=request.POST, files=request.FILES, instance=request.user.userprofile) context = { 'title': title, 'form': edit_form, 'profile_form': profile_form, } 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) profile_form = ShopUserProfileEditForm( data=request.POST, instance=request.user.shopuserprofile) if form.is_valid() and profile_form.is_valid(): form.save() return HttpResponseRedirect(reverse('auth:profile')) else: messages.error(request, 'Введены данные не корректно') return render(request, 'authapp/login.html') else: form = UserProfileForm(instance=request.user) profile_form = ShopUserProfileEditForm( instance=request.user.shopuserprofile) # baskets = Basket.objects.filter(user=request.user) context = { 'form': form, 'profile_form': profile_form, # 'baskets': get_basket(request.user), } 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) profile_form = UserProfileEditForm(data=request.POST, instance=request.user.userprofile) if form.is_valid() and profile_form.is_valid(): form.save() return HttpResponseRedirect(reverse('auth:profile')) else: form = UserProfileForm(instance=request.user) profile_form = UserProfileEditForm(instance=request.user.userprofile) carts = Cart.objects.filter(user=request.user) context = { 'title': 'профиль', 'style_link': 'css/profile.css', 'carts': carts, 'form': form, 'profile_form': profile_form } 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) profile_form = ShopUserProfileEditForm( data=request.POST, instance=request.user.shopuserprofile) if form.is_valid() and profile_form.is_valid(): form.save() return HttpResponseRedirect(reverse('auth:profile')) else: form = UserProfileForm(instance=request.user) profile_form = ShopUserProfileEditForm( instance=request.user.shopuserprofile) # baskets = Basket.objects.filter(user=request.user) context = { 'form': form, 'profile_form': profile_form, 'baskets': Basket.objects.filter(user=request.user).select_related('product'), # '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)
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) # 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() 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)
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) # total_quantity = 0 # total_sum = 0 # for basket in baskets: # total_quantity += basket.quantity # total_sum += basket.sum() # 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), } return render(request, 'authapp/profile.html', context)
def profile(request): user = request.user title = 'редактирование' if request.method == 'POST': edit_form = UserProfileForm(request.POST, request.FILES, instance=request.user) profile_form = UserProfileEditForm(request.POST, instance=request.user.userprofile) if edit_form.is_valid() and profile_form.is_valid(): edit_form.save() return HttpResponseRedirect(reverse('auth:profile')) else: edit_form = UserProfileForm(instance=request.user) profile_form = UserProfileEditForm(instance=request.user.userprofile) baskets = Basket.objects.filter(user=user) content = { 'title': title, 'form': edit_form, 'baskets': baskets, 'profile_form': profile_form } return render(request, 'authapp/profile.html', content)
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) # full_price = \ # Basket.objects.filter(user=request.user).aggregate( # full_price=Sum(F('product__price') * F('quantity'), output_field=FloatField()))['full_price'] # full_quantity = \ # Basket.objects.filter(user=request.user).aggregate( # full_quantity=Sum('quantity'))['full_quantity'] 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) # 'full_price': full_price, # 'full_quantity': full_quantity, } return render(request, 'authapp/profile.html', context)
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, })
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 = { 'form': form, 'baskets': Basket.objects.filter(user=request.user), } return render(request, 'authapp/profile.html', context)
def profile(request): if request.method == 'POST': form = UserProfileForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): form.author = request.user form.save() return HttpResponseRedirect(reverse('auth:profile')) else: form = UserProfileForm(instance=request.user) baskets = Basket.objects.filter(user=request.user) context = { 'title': 'Профиль', 'baskets': baskets, 'form': form, '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)
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) context = { 'title': 'GeekShop - Личный кабинет', 'form': form, 'to_day': date.today(), 'baskets': Basket.objects.filter(user=request.user) } 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() 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)
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)
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): 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)
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)
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)
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)
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 })