Example #1
0
def submitidea(request):
	error_msg = u"No POST data sent."	
	if request.method == "POST":
		post = request.POST.copy()
		if post.has_key('tags') and post.has_key('title') and post.has_key('content'):
			try:
				content = post['content']
				idea = Idea()
				idea.tags = post['tags'].strip().split(',')
				idea.author = str(request.user)
				print "user: "******"Insufficient POST data (need 'content' and 'title'!)"
	return HttpResponseServerError(error_msg)
Example #2
0
def submitarticle(request):
	error_msg = u"No POST data sent."	
	if request.method == "POST":
		post = request.POST.copy()
		if post.has_key('tags') and post.has_key('title') and post.has_key('url'):
			try:
				url = post['url']
				art = Article()
				art.tags = post['tags'].strip().split(',')
				art.author = str(request.user)
				art.title = post['title']
				art.votecount = 0
				art.viewcount = 0
				if not url.startswith('http://'):
					url = 'http://'+url
				art.url = url
				if art.url and art.title and art.author:
					try:
						person = getPerson(request)
						person.timesArticle = person.timesArticle + 1
						person.lastActive = datetime.datetime.now()
						rating = Score.objects(type='submitarticle')[0].value
						person.currentRating = person.currentRating + rating
						person.save()
						incrementStat('articles',1)
						art.save()
					except Exception as inst:
						print inst
				return HttpResponseRedirect('/')
			except:
				return HttpResponseServerError('wowza! an error occurred, sorry!')
		else:
			error_msg = u"Insufficient POST data (need 'content' and 'title'!)"
	return HttpResponseServerError(error_msg)
Example #3
0
def promote(request):
	error_msg = u"No POST data sent."	
	if request.method == "POST":
		post = request.POST.copy()
		print "promote ID: "+post['id']
		if post.has_key('id') :
			try:
				iid = post['id']
				ideas = Idea.objects(id=iid)
				print "len: "+str(len(ideas))
				if(len(ideas) >0):
					idea = ideas[0]
					idea.ispromoted = True
					incrementStat('promotions',1)
					people = Person.objects(email=idea.email)
					if people and len(people)>0:
						person = people[0]
						person.timesPromoted = person.timesPromoted +1
						rating = Score.objects(type='promotion')[0].value
						person.currentRating = person.currentRating + rating
						person.save()
					idea.save()
					try:
						t = ThreadClass("Idea Promoted", "Your idea '"+str(idea.title)+"' has been promoted and will now go forward for idea selection, it may or may not be chosen for implementation.",[idea.email])
						t.start()					
					except Exception as inst:
						print 'exception sending email '+str(inst)
						traceback.print_exc()
				return HttpResponseRedirect('/')
			except Exception as inst:
				return HttpResponseServerError('wowza! an error occurred, sorry!</br>'+str(inst))
		else:
			error_msg = u"Insufficient POST data (need 'slug' and 'title'!)"
	return HttpResponseServerError(error_msg)
Example #4
0
	def run(self):
		try:
			person = views.getPerson(self.request)
			if person:
				person.timesViewed = person.timesViewed + 1
				rating = Score.objects(type='view')[0].value
				person.currentRating = person.currentRating + rating
				person.save()
		except Exception as excep:
			print 'error updating ratings in thread '+str(excep)
Example #5
0
def initialiseScoring(request):
	score = Score.objects(type='submitidea')
	if not score:
		score = Score()
		score.type='submitidea'
		score.value=100
		score.save()
	
	score = Score.objects(type='submitarticle')
	if not score:
		score = Score()
		score.type='submitarticle'
		score.value=80
		score.save()
	
	score = Score.objects(type='comment')
	if not score:
		score = Score()
		score.type='comment'
		score.value=50
		score.save()
	
	score = Score.objects(type='vote')
	if not score:
		score = Score()
		score.type='vote'
		score.value=40
		score.save()

	score = Score.objects(type='report')
	if not score:
		score = Score()
		score.type='report'
		score.value=20
		score.save()
	
	score = Score.objects(type='view')
	if not score:
		score = Score()
		score.type='view'
		score.value=10
		score.save()
	
	score = Score.objects(type='promotion')
	if not score:
		score = Score()
		score.type='promotion'
		score.value=80
		score.save()
		
	initialiseRatings()
	return HttpResponseRedirect('/')
Example #6
0
def reportarticle(request):
	tag =  request.path_info
	tag = tag.split('/')[2]
	articles = Article.objects(id=tag)
	if len(articles)>0:
		art = articles[0]
		art.reported = True
		incrementStat('articlesreported',1)
		person = getPerson(request)
		if person:
			person.timesReport = person.timesReport +1
			rating = Score.objects(type='report')[0].value
			person.currentRating = person.currentRating + rating
			person.save()
		art.save()
	return HttpResponseRedirect('/')
Example #7
0
def report(request):
	tag =  request.path_info
	tag = tag.split('/')[2]
	ideas = Idea.objects(id=tag)
	if len(ideas)>0:
		idea = ideas[0]
		idea.reported = True
		incrementStat('ideasreported',1)
		person = getPerson(request)
		if person:
			person.timesReport = person.timesReport +1
			rating = Score.objects(type='report')[0].value
			person.currentRating = person.currentRating + rating
			person.save()
		idea.save()
	return HttpResponseRedirect('/')
Example #8
0
def go(request):
	user = request.user
				
	scores = None
	#articles = Article.objects(reported=True)
	scores = Score.objects()
	ratings = Rating.objects()
	
	
	template_values = {
		'scores': scores,
		'user' : user,
		'ratings':ratings,
	}

	path = os.path.join(os.path.dirname(__file__), 'templates/ideas/managescores.html')
	return render_to_response(path, template_values)
Example #9
0
def addcomment(request):
	error_msg = u"No POST data sent."
	print 'addcomment called'	
	if request.method == "POST":
		post = request.POST.copy()
		if post.has_key('content') and post.has_key('id'):
			try:
				iid = post['id']
				ideas = Idea.objects(id=iid)
				if(len(ideas) >0):
					idea = ideas[0]
					comment = Comment()
					comment.content = post['content']
					if not comment.content or comment.content.strip()=="":
						return HttpResponseRedirect('/')
					comment.author = str(request.user)
					idea.comments.append(comment)
					incrementStat('comments',1)
					person = getPerson(request)
					if person:
						person.lastActive = datetime.datetime.now()
						person.timesCommented = person.timesCommented + 1
						rating = Score.objects(type='comment')[0].value
						person.currentRating = person.currentRating + rating
						person.save()
					idea.save()
					try:
						t = ThreadClass(comment.author+" has commented on your idea: '"+idea.title+"'", comment.author+" commented: '"+comment.content+"'",[idea.email])
						t.start()					
					except Exception as inst:
						print 'exception sending email '+str(inst)
				return HttpResponseRedirect('/')
			except Exception as inst:
				return HttpResponseServerError('wowza! an error occurred, sorry!</br>'+str(inst))
		else:
			print 'didnt comment, no data'
			return HttpResponseRedirect('/')
#			error_msg = u"Insufficient POST data (need 'slug' and 'title'!)"

	return HttpResponseServerError(error_msg)
Example #10
0
def vote(request):
	error_msg = u"No POST data sent."	
	if request.method == "POST":
		post = request.POST.copy()
		print 'post = '+str(post)
		if post.has_key('id') and post.has_key('star1'):
			try:
				iid = post['id']
				ideas = Idea.objects(id=iid)
				if(len(ideas) >0):
					idea = ideas[0]
					curcount = idea.votecount
					print post['star1']
					voteval = int(post['star1'])		
					idea.votecount = idea.votecount + voteval
					idea.voters.append(str(request.user))
					incrementStat('unique_idea_votes',1)
					incrementStat('total_idea_vote_count',voteval)
					person = getPerson(request)
					if person:
						person.lastActive = datetime.datetime.now()
						rating = Score.objects(type='vote')[0].value
						person.currentRating = person.currentRating + rating
						person.timesVoted = person.timesVoted + 1
						person.save()
					idea.save()
					try:
						t = ThreadClass("Idea voted on", "Your idea '"+idea.title +"' has been given a voting of "+str(voteval)+".",[idea.email])
						t.start()					
					except Exception as inst:
						print 'exception sending email '+str(inst)
				return HttpResponseRedirect('/')
			except Exception as inst:
				return HttpResponseServerError('wowza! an error occurred, sorry!</br>'+str(inst))
		else:
			print 'no vote cast, no stars selected'
#			error_msg = u"Insufficient POST data (need 'slug' and 'title'!)"
			return HttpResponseRedirect('/')
	return HttpResponseServerError(error_msg)