Skip to content

Commit 724c289

Browse files
Messaging Framewok Has Been Tested Successfully
1 parent 80de853 commit 724c289

File tree

7 files changed

+80
-17
lines changed

7 files changed

+80
-17
lines changed

Amazon/settings.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878

7979
# User-Feedback
8080
'tellme',
81+
82+
83+
#Mobile Authentication
84+
"phone_verify",
85+
86+
'rest_framework'
8187
]
8288

8389
# Site Id
@@ -243,7 +249,7 @@
243249
integrations=[DjangoIntegration()],
244250
traces_sample_rate=1.0,
245251

246-
# If you wish to associate users to errors (assuming you are using
252+
# to associate users to errors (assuming you are using
247253
# django.contrib.auth) you may enable sending PII data.
248254
send_default_pii=True
249255
)
@@ -258,3 +264,23 @@
258264

259265
# Adding Extra Data To Notification
260266
DJANGO_NOTIFICATIONS_CONFIG = {'USE_JSONFIELD': True}
267+
268+
269+
270+
271+
# In settings.py
272+
# Add settings for phone_verify to work
273+
PHONE_VERIFICATION = {
274+
"BACKEND": "phone_verify.backends.twilio.TwilioBackend",
275+
"OPTIONS": {
276+
"SID": "ACdb84efb2452409796286622b88ad1abd",
277+
"SECRET": "d6b1fcb0e949a5a936ade03a0c3f1f9a",
278+
"FROM": "+15052786084",
279+
"SANDBOX_TOKEN": "123456",
280+
},
281+
"TOKEN_LENGTH": 6,
282+
"MESSAGE": "Welcome to Amazon! Please use security code {security_code} to proceed.",
283+
"APP_NAME": "Phone Verify",
284+
"SECURITY_CODE_EXPIRATION_TIME": 3600, # In seconds only
285+
"VERIFY_SECURITY_CODE_ONLY_ONCE": False, # If False, then a security code can be used multiple times for verification
286+
}

Amazon/urls.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
handler404 = 'Home.views.error404handler'
3131

3232

33+
3334
# Sitemap Integration
3435
sitemaps = {
3536
'static': StaticViewSitemap,
@@ -61,5 +62,12 @@
6162
# User Feedback
6263
path('tellme/', include("tellme.urls")),
6364

65+
path('api/', include('phone_verify.urls'))
66+
67+
68+
69+
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
70+
71+
6472

65-
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
73+
#Phone Registration

Shop/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Product(models.Model):
2828
main_banner = models.ImageField(upload_to="Shop/images", default=None)
2929
pub_date = models.DateField()
3030

31+
3132
def __str__(self):
3233
return self.name
3334

Shop/views.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,24 @@
1515
@login_required(login_url="/account/login")
1616
def cart_add(request, id):
1717
cart = Cart(request)
18-
product = Product.objects.get(id=id)
19-
cart.add(product=product)
18+
19+
#Getting The Values
20+
if request.method == 'POST':
21+
global product, color, size, quantity
22+
product = Product.objects.get(id=id)
23+
color = request.POST['color']
24+
size = request.POST['size']
25+
quantity = request.POST['quantity']
26+
27+
#Adding the products in cart
28+
cart.add(product=product, color=color, size=size, quantity=int(quantity))
29+
30+
#Sending Action and Notification To The User
2031
action.send(request.user, verb="Product Has Been Added",
21-
description=f"The User {request.user} has added the product {product} in his cart", action_object=product)
32+
description=f"The User {request.user} has added the product {product} in his cart of the color {color} and size of {size} and quantity of {quantity}", action_object=product)
2233
notify.send(request.user, verb="Product Has Been Added In Your Cart",
2334
recipient=request.user, level="success", action_object=product, description=f"The User {request.user} has added the product {product} in his cart")
24-
print(request.user.notifications.unread())
35+
2536
return redirect("Home")
2637

2738

@@ -74,7 +85,7 @@ def cart_detail(request):
7485
filtering_history = Action.objects.filter(actor_object_id=request.user.id, verb="User Has Viewed Product").order_by('timestamp')[:3]
7586
for items in filtering_history:
7687
prods.add(items.action_object_object_id)
77-
user_history = Product.objects.filter(id__in = prods)
88+
user_history = Product.objects.filter(id__in = prods)[::-1]
7889

7990
#Context Used In Template
8091
params = {'userHistory' : user_history}

cart/cart.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, request):
1515
cart = self.session[settings.CART_SESSION_ID] = {}
1616
self.cart = cart
1717

18-
def add(self, product, quantity=1, action=None):
18+
def add(self ,product, quantity, size, color, action=None):
1919
"""
2020
Add a product to the cart or update its quantity.
2121
"""
@@ -27,17 +27,20 @@ def add(self, product, quantity=1, action=None):
2727
'userid': self.request.user.id,
2828
'product_id': id,
2929
'name': product.name,
30-
'quantity': 1,
30+
'quantity': quantity,
3131
'price': str(product.price),
32-
'image': product.image.url
33-
}
32+
'image': product.image.url,
33+
'brand':product.brand,
34+
'size':size,
35+
'color': color,
36+
}
3437
else:
3538
newItem = True
3639

3740
for key, value in self.cart.items():
3841
if key == str(product.id):
3942

40-
value['quantity'] = value['quantity'] + 1
43+
value['quantity'] = value['quantity'] + quantity
4144
newItem = False
4245
self.save()
4346
break
@@ -47,9 +50,13 @@ def add(self, product, quantity=1, action=None):
4750
'userid': self.request,
4851
'product_id': product.id,
4952
'name': product.name,
50-
'quantity': 1,
53+
'quantity': quantity,
5154
'price': str(product.price),
52-
'image': product.image.url
55+
'image': product.image.url,
56+
'brand':product.brand,
57+
'size':size,
58+
'color': color,
59+
5360
}
5461

5562
self.save()

templates/Shop/cart.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,15 @@ <h1 class="cart__head" style="margin-bottom: 15px">Shopping Cart</h1>
249249
<span class="hero__seller">By Amazon</span>
250250
<span class="stock__status green">In stock</span>
251251
<span class="hero__quantity">
252-
<span class="hero__q__label">Quantity : {{value.quantity}} </span>
252+
<span class="hero__q__label">Quantity : {{value.quantity}} | Color : {{value.color}} |
253+
Size : {{value.size}}
254+
</span>
255+
256+
</span>
257+
253258

254259
</span>
255-
<span class="cart__ins"><a href="#" class="card-shop-link" style="font-size: 12px;">Delete</a></span>
260+
<span class="cart__ins"><a href="{% url 'item_clear' value.product_id %}" class="card-shop-link" style="font-size: 12px;">Delete</a></span>
256261
<span class="cart__ins" style="padding-left: 10px;"><a href="#" class="card-shop-link" style="font-size: 12px;">Save for later</a></span>
257262
</div>
258263
<div class="hero__price">

templates/home/product.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ <h1 class="he__contain">{{products.name}}</h1>
621621
<div class="prduct__section__count">
622622
<span class="dropdpwn__product">
623623
<label for="quantity">Qty: </label>
624+
<form method="POST" action="{% url 'cart_add' products.id %}">
625+
{% csrf_token %}
624626
<select name="quantity" id="product__countselect">
625627
<option value="1" selected="">1</option>
626628
<option value="2">2</option>
@@ -633,7 +635,10 @@ <h1 class="he__contain">{{products.name}}</h1>
633635
</div>
634636
<span class="buy__cart__button">
635637
<div class="product" style="margin: 0;padding: 0;">
636-
<button id="pr{{products.id}}" class="cart" style="margin-bottom: 10px;"><a href="{% url 'cart_add' products.id %}">Add To Cart</a></button>
638+
<input type="hidden" name="color" value="white">
639+
<input type="hidden" name="size" value="Extra-Large">
640+
<button id="pr{{products.id}}" class="cart" style="margin-bottom: 10px;" type="submit">Add To Cart</button>
641+
</form>
637642
<button
638643
style="margin-top: 0px !important;background: linear-gradient(to bottom,#f6c88f,#ed9220);margin-bottom: 10px;">Buy
639644
Now</button>

0 commit comments

Comments
 (0)