def get_group_info(request, id=None): result_dict = {} result_dict['success'] = False result_dict['message'] = '' result_dict['data'] = {} try: group = Attribute_Group.objects.get(id=id) except Exception as err: logger.error('Can not find attribute_group which id is %s.' % id) result_dict['message'] = _('找不到属性组信息,可能已经被删除了,请重试。') return JsonResponse(result_dict) from shopcart.serializer import serializer attributes = {} for att in group.attributes.all(): logger.debug("att:%s" % att.name) serialized_attr = serializer(att, datetime_format='string', output_type='dict') attributes[att.code] = serialized_attr result_dict['data']['items'] = attributes serialized_group = serializer(group, datetime_format='string', output_type='dict') result_dict['data']['group'] = serialized_group result_dict['success'] = True return JsonResponse(result_dict)
def get_group_info(request,id=None): result_dict = {} result_dict['success'] = False result_dict['message'] = '' result_dict['data'] = {} try: group = Attribute_Group.objects.get(id=id) except Exception as err: logger.error('Can not find attribute_group which id is %s.' % id) result_dict['message'] = _('找不到属性组信息,可能已经被删除了,请重试。') return JsonResponse(result_dict) from shopcart.serializer import serializer attributes = {} for att in group.attributes.all(): logger.debug("att:%s"%att.name) serialized_attr = serializer(att,datetime_format='string',output_type='dict') attributes[att.code] = serialized_attr result_dict['data']['items'] = attributes serialized_group = serializer(group,datetime_format='string',output_type='dict') result_dict['data']['group'] = serialized_group result_dict['success'] = True return JsonResponse(result_dict)
def view_cart(request): if 'cart_id' in request.COOKIES: cart_id = request.COOKIES["cart_id"] cart, created = Cart.objects.get_or_create(id=cart_id) else: if request.user.is_authenticated(): cart, object = Cart.objects.get_or_create(user=request.user) else: cart = Cart.objects.create(user=None) if request.is_ajax(): ret_dict = {} ret_dict['success'] = True ret_dict['item_type_count'] = cart.cart_products.all().count() from shopcart.serializer import serializer # serialized_cart = serializer(cart,datetime_format='string',output_type='dict',many=True) # 先不返回购物车中商品信息 serialized_cart = serializer(cart, datetime_format='string', output_type='dict', many=False) # logger.debug(serialized_cart) ret_dict['cart'] = serialized_cart return JsonResponse(ret_dict) else: ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'My Cart' if request.method == 'GET': ctx['cart'] = cart response = TemplateResponse(request, System_Config.get_template_name() + '/cart_detail.html', ctx) response.set_cookie('cart_id', cart.id, max_age=3600 * 24 * 365) return response
def address_detail(request,address_id): ctx = {} result_dict = {} result = False if request.method=='GET': try: address = Address.objects.get(user=request.user,id=address_id) from shopcart.serializer import serializer serialized_address = serializer(address,datetime_format='string',output_type='dict') #serialized_address = serialized_address.replace('\n','').replace('\\"','"') logger.debug(serialized_address) result_dict['address'] = serialized_address result = True except Exception as err: logger.error('Can not find the address which id is %s and user is %s .' % (address_id,request.user.email)) logger.error(str(err)) result_dict['success'] = result #return HttpResponse(serializer(result,datetime_format='string',output_type='json')) return JsonResponse(result_dict)
def view_cart(request): if 'cart_id' in request.COOKIES: cart_id = request.COOKIES["cart_id"] cart,created = Cart.objects.get_or_create(id=cart_id) else: if request.user.is_authenticated(): cart,object = Cart.objects.get_or_create(user=request.user) else: cart = Cart.objects.create(user=None) if request.is_ajax(): ret_dict = {} ret_dict['success'] = True ret_dict['item_type_count'] = cart.cart_products.all().count() from shopcart.serializer import serializer #serialized_cart = serializer(cart,datetime_format='string',output_type='dict',many=True) #先不返回购物车中商品信息 serialized_cart = serializer(cart,datetime_format='string',output_type='dict',many=False) #logger.debug(serialized_cart) ret_dict['cart'] = serialized_cart return JsonResponse(ret_dict) else: ctx = {} ctx['system_para'] = get_system_parameters() ctx['menu_products'] = get_menu_products() ctx['page_name'] = 'My Cart' if request.method =='GET': ctx['cart'] = cart response = render(request,System_Config.get_template_name() + '/cart_detail.html',ctx) response.set_cookie('cart_id',cart.id ,max_age = 3600*24*365) return response
def address_detail(request, address_id): ctx = {} result_dict = {} result = False if request.method == 'GET': try: address = Address.objects.get(user=request.user, id=address_id) from shopcart.serializer import serializer serialized_address = serializer(address, datetime_format='string', output_type='dict') #serialized_address = serialized_address.replace('\n','').replace('\\"','"') logger.debug(serialized_address) result_dict['address'] = serialized_address result = True except Exception as err: logger.error( 'Can not find the address which id is %s and user is %s .' % (address_id, request.user.email)) logger.error(str(err)) result_dict['success'] = result #return HttpResponse(serializer(result,datetime_format='string',output_type='json')) return JsonResponse(result_dict)