Example #1
0
def merchant_offer_home(request, days= "7"):
	u = request.user
	
	try:

		try:
			page = int(request.GET.get("page"))
		except Exception , e:
			page = 1

		merchant = u.shoppleyuser.merchant
		total_stats = [(i.num_init_sentto, i.offercode_set.filter(forwarder__isnull=False).count(), i.offercode_set.filter(redeem_time__isnull=False).count()) for i in merchant.offers_published.all()]

		days_ago = get_days_ago(days)	
		offercodes = OfferCode.objects.filter(Q(offer__merchant = merchant), Q(offer__time_stamp__gt=days_ago))
		unique_customers = offercodes.values("customer").distinct()
		total_forwards =offercodes.filter(forwarder__isnull=False).count()
		total_redeemed = offercodes.filter(redeem_time__isnull=False).count()
		total_sent = merchant.offers_published.aggregate(Sum('num_init_sentto'))
		past_offers = merchant.offers_published.filter(expired_time__lt=datetime.now())
		current_offers = merchant.offers_published.filter(expired_time__gt=datetime.now())
		scheduled_offers = merchant.offers_published.filter(time_stamp__gt=datetime.now())

		paginator = Paginator(past_offers, 10)
		total_pages = paginator.num_pages
		
		try:
			offer_list= paginator.page(page)
		except PageNotAnInteger:
			offer_list = paginator.page(1)
		except EmptyPage:
			offer_list = paginator.page(total_pages)

		return render_to_response("offer/merchant_offer_home.html",
					{
						"all_offers": merchant.offers_published.all(),
						"past_offers": offer_list,
						"current_offers": current_offers,
						"scheduled_offers": scheduled_offers,
						"total_forwards": total_forwards,
						"total_redeemed": total_redeemed,
						"total_sent": total_sent,
						"balance": merchant.balance,
						"biz_name": merchant.business_name,
						},
                                                context_instance=RequestContext(request))
Example #2
0
def customer_offer_home(request, days = "7"):
	u = request.user
	try:
		try:
			page = int(request.GET.get("page"))
		except Exception , e:
			page = 1
		customer = u.shoppleyuser.customer
		days_ago = get_days_ago(days)
		all_active_offers = Offer.objects.filter(expired_time__gt=datetime.now())
		all_exp_offers = Offer.objects.filter(expired_time__lt=datetime.now())

		rcv_offercodes = customer.offercode_set.order_by("-redeem_time")
		rcv_active_offercodes = customer.offercode_set.filter(expiration_time__gt=datetime.now()).order_by("-redeem_time")
		other_active_offers = all_active_offers.exclude(pk__in =customer.offercode_set.all())
		used_offercodes = customer.offercode_set.order_by("-redeem_time").filter(redeem_time__isnull=False)
		exp_rcv_offercodes = customer.offercode_set.filter(expiration_time__lt=datetime.now()).order_by("-expiration_time")

		paginator = Paginator(other_active_offers, 10)
		total_pages = paginator.num_pages

		try:
			offer_list= paginator.page(page)
		except PageNotAnInteger:
			offer_list = paginator.page(1)
		except EmptyPage:
			offer_list = paginator.page(total_pages)


		return render_to_response("offer/customer_offer_home.html", 
						{
							"used_offercodes": used_offercodes,
							"rcv_offercodes": rcv_offercodes,
							"other_active_offers": offer_list,
							"total_points": customer.balance,
							"daily_limits": customer.daily_limit,
							"num_used_offercodes": used_offercodes.count(),
							"num_rcv_offercodes": rcv_offercodes.count() ,
							"num_exp_rcv_offercodes": exp_rcv_offercodes.count(),
							"page": page,
							"total_pages": total_pages,
							
							
						},
                                                context_instance=RequestContext(request))