예제 #1
0
@access_required
def detail(request,pk,*kwargs):	
	try:
		object = Product.objects.get(pk=pk)
	except Exception,e:
		return redirect('products-list')
	user = Login(request).getUser()
	promotions =  object.promotion_set.all()
	wish = WishList(user = user)
	#wish.products = [object]
	wishlistform = WishListProductForm(instance = wish )
	
	if request.POST:
		if 'action' in request.POST and request.POST.get('action','') == 'create_wishlist':
			wishlistform = WishListProductForm(request.POST,instance = wish )
			if wishlistform.is_valid():
				wish = wishlistform.save()
				wish.products = [object]
	
	
	return render(request, 'facebook/product_detail.html', {
		'object': object,
		'promotions':map(lambda x: x.getPromotionInfo(user), promotions),
		'wishlists':user.wishlist_set.all(),
		'wishlistform':wishlistform,
	},)

	
	
	return redirect('product-detail',pk = pk )
예제 #2
0
		product = Product.objects.get(pk= int(product_pk) )
	except Exception,e:
		json.setError()
		json.addError('Product don\'t exit.')
		
	if not json.isError():
		user = Login(request).getUser()
		wish = WishList(user = user)
		try:
			wishlistform = WishListProductForm(instance = wish )
			if request.POST:
				if 'action' in request.POST and request.POST.get('action','') == 'create_wishlist':
					wishlistform = WishListProductForm(request.POST,instance = wish )
					if wishlistform.is_valid():
						wish = wishlistform.save()
						wish.products = [product]
				if 'pk' in request.POST and request.POST.get('pk',None) is not None:
					try:
						if 'action' in request.POST and request.POST.get('action','') == 'wishlist_remove':
								user.wishlist_set.get(pk= request.POST.get('pk',None) ).delete()
							
						if 'action' in request.POST and request.POST.get('action','') == 'wishlist_remove_product':
								user.wishlist_set.get(pk= request.POST.get('pk',None) ).products.remove(product)
	
						if 'action' in request.POST and request.POST.get('action','') == 'wishlist_add_product':
								user.wishlist_set.get(pk= request.POST.get('pk',None) ).products.add(product)

					except Exception,e:
							pass
			wishlist = user.wishlist_set.all()
			for w in wishlist: