Exemple #1
0
def profile_add(request):

    if request.method == 'POST':

        buyer_form = BuyerSaveForm(request.POST)

        if buyer_form.is_valid():

            first_name = buyer_form.cleaned_data['input_first_name']
            last_name = buyer_form.cleaned_data['input_second_name']
            phone = buyer_form.cleaned_data['input_phone']
            locality = buyer_form.cleaned_data['input_locality']
            street = buyer_form.cleaned_data['input_street']
            house = buyer_form.cleaned_data['input_house']
            apartments = buyer_form.cleaned_data['input_apartments']
            porch = buyer_form.cleaned_data['input_porch']
            floor = buyer_form.cleaned_data['input_floor']

            buyer = Buyer(
                user=request.user,
                first_name=first_name,
                last_name=last_name,
                phone=phone,
                locality=locality,
                street=street,
                house=house,
                apartments=apartments,
                porch=porch,
                floor=floor,
            )

            buyer.save()

        current_path = request.META['HTTP_REFERER']
        return redirect(current_path)
Exemple #2
0
def register(request):

    if request.method == 'POST':

        reg_form = RegistrationForm(request.POST)

        if reg_form.is_valid():

            userfirst_name = reg_form.cleaned_data['userfirst_name']
            userlast_name = reg_form.cleaned_data['userlast_name']
            companyname = reg_form.cleaned_data['companyname']
            usertel = reg_form.cleaned_data['usertel']
            username = reg_form.cleaned_data['username']
            useremail = reg_form.cleaned_data['useremail']
            userpassword = reg_form.cleaned_data['userpassword']
            userpassword_2 = reg_form.cleaned_data['userpassword_2']

            if userpassword == userpassword_2:
                if User.objects.filter(username=username).exists():
                    messages.info(request,
                                  'Пользователь с таким именем существует!!!')
                    return redirect('login_register')
                elif User.objects.filter(email=useremail).exists():
                    messages.info(request,
                                  'Пользователь с таким email существует!!!')
                    return redirect('login_register')
                else:
                    user = User.objects.create_user(username=username,
                                                    password=userpassword,
                                                    email=useremail)
                    user.save()

                    new_buyer = Buyer(user=user,
                                      first_name=userfirst_name,
                                      last_name=userlast_name,
                                      Phone=usertel,
                                      email=useremail,
                                      name=companyname)
                    new_buyer.save()

                    auth.login(request, user)

                    template_name = 'authapp/my-account.html'

                    return render(request, template_name,
                                  get_cart_header(request))
            else:
                messages.info(request, 'Пароли не совпадают!!!')
                return redirect('login_register')

    else:

        return redirect('login_register')
Exemple #3
0
def place_order(request):

    if request.method == 'POST':
        price_form = RegistrationForm(request.POST)
        if price_form.is_valid():

            userfirst_name = price_form.cleaned_data['userfirst_name']
            userlast_name = price_form.cleaned_data['userlast_name']
            companyname = price_form.cleaned_data['companyname']
            useremail = price_form.cleaned_data['useremail']
            usertel = price_form.cleaned_data['usertel']

            new_order = Order()
            if request.user.is_authenticated:

                buyer = Buyer.objects.filter(user=request.user).first()
                if buyer is not None:
                    new_order.buyer = buyer
                else:
                    buyer = Buyer(first_name=userfirst_name,
                                  last_name=userlast_name,
                                  Phone=usertel,
                                  email=useremail)
                    buyer.user = request.user
                    buyer.save()
                    new_order.buyer = buyer
            else:
                buyer = Buyer(first_name=userfirst_name,
                              last_name=userlast_name,
                              Phone=usertel,
                              email=useremail)
                buyer.save()
                new_order.buyer = buyer

            cart = get_cart(request)

            new_order.summ = cart.summ
            new_order.save()

            for cart_item in Cart_Item.objects.all().filter(cart=cart):
                order_item = Order_Item(order=new_order,
                                        good=cart_item.good,
                                        quantity=cart_item.quantity,
                                        price=cart_item.price,
                                        summ=cart_item.summ)
                order_item.save()

            cart.delete()

            return HttpResponse('{}{}'.format(userfirst_name, userlast_name))
Exemple #4
0
def profile_add(request):

    if request.method == 'POST':

        buyer_form = BuyerSaveForm(request.POST)

        if buyer_form.is_valid():

            first_name = buyer_form.cleaned_data['input_first_name']
            last_name = buyer_form.cleaned_data['input_second_name']
            phone = buyer_form.cleaned_data['input_phone']

            buyer = Buyer(
                user=request.user,
                first_name=first_name,
                last_name=last_name,
            )

            buyer.save()

        current_path = request.META['HTTP_REFERER']
        return redirect(current_path)
Exemple #5
0
def get_price(request):
	if request.method == 'POST':
		price_form = GetPriceForm(request.POST)
		if price_form.is_valid():


			userfirst_name 	= price_form.cleaned_data['userfirst_name']
			userlast_name 	= price_form.cleaned_data['userlast_name']
			companyname 	= price_form.cleaned_data['companyname']
			useremail 		= price_form.cleaned_data['useremail']
			usertel 		= price_form.cleaned_data['usertel']
			usercomment 	= price_form.cleaned_data['usercomment']

			new_buyer		= Buyer(first_name=userfirst_name, last_name=userlast_name, Phone=usertel, email=useremail)
			new_buyer.save()

			send_price(request, useremail)


			return render(request, 'baseapp/get_price.html')

		else:

			return redirect('show_index')
Exemple #6
0
def order_add(request):
	
	if request.method == 'POST':

		buyer_form = BuyerSaveForm(request.POST)

		if buyer_form.is_valid():

			first_name 		= buyer_form.cleaned_data['input_first_name']
			last_name		= buyer_form.cleaned_data['input_second_name']
			phone 			= buyer_form.cleaned_data['input_phone']
			locality  		= buyer_form.cleaned_data['input_locality']
			street  		= buyer_form.cleaned_data['input_street']
			house  			= buyer_form.cleaned_data['input_house']
			apartments  	= buyer_form.cleaned_data['input_apartments']
			porch  			= buyer_form.cleaned_data['input_porch']
			floor 			= buyer_form.cleaned_data['input_floor']
			input_cook_time = buyer_form.cleaned_data['input_cook_time']
			input_time 		= buyer_form.cleaned_data['input_time']
			input_email 	= buyer_form.cleaned_data['input_email']
			quantity 		= buyer_form.cleaned_data['quantity']
			comment 		= buyer_form.cleaned_data['comment']
			good_id 		= buyer_form.cleaned_data['good_id']
			input_location 	= buyer_form.cleaned_data['input_location']

			if street:
				address =  "{}, {} ул., д. {}, кв. {}, подъезд {}, этаж {}".format(locality, street, house, apartments, porch, floor)
			else:
				if input_location == '1':

					address = "Самовывоз - ул. Костюкова 36Г, Белгород"

				elif input_location == '2':

					address = "Самовывоз - ул. Левобережная 22А, Белгород"

	
			try:

				if request.user.is_authenticated:
				
					buyer = Buyer.objects.get(user = request.user)

				else:
					
					buyer = None	

			except Buyer.DoesNotExist:
				
				buyer = Buyer(
				user = request.user,
				first_name = first_name,
				last_name = last_name, 
				phone = phone,
				email = input_email,
				locality = locality,
				street = street, 
				house = house,
				apartments = apartments,
				porch = porch,
				floor = floor,

				)

				buyer.save()


			if buyer:

				new_order = Order(
					first_name=first_name, 
					last_name=last_name, 
					phone=phone, 
					buyer=buyer, 
					email = input_email,
					address = address,
					cook_time= "{}".format(str(input_time) if input_cook_time=="by_time" else "Как можно скорее"),
					comment=comment,
						)

			else:

				new_order = Order(
					first_name=first_name, 
					last_name=last_name, 
					phone=phone, 
					address = address,
					email = input_email,
					cook_time= "{}".format(str(input_time) if input_cook_time=="by_time" else "Как можно скорее"),
					comment=comment,
					)

			new_order.save()

			if good_id == 'lunch' :

				set_lunch_good = Good.objects.filter(name="Дружеский обед").first()

				order_item = Order_Item(

					order = new_order,
					good = set_lunch_good,
					quantity = Decimal(quantity),
					price = set_lunch_good.price,
					summ = set_lunch_good.price*Decimal(quantity),

					)
				order_item.save()

			elif good_id == 'gift' :

				gift_good = Good.objects.filter(name="Подарочная коробка").first()

				order_item = Order_Item(

					order = new_order,
					good = gift_good,
					quantity = Decimal(quantity),
					price = gift_good.price,
					summ = gift_good.price*Decimal(quantity),

					)
				order_item.save()


			else:	
				cart_items = Cart_Item.objects.filter(cart=get_cart(request))

				for item in cart_items:

					order_item = Order_Item(

						order = new_order,
						good = item.good,
						quantity = item.quantity,
						price = item.price,
						summ = item.summ,

						)
					order_item.save()

				cart_to_clear = get_cart(request)

				cart_items_to_delete = Cart_Item.objects.filter(cart=cart_to_clear)

				for item in cart_items_to_delete:

					item.delete()

				cart_to_clear.summ = 0
				cart_to_clear.save()
				
				send_mail_to_buyer(new_order.id, input_email)

			send_mail_on_bar(new_order.id)

			context = {

				'order': new_order, 'order_items': Order_Item.objects.filter(order=new_order),
				'cart': get_cart(request),
				'cart_count' : Cart_Item.objects.filter(cart=get_cart(request)).aggregate(Sum('quantity'))['quantity__sum'],
				'in_bar': get_in_barrels(),
				'wishlist_count' : len(Wishlist_Item.objects.filter(wishlist=get_wishlist(request))), 

				}

			return render(request, 'orderapp/order_created.html', context)