Exemple #1
0
def go(request):
	
	tabselected = None
	filtertag = request.META['PATH_INFO']
	if filtertag.find('/idea/') >= 0:
		filtertag = filtertag[6:]
		tabselected = filtertag.replace('/', '')
#		tabselected = 4
	else:
		filtertag = None
		
 	user = request.user
 	
 	rating = None
 	if user.is_authenticated():
		
		person = views.getPerson(request)
	 	if person:
	 		pratings = Rating.objects().order_by('score')
	 		if pratings and len(pratings)>=0:
	 			for prating in pratings:
	 				if person.currentRating >= prating.score:
	 					rating = prating
	 				else:
						break
	 	else:
			person = Person()
			person.email = user.email
			person.name = str(user)
			person.activationdate = datetime.datetime.now()
			person.save()
			views.incrementStat('users',1)
	 		pratings = Rating.objects().order_by('score')
	 		if pratings and len(pratings)>=0:
	 			for prating in pratings:
	 				if person.currentRating >= prating.score:
	 					rating = prating
					else:
						break
 		
 	
	template_values = {
 		'user':user,
 		'tabselected':tabselected,
 		'filtertag':None,
 		'rating':rating,
	}
	path = os.path.join(os.path.dirname(__file__), 'templates/ideas/index.html')
	return render_to_response(path, template_values)
Exemple #2
0
def go(request):
	
	views.incrementStat('ideaviews',1)
	pathinfo = request.META['PATH_INFO']
	pathinfo = pathinfo[10:]
	pathinfo = pathinfo.replace('/','')
	
	user = request.user
	ideas = None
	idea = None
	try:
#		ideas = Idea.objects(Q(isvisible=True) & Q(ispromoted=False)).order_by('-votecount')[:20]
		ideas = Idea.objects(Q(isvisible=True) & Q(ispromoted=False) & Q(id=pathinfo)).order_by('-votecount')[:20]
	except:
		ideas = Idea.objects(Q(isvisible=True) & Q(ispromoted=False)).order_by('-votecount')[:20]
	if ideas == None or len(ideas) == 0:
		ideas = Idea.objects(Q(isvisible=True) & Q(ispromoted=False)).order_by('-votecount')[:20]
	if len(ideas)>0:
		idea = ideas[0]
		vc = idea.viewcount
		if str(user) in idea.voters:
			idea.hasvoted = True
		if vc==None:
			vc = 1
		else:
			vc = vc + 1
		idea.viewcount = vc
		idea.save()
		
		if user.is_authenticated():
			try:
				t = ThreadClass(request)
				t.start()					
			except Exception as inst:
				print 'exception updating view rating '+str(inst)
		
	template_values = {
		'idea': idea,
		'user' : user,
	}

	path = os.path.join(os.path.dirname(__file__), 'templates/ideas/idea.html')
	return render_to_response(path, template_values)