Exemplo n.º 1
0
Arquivo: views.py Projeto: shredz/Tool
def dashboard(request):
	if request.user.is_authenticated():
		params = {}
		
		params["user"] = User.instance(request.user)
	
		#1- activities chart
		params["activities"]	=	Activity.chart(params["user"],5)
		
		#2- my deals [deals he is interested in]
		params["mydeals"] =	UserDeal.objects.filter(user=params["user"]).extra(order_by=['-added'])[:5]
		
		#3- friends
		params["friends"] = params["user"].friends
		
		#4- recent activities
		params["recent_points"] = Activity.recent(params["user"],5)
		
		
		#-5 rewards
		
		
		#-6 invite
		params["iform"] = InvitationForm()
		
		
		
		
		
		return Response.render("members/dashboard.html",params,request)
	else:
		return Response.send_to_login(request)
Exemplo n.º 2
0
Arquivo: views.py Projeto: shredz/Tool
def login (request):	
	if request.user.is_authenticated():
		return HttpResponseRedirect('/members/')
	
	if request.method == 'POST': 
		form = LoginForm(request.POST)
		if form.is_valid():
			username 				= form.cleaned_data['username']
			password				= form.cleaned_data['password']
			
			user = authenticate(username=username, password=password)
			
			if user is None:
				form.errors["username"]	= ErrorList([u'Invalid Username or Password'])
			else:
				s_user = User.objects.get(id=user.id)
				if s_user.verification.verified == False:
					form.errors["username"]	= ErrorList([u'User must be verified first due to "%s"' % (s_user.verification.purpose)])
				elif user.is_active:
					userlogin(request,user)
					return Response.send_to_destination(request)
				else:
					form.errors["username"]	= ErrorList([u'Account Disabled'])
	else:
		form = LoginForm()
		
	return Response.render_form (request,'members/login.html',form)
Exemplo n.º 3
0
Arquivo: views.py Projeto: shredz/Tool
def share_deal(request,deal_id):
	if not request.user.is_authenticated():
		return Response.send_to_login(request)
	
	user = User.instance(request.user)
	facebook = Account.get_for_user(user,"facebook")
	
	if not facebook:
		return HttpResponse("Not connected TO facebook YET")
		
	
	try:
		deal = Deal.objects.get(id=deal_id)		
		deal = Deal.assign_left([deal])[0]
		deal.link = "http://ldev.spiffcity.com/spiffs/deal/"+str(deal.id)+"/"
		
		##TODO create activity to get points
		
		deal.shared(user)
		
		##
		
		return Response.render("spiffs/fbshare.html",{"deal":deal,"fb_api_key":settings.CRED['FACEBOOK_APP_ID'],"access_token":facebook.oauth_token},request)
		
		#fb = Facebook(settings.CRED['FACEBOOK_APP_ID'] ,settings.CRED['FACEBOOK_APP_SECRET'],settings.CRED['FACEBOOK_RETURN_URL'])
		#data = fb.share_deal(facebook, deal)
		#Response.html(data)
		#return Response.render("spiffs/deal.html",{"deal":deal},request)
		
	except Deal.DoesNotExist, dne :
		Response.not_found()
Exemplo n.º 4
0
Arquivo: views.py Projeto: shredz/Tool
def settings_view(request):
	if request.user.is_authenticated():
		if request.method == 'POST': 
			for cid in request.POST: 
				try:
					c = Config.objects.get(id=cid)
					c.value = request.POST[cid]
					c.save()
				except:
					pass
		
		configList = User.instance(request.user).get_all_config()
		
		clm 		= 1
		total_clm	= 2
		
		table = []
		row   = {}
		
		for title in configList:
			row[title] = configList[title]
			clm = clm + 1
			if clm > total_clm:
				table.append(row)
				row = {}
		
		table.append(row)
		
		c = {"table":table}
		
		c.update(csrf(request))	
		return Response.render("members/settings.html", c , request)
	else:
		return Response.send_to_login(request)
Exemplo n.º 5
0
Arquivo: views.py Projeto: shredz/Tool
def facebook_feed(request):
	f_acc = feed_account(request,"facebook")
	if f_acc is dict:
		return Response.json(f_acc)
	
	fb = Facebook(settings.CRED['FACEBOOK_APP_ID'] ,settings.CRED['FACEBOOK_APP_SECRET'],settings.CRED['FACEBOOK_RETURN_URL'])
	params = {"feed" : fb.news_feed(f_acc.oauth_token)}
	return Response.render_html("social/facebook_feed.html",params)
Exemplo n.º 6
0
Arquivo: views.py Projeto: shredz/Tool
def index(request):
	if not request.user.is_authenticated():
		return Response.send_to_login(request)
	
	user = User.instance(request.user)
	params = {"errors":[]}
	
	params["facebook"] = Account.get_for_user(user,"facebook")
	params["twitter"] = Account.get_for_user(user,"twitter")
		
	return Response.render("social/social.html",params,request)
Exemplo n.º 7
0
Arquivo: views.py Projeto: shredz/Tool
def twitter_feed(request):
	f_acc = feed_account(request,"twitter")
	if f_acc is dict:
		return Response.json(f_acc)
	
	twt = Twitter(settings.CRED['TWITTER_CONSUMER_KEY'] ,settings.CRED['TWITTER_CONSUMER_SECRET'],settings.CRED['TWITTER_RETURN_URL'])
	
	#return Response.json(twt.home_timeline(f_acc))
	
	params = {"feed":twt.home_timeline(f_acc)}
	return Response.render_html("social/twitter_feed.html",params)
Exemplo n.º 8
0
Arquivo: views.py Projeto: shredz/Tool
def like_deal(request,deal_id):
	if request.user.is_authenticated():
		user = User.instance(request.user)
		try:
			deal = Deal.objects.get(id=deal_id)
		except Deal.DoesNotExist, dne:
			return Response({"success":False,"message":"Deal does not exist"})
		try:
			ud = UserDeal.objects.get(deal=deal,user=user)
			return Response.json({"success":False,"message":"Already in my deals","at":str(ud.added)})
		except UserDeal.DoesNotExist,ex:
			ud = UserDeal(deal=deal,user=user)
			ud.save()
			return Response.json({"success":True,"message":"success added to my deals", "id":ud.id})
Exemplo n.º 9
0
Arquivo: views.py Projeto: shredz/Tool
def deals (request,page):
	if request.user.is_authenticated():
		user = User.instance(request.user)
		layout = user.get_config("Layout").value
	else:
		layout = 0
	
	deals, names = front_page(request, layout, "CJ" , int(page))	
	
	#return Response.html(len(deals))
	if len(deals) == 0:
		return Response.html("<!-- END -->")
	
	params = {'deals' :  deals , "names" : names,"layout":layout}
	return Response.render("spiffs/schemes/"+str(layout)+".html" , params,request)
Exemplo n.º 10
0
Arquivo: views.py Projeto: shredz/Tool
def verify(request,code):
	#http://localhost/members/v/yxdRRWPx22Fr/
	if request.user.is_authenticated():
		return HttpResponseRedirect('/members/')
		
	try:
		user = User.objects.get(verification=Verification.objects.get(code=code))
		if user.verification.purpose == "1" and user.verification.verified == False:
			user.verification.verified 		= True
			user.verification.verified_on 	= datetime.datetime.now()
			user.verification.save()
			
			user.is_active 					= True	
			user.is_staff					= True
			user.save()
			
			try:
				ref = Referral.objects.get(reffered_to=user)
				inv = Invitation.objects.get(sender=ref.reffered_by)
				inv.status = 'VERIFIED'
				inv.save()
			except:
				pass
			
		return Response.send_to_login(request,False)
	
	except Exception,e:
		return HttpResponse(e)
Exemplo n.º 11
0
Arquivo: views.py Projeto: shredz/Tool
def profile(request):
	if not request.user.is_authenticated():
		return Response.send_to_login(request)
	
	param = {}
	try:
		param['needs_username_correction'] = request.session['needs_username_correction']
	except Exception,ex:
		param['needs_username_correction'] = False
Exemplo n.º 12
0
Arquivo: views.py Projeto: shredz/Tool
def new_deals(request,page):	
	new_deals	 = Deal.objects.list_new(int(page) , 20)
	
	left = new_deals[0:10]
	right = new_deals[10:20]
	
	#Response.html(len(new))
	
	return Response.render("spiffs/new_deals.html" , {"deals": [left , right] , "page" : page , "nextpage" : int(page) + 1 },request)
Exemplo n.º 13
0
Arquivo: views.py Projeto: shredz/Tool
def deal(request,deal_type,deal_id):
	try:
		if deal_type == "CJ":
			deal = CDeal.objects.get(id=deal_id)
			#TRACKING = "&sid=%s" % (request.user.id)
			
		elif deal_type == "LS":
			deal = LDeal.objects.get(id=deal_id)
			#TRACKING = "&u1=%s" % (request.user.id)
			
		else:
			deal = Deal.objects.get(id=deal_id)
			#TRACKING = "&u1=%s&sid=%s" % (request.user.id, request.user.id)
		
		
		deal.purchase_url  = "/spiffs/v/%s/%s/" % (deal_type, deal.id)
		deal.link = "http://dev.spiffcity.com/spiffs/deal/%s/%s/" % (deal_type, deal.id)
		return Response.render("spiffs/deal.html",{"deal":deal},request)
		
	except Deal.DoesNotExist, dne :
		Response.not_found()
Exemplo n.º 14
0
Arquivo: views.py Projeto: shredz/Tool
def invite(request):
	if not request.user.is_authenticated():
		return Response.send_to_login(request)
	
	message = None
	
	if request.method == 'POST': 
		form = InvitationForm(request.POST)
		if form.is_valid():	
			
			
			p = Prospect(
							email = form.cleaned_data['email'],
							first_name	= form.cleaned_data['first_name'],
							last_name = form.cleaned_data['last_name'],
							source	= "Invitation"
							)
			p.save()
			
			
			
			invitation = Invitation(			
						sender 		= User.instance(request.user),
						prospect 	= p
					)
			invitation.create_curl()
			invitation.save()
			invitation.sendmail()
		
			message = "An invitation has been sent to %s " % (p.email)
			form = InvitationForm()	
		else:
			pass
	else:
		form = InvitationForm()
	
	return Response.render ("members/invite.html",{"form" : form , "appId" : settings.CRED["FACEBOOK_APP_ID"], "message" : message},request)
Exemplo n.º 15
0
Arquivo: views.py Projeto: shredz/Tool
def visited(request, deal_type ,deal_id):
	if request.user.is_authenticated():
		uid = request.user.id
	else:
		uid = "0"
	
	
	deal = Deal.objects.get(id=deal_id)
	dv = DealVisit(
		user 	= uid,
		deal_id = deal_id
	)
	dv.save()
	
	if deal_type == "CJ":
		TRACKING = "&sid=%s" % (dv.id)
	elif deal_type == "LS":
		TRACKING = "&u1=%s" % (dv.id)		
	else:
		TRACKING = "&u1=%s&sid=%s" % (dv.id, dv.id)
		
	return Response.send_to(deal.purchase_url+TRACKING)
Exemplo n.º 16
0
Arquivo: views.py Projeto: shredz/Tool
def invitation_landing(request,invid,name):
	if request.user.is_authenticated():
		return HttpResponseRedirect('/members/')
		
	first_name = ""
	last_name = ""
	
	parts = name.split("/")
	if len(parts) == 1:
		first_name = parts[0]
	elif len(parts) > 1:
		first_name = parts[0]
		last_name = parts[1]
	try:	
		i = Invitation.objects.get(curl=invid)
	except:
		raise Http404()
	
	if i.prospect.first_name == first_name and i.prospect.last_name == last_name and (i.status == 'SENT' or i.status == 'VISITED'):
		form = SignupForm(
							{
								"email" 		: i.prospect.email,
								"first_name" 	: i.prospect.first_name,
								"last_name" 	: i.prospect.last_name,
							}
						)
		
		request.session["invitation"] = i.id
		
		i.status = 'VISITED'
		i.save()
		
		return Response.render_form(request,'members/signup.html',form,errors=False)
	else:
		raise Http404()
	
	#p  = Prospect.objects.get(id=invid,first_name=first_name,last_name=last_name,source="Invitation")
	
	return HttpResponse(i)
Exemplo n.º 17
0
Arquivo: views.py Projeto: shredz/Tool
def about(request):
	return Response.render("general/aboutus.html",{},request)
Exemplo n.º 18
0
Arquivo: views.py Projeto: shredz/Tool
def show_deal(request,page):	
	catgs = Category.objects.values('title').distinct()[:10]
	return Response.render("spiffs/show_deal.html" , {'catgs': catgs},request)
Exemplo n.º 19
0
Arquivo: views.py Projeto: shredz/Tool
def approve_deal(request, deal_id):
	deal = Deal.objects.get(id=deal_id)
	deal.approved = True
	deal.save()
	
	return Response.json({"success" : True , "message" : "Deal Has Been Approved"})
Exemplo n.º 20
0
Arquivo: views.py Projeto: shredz/Tool
def reject_deal(request , deal_id):
	deal = Deal.objects.get(id=deal_id)
	deal.delete()
	
	return Response.json({"success" : True , "message" : "Deal Has Been DELETED"})
Exemplo n.º 21
0
Arquivo: views.py Projeto: shredz/Tool
def search(request):
	if request.method == "POST":
		keyword = request.POST['str']
		params = {'deals' : Deal.search(keyword) }
		return Response.render("spiffs/deals.html" , params,request)
Exemplo n.º 22
0
Arquivo: views.py Projeto: shredz/Tool
def signup (request):
	if request.user.is_authenticated():
		return HttpResponseRedirect('/members/')
			
	if request.method == 'POST': 
		form = SignupForm(request.POST)
		
		
		if form.is_valid():
			email1		= form.cleaned_data['email']
			email2		= form.cleaned_data['email2']
		
			if email1 != email2:
				form.errors['email2'] 	= ErrorList([u'Emails do not match'])
			
			try:
				User.objects.get(email=email1)
				form.errors['email']  		= ErrorList([u'Username with this email already exists'])
			except:
				pass
					
			username 		= form.cleaned_data['username']
			try:
				User.objects.get(username=username)
				form.errors['username']  	= ErrorList([u'Username already exists'])
			except:
				pass
			
			password			= form.cleaned_data['password']
			
			
			if not form.errors:
				first_name		= form.cleaned_data['first_name']
				last_name		= form.cleaned_data['last_name']
			
				gender	 		= form.cleaned_data['gender']
				dob 			= form.cleaned_data['dob']
	
				
			
				country = Country.objects.get(id=1)
				
				phonenumber = PhoneNumber(
					countrycode = 0,
					carriercode = 0,
					number 		= 0,
				)
				phonenumber.save()
				
				address = Address(
					zipcode 		= "",
					street_line_1	= "",
					street_line_2	= "",
					city			= "",
					state			= "",
					country			= country,
					location 		= country.location,
					phonenumebr		= phonenumber
				)
			
				address.save()
			
				user = User (
					username		= username,
					email			= email1,
					password		= User.encode_pass(password),
					first_name		= first_name,
					last_name		= last_name,
					dob				= dob,
					gender			= gender,
					address			= address,
					verification	= User.create_verification("1"),
					points 			= 0,
				)
				user.save()
				
				
				reffered_by = False
				try:
					ref_id = request.session["f"]
					reffered_by = User.objects.get(id=ref_id)
					del request.session["f"]
				except:
					pass
		
		
				invitation = False
				try:
					invitation = Invitation.objects.get(id=request.session["invitation"])
					del request.session["invitation"]
				except:
					try:
						invitation = Invitation.objects.get(prospect=Prospect.objects.get(email=user.email))
					except:
						pass
							
				if invitation:
					reffered_by = invitation.sender
					invitation.status = "SIGNUP"
					invitation.save()
					
				if reffered_by:
					ref = Referral(reffered_by=reffered_by,reffered_to=user)
					ref.save()
				
				user.send_verification_mail()
				return HttpResponseRedirect('/members/')
				
	else:
		try:
			request.session["f"] = request.GET["f"]
			return HttpResponseRedirect("/members/signup/")
		except:
			pass
			
		form = SignupForm()
	
	return Response.render_form (request,'members/signup.html',form)
Exemplo n.º 23
0
Arquivo: views.py Projeto: shredz/Tool
def howitworks(request):
	return Response.render("general/howitworks.html",{},request)
Exemplo n.º 24
0
Arquivo: views.py Projeto: shredz/Tool
								"username" 		: un,
								"email" 		: em,
								"first_name" 	: fn,
								"last_name" 	: ln,
								"gender" 		: user.gender,
								"dob" 			: user.dob,
								"zipcode" 		: user.address.zipcode,
								"street_line_1" : user.address.street_line_1,
								"street_line_2" : user.address.street_line_2,
								"city" 			: user.address.city,
								"state" 		: user.address.state,
								"country" 		: user.address.country.id,
							}
						)
		param['errors'] = False		
	return Response.render ('members/profile.html',param,request)
	

def signup (request):
	if request.user.is_authenticated():
		return HttpResponseRedirect('/members/')
			
	if request.method == 'POST': 
		form = SignupForm(request.POST)
		
		
		if form.is_valid():
			email1		= form.cleaned_data['email']
			email2		= form.cleaned_data['email2']
		
			if email1 != email2:
Exemplo n.º 25
0
Arquivo: views.py Projeto: shredz/Tool
def index(request):
	return Response.render("general/main.html" , {},request)
Exemplo n.º 26
0
Arquivo: views.py Projeto: shredz/Tool
def groupon(request):
	return Response.render("general/groupon.html",{},request)
Exemplo n.º 27
0
Arquivo: views.py Projeto: shredz/Tool
def merchants(request):
	return Response.render("general/merchants.html",{},request)