Skip to content

Commit

Permalink
模板数据绑定完善
Browse files Browse the repository at this point in the history
  • Loading branch information
HZreal committed Sep 1, 2021
1 parent 89bbccc commit 404233c
Show file tree
Hide file tree
Showing 13 changed files with 564 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from ronglian_sms_sdk import SmsSDK

# accId = '容联云通讯分配的主账号ID'
Expand Down
4 changes: 2 additions & 2 deletions meiduo_mall/meiduo_mall/apps/carts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def post(self, request):
if user.is_authenticated: # 已登录返回True,操作redis购物车
redis_conn = get_redis_connection('carts')
pl = redis_conn.pipeline()
# 数据sku_id, count用harh类型存储
# 数据sku_id, count用harsh类型存储
# 查询key记录,sku_id存在则原count与当前所传count相加,不存在则count为当前所传值,hincrby方法已封装此逻辑,直接调用
pl.hincrby('carts_%s' % user.id, sku_id, count)
# 勾选状态selected用set类型存储
Expand Down Expand Up @@ -79,7 +79,7 @@ def post(self, request):
origin_count = cart_dict[sku_id]['count']
count += origin_count

# 无论sku存在只需修改count,sekected,还是不存在需要添加新数据sku_id,count,selected到购物车,都可以统一化处理为:重写购物车字典数据
# 无论sku存在只需修改count, selected,还是不存在需要添加新数据sku_id,count,selected到购物车,都可以统一化处理为:重写购物车字典数据
cart_dict[sku_id] = {
'count': count,
'selected': selected,
Expand Down
2 changes: 1 addition & 1 deletion meiduo_mall/meiduo_mall/apps/orders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def post(self, request):
new_sales = origin_sales + sku_count
# 采用乐观锁:以原始值为条件更新数据库数据,若因并发,原始值被修改过,则返回0表示有资源抢夺,更新数据失败
result = SKU.objects.filter(id=sku_id, stock=origin_stock).update(stock=new_stock, sales=new_sales)
if result ==0:
if result == 0:
# return http.JsonResponse('下单失败')
# 库存10 A用户要买1 但此时下单有B用户资源抢夺买2 即使B下单完成库存依然对A足够 不能因为B的抢夺而告知A下单失败,而是让A再去下单,直至库存不足

Expand Down
4 changes: 2 additions & 2 deletions meiduo_mall/meiduo_mall/apps/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ def get(self, request):


# 用户中心:需要验证用户登入才可进入(有多种方式,其他方式写在utils.view里)
# 方式一:继承父类LoginRequiredMixin
# 方式一:继承父类LoginRequiredMixin(auth子应用)
# LoginRequiredMixin类定义了dispatch方法,实现了is_authenticated认证以及调用super().dispatch()
# 通过as_view()原理可知,优先调用LoginRequiredMixin的dispatch方法,然后调用View类的dispatch()方法进入到UserInfoView实例的get()
# 通过as_view()原理可知,优先调用LoginRequiredMixin的dispatch方法,然后调用View类的dispatch()方法分发进入到UserInfoView实例的get()
# 因此用户未认证会被LoginRequiredMixin类的dispatch方法引导到handle_no_permission()进行处理,即不会进入此视图类,但是会被重定向到LOGIN_URL指定的地址(通常是登录页面),当用户完成登录又重定向到next,可回到此类视图UserInfoView
class UserInfoView(LoginRequiredMixin, View):
# 提供用户中心页面
Expand Down
Loading

0 comments on commit 404233c

Please sign in to comment.