def showResults(self): if (not 'poll_id' in request.params): redirect(url(controller='poll', action='showAll')) try: poll = Session.query(Poll).filter(Poll.owner == self.uid).filter(Poll.id == request.params['poll_id']).one() c.poll = poll votes = {} votes['missing'] = 0 if poll.type == 'yesno' or poll.type == 'yesnonull': for v in poll.votes: if v.simple_vote is None: votes['missing'] += 1 elif not v.simple_vote in votes: votes[v.simple_vote] = 1 else: votes[v.simple_vote] += 1 else: for v in poll.votes: if v.complex_vote is None: votes['missing'] += 1 else: votes[v.complex_vote] = 1 c.votes = votes return render('/vote/showResults.mako') except Exception as e: print e pass redirect(url(controller='poll', action='showAll'))
def results(self): if not 'vote_key' in request.params or request.params['vote_key'] == '': return render('/vote/results.mako') else: try: vote = Session.query(Vote).filter(Vote.key == request.params['vote_key']).one() poll = Session.query(Poll).filter(Poll.id == vote.poll_id).one() if vote.update_date is None: session['flash'] = _('Vote first') session['flash_class'] = 'error' session.save() redirect(url(controller='vote', action='vote')) c.poll = poll votes = {} votes['missing'] = 0 if poll.type == 'yesno' or poll.type == 'yesnonull': for v in poll.votes: if v.simple_vote is None: votes['missing'] += 1 elif not v.simple_vote in votes: votes[v.simple_vote] = 1 else: votes[v.simple_vote] += 1 else: for v in poll.votes: if v.complex_vote is None: votes['missing'] += 1 else: votes[v.complex_vote] = 1 c.votes = votes return render('/vote/showResults.mako') except Exception as e: print e raise e pass return render('/vote/results.mako')
def vote(self): if 'vote_key' in request.params and not request.params['vote_key'] == '': try: vote = Session.query(Vote).filter(Vote.key == request.params['vote_key']).one() poll = Session.query(Poll).filter(Poll.id == vote.poll_id).one() if datetime.now() > poll.expiration_date: session['flash'] = _('Sorry, poll has expired') session['flash_class'] = 'error' session.save() redirect(url(controller='vote', action='vote')) if vote.update_date is None: c.poll = Session.query(Poll).filter(Poll.id == vote.poll_id).one() c.vote_key = request.params['vote_key'] return render('/vote/dovote.mako') except Exception as e: import sys, traceback traceback.print_exc(file=sys.stdout) pass return render('/vote/vote.mako')
def showAll(self): c.heading = _('All polls') c.polls = [] try: polls = Session.query(Poll).filter(Poll.owner == self.uid).all() for s in polls: try: s.name = s.name.encode('ascii','ignore') except: s.name ='poo...frickin P000000' c.polls.append(s) except NoResultFound: print 'No such poll' return render('/poll/showAll.mako')
def editPoll(self): if (not 'poll_id' in request.params): redirect(url(controller='poll', action='showAll')) try: poll = Session.query(Poll).filter(Poll.owner == self.uid).filter(Poll.id == request.params['poll_id']).one() c.heading = _('Edit poll') c.mode = 'edit' if len(poll.votes) > 0: session['flash'] = _('Cannot edit a running poll') session['flash_class'] = 'error' session.save() redirect(url(controller='poll', action='showAll')) c.poll = poll return render('/poll/edit.mako') except: pass redirect(url(controller='poll', action='showAll'))
def login(self): if not self.uid is None: redirect(url(controller='poll', action='showAll')) return render('/login.mako')
def addPoll(self): c.mode = 'add' return render('/poll/edit.mako')