예제 #1
0
def promotion_detail_groups_ajax(request,pk,*kwargs):
	json = MyJson(request)
	try:
		
		promotion = Promotion.objects.get(pk=pk)
		user = Login(request).getUser()
		inPromotion = promotion.userInPromotion(user)
		friendsInPromotion = []
		if inPromotion:
			friendsInPromotion = user.promotion_group_users.get(promotion=promotion).users.exclude(user=user).all()
		
		data = render(request, 'facebook/promotion/tab_groups.html', {
					'promotion': promotion,
					'product': promotion.product,
					'retailer': promotion.retailer,
					'inPromotion':inPromotion,
					'friendsInPromotion':friendsInPromotion,
					'friendsNeed':promotion.elements_number-1-len(friendsInPromotion)
				},
				).content
		json.setOk()
		json.addData(data)
	except Exception,e:
		json.setError()
		json.addError(str(e))
예제 #2
0
def promotion_detail_groups_create_ajax(request,pk,*kwargs):
	json = MyJson(request)
	try:
		promotion = Promotion.objects.get(pk=pk)
		if not promotion.promotionIsActive():
			raise Exception('Promotion is not active')
		user = Login(request).getUser()
		groups = promotion.promotionGroups.filter(users__in = [user])
		for g in groups.all():
			if g.win_date is None and g.active:
				g.users.remove(user)
			else:
				raise Exception('You are in a group that wins the promotion or the promotion is not active')
		pg,c = PromotionGroup.objects.get_or_create(user = user, promotion = promotion)
		if c:
			pg.save()
		pg.users.add(user)
		pg.postSave()
		
		data = {}
		json.addData(data)
		json.addMessage('You create a group with successfull')
		json.setOk()
	except Exception,e:
		json.setError()
		json.addError(str(e))
예제 #3
0
def promotion_detail_groups_join_ajax(request,pk,*kwargs):
	json = MyJson(request)
	try:
		promotion = Promotion.objects.get(pk=pk)
		if not promotion.promotionIsActive():
			raise Exception('Promotion is not active')
		
		user = Login(request).getUser()
		
		if 'group' not in request.POST:
			raise Exception('Group don\'t exists')
		#user.promotions = 
		group_id = int( request.POST.get('group',None) )
		print group_id
		groups = promotion.promotionGroups.filter(users__in = [user])
		for g in groups.all():
			if g.win_date is None and g.active:
				g.users.remove(user)
			else:
				raise Exception('You are in a group that wins the promotion or the promotion is not active')
		
		pg = PromotionGroup.objects.get(promotion = promotion, pk=group_id,active=True,win_date__exact = None)
		pg.users.add(user)
		pg.postSave()
		data = {}
		json.addData(data)
		json.addMessage('You join with successfull')
		json.setOk()
	except Exception,e:
		json.setError()
		json.addError(str(e))
예제 #4
0
def wishlist(request,product_pk,*kwargs):
	json = MyJson(request)
	try:
		product = Product.objects.get(pk= int(product_pk) )
	except Exception,e:
		json.setError()
		json.addError('Product don\'t exit.')
예제 #5
0
def promotions(request,product_pk,retailer_pk,*kwargs):
	json = MyJson(request)
	promotions = []
	product = None
	retailer = None
	if product_pk is not None:
		try:
			product = Product.objects.get(pk= int(product_pk) )
			promotions =  product.promotion_set.all()
			
		except Exception,e:
			json.setError()
			json.addError('Product don\'t exist.')
예제 #6
0
					except Exception,e:
							pass
			wishlist = user.wishlist_set.all()
			for w in wishlist:
				w.hasProduct = w.products.filter(pk=product.pk).exists()
			
			data = render(request,'facebook/ajax/wishlists.html',{
				'wishlists':wishlist,
				'wishlistform':wishlistform,
				'product':product,
			} ).content
			json.setOk()
			json.addData(data)
		except Exception,e:
			json.setError()
			json.addError(str(e))
	return json.getJsonRequest()


@access_required_ajax
def promotions(request,product_pk,retailer_pk,*kwargs):
	json = MyJson(request)
	promotions = []
	product = None
	retailer = None
	if product_pk is not None:
		try:
			product = Product.objects.get(pk= int(product_pk) )
			promotions =  product.promotion_set.all()
			
		except Exception,e: