def go(request): user = request.user articles = None #articles = Article.objects(reported=True) articles = Article.objects(Q(reported=True) & Q(isvisible=True)) s_articles = [] for art in articles: s_articles.append(art) ideas = None ideas = Idea.objects(Q(reported=True) & Q(isvisible=True)) s_ideas = [] for idea in ideas: s_ideas.append(idea) promoted = Idea.objects(ispromoted=True) s_promoted = [] for prom in promoted: s_promoted.append(prom) template_values = { 'articles': s_articles, 'ideas': s_ideas, 'user' : user, 'promoted': s_promoted, } path = os.path.join(os.path.dirname(__file__), 'templates/ideas/manage.html') return render_to_response(path, template_values)
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)
def unpublish(request): error_msg = u"No POST data sent." if request.method == "POST": post = request.POST.copy() if post.has_key('id') and post.has_key('type'): try: iid = post['id'] type = post['type'] if type =='idea': ideas = Idea.objects(id=iid) if(len(ideas) >0): idea = ideas[0] idea.isvisible = False idea.save() try: t = ThreadClass("Idea Unpublished", "Your idea '"+idea.title +"' has been unpublished.",[idea.email]+"'") t.start() except Exception as inst: print 'exception sending email '+str(inst) else: articles = Article.objects(id=iid) if(len(articles) >0): art = articles[0] art.isvisible = False art.save() 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)
def approve(request): error_msg = u"No POST data sent." if request.method == "POST": post = request.POST.copy() if post.has_key('id') and post.has_key('type'): try: iid = post['id'] type = post['type'] if type =='idea': ideas = Idea.objects(id=iid) if(len(ideas) >0): idea = ideas[0] idea.reported = False idea.save() else: articles = Article.objects(id=iid) if(len(articles) >0): art = articles[0] art.reported = False art.save() 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)
def go(request): user = request.user filtertag = request.META['HTTP_REFERER'] showtag = False if filtertag.find('/tag/') >=0: showtag = True filtertag = filtertag.split('/')[4] else: filtertag = None ideas = None ideas = Idea.objects(Q(isvisible=True) & Q(ispromoted=False)).order_by('-votecount') s_ideas = [] for idea in ideas: if str(request.user) in idea.voters: idea.hasvoted = True if showtag: if filtertag in idea.tags: s_ideas.append(idea) else: s_ideas.append(idea) template_values = { 'ideas': s_ideas, 'user' : user, } path = os.path.join(os.path.dirname(__file__), 'templates/ideas/allideas.html') return render_to_response(path, template_values)
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)
def go(request): user = request.user filtertag = request.META['HTTP_REFERER'] showtag = False tabselected=None ideaid=None if filtertag.find('/tag/') >=0: showtag = True filtertag = filtertag.split('/')[4] elif filtertag.find('/idea/') >=0: ideaid = filtertag.split('/')[5] filtertag=None tabselected='4' else: filtertag = None tags = Idea.objects.item_frequencies('tags', normalize=True) top_tags = sorted(tags.items(), key=itemgetter(1), reverse=True)[:6] tagobs = [] for key in top_tags: tg = tagclass() tg.tag = key[0] tg.val = key[1] tg.color = str(random.randrange(10,30,1)) if len(tg.tag)>0: tagobs.append(tg) ideas = None ideas = Idea.objects(Q(isvisible=True) & Q(ispromoted=False)).order_by('-votecount')[:20] s_ideas = [] for idea in ideas: if str(request.user) in idea.voters: idea.hasvoted = True if showtag: if filtertag in idea.tags: s_ideas.append(idea) else: s_ideas.append(idea) template_values = { 'ideas': s_ideas, 'user' : user, 'tags': tagobs, 'filtertag':filtertag, 'tabselected':tabselected, 'ideaid':ideaid, } path = os.path.join(os.path.dirname(__file__), 'templates/ideas/topten.html') return render_to_response(path, template_values)
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('/')
def go(request): user = request.user ideas = None ideas = Idea.objects(Q(isvisible=True) & Q(ispromoted=False)).order_by('-date')[:20] s_ideas = [] for idea in ideas: s_ideas.append(idea) template_values = { 'ideas': s_ideas, 'user' : user, } path = os.path.join(os.path.dirname(__file__), 'templates/ideas/newideas.html') return render_to_response(path, template_values)
def demote(request): error_msg = u"No POST data sent." if request.method == "POST": post = request.POST.copy() if post.has_key('id') : try: iid = post['id'] ideas = Idea.objects(id=iid) if(len(ideas) >0): idea = ideas[0] idea.ispromoted = False idea.save() 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)
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)
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)