def doEditPoll(self): try: if request.params['mode'] == 'edit': poll = Session.query(Poll).filter(Poll.owner == self.uid).filter(Poll.id == request.params['poll_id']).one() else: poll = Poll() poll.owner = self.uid poll.name = request.params['name'].encode('utf8') poll.instructions = str(request.params['instructions'].encode('utf-8')) poll.expiration_date = request.params['expiration_date'] poll.type = request.params['type'] if request.params['public'] == 'yes': poll.public = True else: poll.public = False if request.params['mode'] == 'add': Session.add(poll) Session.flush() voters = request.params['voters'].split('\n') voters = list(set(voters)) for v in voters: vo = None vo = Vote() vo.poll_id = poll.id vo.key = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(20)) mailtext = '''\ Hey, Your vote is requested for "%s". You can vote here: https://votex.hackerspace.lu:8443/vote/vote?vote_key=%s Your voting key is: %s The poll expires on %s ''' %\ (poll.name, vo.key, vo.key, poll.expiration_date) msg = MIMEText(mailtext, 'plain') msg['Subject'] = 'syn2cat - We need you to vote' msg['From'] = '*****@*****.**' msg['To'] = v s = smtplib.SMTP('localhost') s.sendmail(msg['From'], v, msg.as_string()) s.quit() Session.add(vo) Session.commit() session['flash'] = _('Poll successfully edited') session.save() redirect(url(controller='poll', action='showAll')) except LookupError: print 'No such user !' session['flash'] = _('Failed to add poll') session['flash_class'] = 'error' session.save() redirect(url(controller='poll', action='showAll'))