Example #1
0
def start_callback():
    election = db.election(request.args(0, cast=int)) or redirect(URL('index'))
    check_closed(election)
    form = SQLFORM.factory(
        submit_button=T('Email Voters and Start Election Now!'))
    form.element(_type='submit').add_class('btn')
    failures = []
    emails = []
    owner_email = election.created_by.email
    if form.process().accepted:
        ballot_counter = db(db.ballot.election_id == election.id).count()
        for email in regex_email.findall(election.voters):
            email = email.lower()
            voter = db(db.voter.election_id==election.id)\
                (db.voter.email==email).select().first()
            if voter:
                voter_uuid = voter.voter_uuid
            else:
                # create a voter
                voter_uuid = 'voter-' + uuid()
                voter = db.voter.insert(election_id=election.id,
                                        voter_uuid=voter_uuid,
                                        email=email,
                                        invited_on=None)
                # create a ballot
                ballot_counter += 1
                ballot_uuid = 'ballot-%i-%.6i' % (election.id, ballot_counter)
                blank_ballot_content = blank_ballot(ballot_uuid)
                signature = 'signature-' + sign(blank_ballot_content,
                                                election.private_key)
                db.ballot.insert(election_id=election.id,
                                 ballot_content=blank_ballot_content,
                                 ballot_uuid=ballot_uuid,
                                 signature=signature)
            link_vote = URL('vote',
                            args=(election.id, voter_uuid),
                            scheme=SCHEME)
            link_ballots = URL('ballots', args=election.id, scheme=SCHEME)
            link_results = URL('results', args=election.id, scheme=SCHEME)
            body = message_replace(election.vote_email,
                                   election_id=election.id,
                                   owner_email=owner_email,
                                   title=election.title,
                                   link=link_vote,
                                   link_ballots=link_ballots,
                                   link_results=link_results)
            subject = '%s [%s]' % (election.title, election.id)
            emails.append((voter, email, subject, body))
        db.commit()
        sender = election.email_sender or mail.settings.sender
        for voter, to, subject, body in emails:
            if mail.send(to=to, subject=subject, message=body, sender=sender):
                db(db.voter.id == voter).update(invited_on=request.now)
            else:
                failures.append(to)
        if not failures:
            session.flash = T('Emails sent successfully')
            redirect(URL('elections'), client_side=True)
    return dict(form=form, failures=failures, election=election)
Example #2
0
def start_callback():
    election = db.election(request.args(0,cast=int)) or redirect(URL('index'))
    check_closed(election)
    form = SQLFORM.factory(
        submit_button=T('Email Voters and Start Election Now!'))
    form.element(_type='submit').add_class('btn')
    failures = []
    emails = []
    owner_email = election.created_by.email
    if form.process().accepted:
        ballot_counter = db(db.ballot.election_id==election.id).count()
        for email in regex_email.findall(election.voters):
            voter = db(db.voter.election_id==election.id)\
                (db.voter.email==email).select().first()
            if voter:
                voter_uuid = voter.voter_uuid
            else:
                # create a voter
                voter_uuid = 'voter-'+uuid()
                voter = db.voter.insert(
                    election_id=election.id,
                    voter_uuid=voter_uuid,
                    email=email,invited_on=None)
                # create a ballot
                ballot_counter+=1
                ballot_uuid = 'ballot-%i-%.6i' % (election.id,ballot_counter)
                blank_ballot_content = blank_ballot(ballot_uuid)
                signature = 'signature-'+sign(blank_ballot_content,
                                              election.private_key)
                db.ballot.insert(
                    election_id=election.id,
                    ballot_content = blank_ballot_content,
                    ballot_uuid=ballot_uuid,
                    signature = signature)
            link_vote = URL('vote',args=(election.id,voter_uuid),scheme=SCHEME)
            link_ballots = URL('ballots',args=election.id,scheme=SCHEME)
            link_results = URL('results',args=election.id,scheme=SCHEME)
            message = message_replace(election.vote_email,
                                      election_id = election.id,
                                      owner_email = owner_email,
                                      title=election.title,
                                      link=link_vote,
                                      link_ballots=link_ballots,
                                      link_results=link_results)
            subject = '%s [%s]' % (election.title, election.id)
            print message
            emails.append((voter,email,subject,message))
        db.commit()
        sender = election.email_sender or mail.settings.sender
        for voter, to, subject, message in emails:
            if meta_send2(to=to,subject=subject,message=message,
                          sender=sender, reply_to=sender):
                db(db.voter.id==voter).update(invited_on=request.now)
            else:
                failures.append(to)
        if not failures:
            session.flash = T('Emails sent successfully')
            redirect(URL('elections'),client_side=True)
    return dict(form=form,failures=failures,election=election)
Example #3
0
def email_voter_and_managers(election,voter,ballot,message):
    import cStringIO
    attachment = mail.Attachment(
        filename=ballot.ballot_uuid+'.html',
        payload=cStringIO.StringIO(ballot.ballot_content))
    ret = mail.send(to=voter.email,
                    subject='Receipt for %s' % election.title,
                    message=message,attachments=[attachment])
    mail.send(to=regex_email.findall(election.managers),
              subject='Copy of Receipt for %s' % election.title,
              message=message,attachments=[attachment])
    return ret
Example #4
0
def email_voter_and_managers(election,voter,ballot,message):
    import cStringIO
    attachment = mail.Attachment(
        filename=ballot.ballot_uuid+'.html',
        payload=cStringIO.StringIO(ballot.ballot_content))
    sender = election.email_sender or mail.settings.sender
    ret = mail.send(to=voter.email,
                    subject='Receipt for %s' % election.title,
                    message=message,attachments=[attachment])
    mail.send(to=regex_email.findall(election.managers),
              subject='Copy of Receipt for %s' % election.title,
              message=message,attachments=[attachment])
    return ret
Example #5
0
def start_callback():
    election = db.election(request.args(0, cast=int)) or redirect(URL("index"))
    form = SQLFORM.factory(submit_button=T("Email Voters and Start Election Now!"))
    form.element(_type="submit").add_class("btn")
    failures = []
    emails = []
    owner_email = election.created_by.email
    if form.process().accepted:
        ballot_counter = db(db.ballot.election_id == election.id).count()
        for email in regex_email.findall(election.voters):
            voter = db(db.voter.election_id == election.id)(db.voter.email == email).select().first()
            if voter:
                voter_uuid = voter.voter_uuid
            else:
                # create a voter
                voter_uuid = "voter-" + uuid()
                db.voter.insert(election_id=election.id, voter_uuid=voter_uuid, email=email, invited_on=request.now)
                # create a ballot
                ballot_counter += 1
                ballot_uuid = "ballot-%i-%.6i" % (election.id, ballot_counter)
                blank_ballot_content = blank_ballot(ballot_uuid)
                signature = "signature-" + sign(blank_ballot_content, election.private_key)
                db.ballot.insert(
                    election_id=election.id,
                    ballot_content=blank_ballot_content,
                    ballot_uuid=ballot_uuid,
                    signature=signature,
                )
            link_vote = URL("vote", args=(election.id, voter_uuid), scheme=SCHEME)
            link_ballots = URL("ballots", args=election.id, scheme=SCHEME)
            link_results = URL("results", args=election.id, scheme=SCHEME)
            message = message_replace(
                election.vote_email,
                election_id=election.id,
                owner_email=owner_email,
                title=election.title,
                link=link_vote,
                link_ballots=link_ballots,
                link_results=link_results,
            )
            subject = "%s [%s]" % (election.title, election.id)
            emails.append((email, subject, message))
        db.commit()
        sender = election.email_sender or mail.settings.sender
        for to, subject, message in emails:
            if not meta_send(to=to, subject=subject, message=message, sender=sender, reply_to=sender):
                failures.append(email)
        if not failures:
            session.flash = T("Emails sent successfully")
            redirect(URL("elections"), client_side=True)
    return dict(form=form, failures=failures, election=election)
Example #6
0
def reminders_callback():
    election = db.election(request.args(0, cast=int)) or redirect(URL('index'))
    owner_email = election.created_by.email
    failures = []
    emails = []
    fields = []
    for email in regex_email.findall(election.voters):
        voter = db(db.voter.election_id==election.id)\
            (db.voter.email==email).select().first()
        voter_uuid = voter.voter_uuid
        key = 'voter_%s' % voter.id
        fields.append(
            Field(key, 'boolean', default=not voter.voted, label=voter.email))
        if key in request.post_vars:
            link = URL('vote', args=(election.id, voter_uuid), scheme=SCHEME)
            link_ballots = URL('ballots', args=election.id, scheme=SCHEME)
            link_results = URL('results', args=election.id, scheme=SCHEME)
            message = message_replace(
                election.vote_email,
                election_id=election.id,
                owner_email=owner_email,
                title=election.title,
                link=link,
                link_ballots=link_ballots,
                link_results=link_results)
            subject = '%s [%s]' % (election.title, election.id)
            emails.append((email, subject, message))
    form = SQLFORM.factory(*fields).process()
    if form.accepted:
        sender = election.email_sender or mail.settings.sender
        for to, subject, message in emails:
            if not meta_send2(
                    to=to,
                    subject=subject,
                    message=message,
                    sender=sender,
                    reply_to=sender):
                failures.append(email)
        if not failures:
            session.flash = T('Emails sent successfully')
            redirect(URL('elections'), client_side=True)
    return dict(form=form, failures=failures, election=election)
Example #7
0
def start_callback():
    import hashlib
    election = db.election(request.args(0,cast=int)) or redirect(URL('index'))
    form = FORM(INPUT(_type='submit',
                      _value=T('Email Voters and Start Election Now!')))
    failures = []
    if form.process().accepted:
        ballot_counter = db(db.ballot.election_id==election.id).count()
        for email in regex_email.findall(election.voters):
            voter = db(db.voter.election_id==election.id)\
                (db.voter.email==email).select().first()
            if voter:
                voter_uuid = voter.voter_uuid
            else:
                # create a voter
                voter_uuid = 'voter-'+uuid()
                db.voter.insert(
                    election_id=election.id,
                    voter_uuid=voter_uuid,
                    email=email,invited_on=request.now)
                # create a ballot
                ballot_counter+=1
                ballot_uuid = 'ballot-%i-%.6i' % (election.id,ballot_counter)
                blank_ballot_content = blank_ballot(ballot_uuid)
                signature = 'signature-'+sign(blank_ballot_content,
                                              election.private_key)
                db.ballot.insert(
                    election_id=election.id,
                    ballot_content = blank_ballot_content,
                    ballot_uuid=ballot_uuid,
                    signature = signature)
            link = URL('vote',args=(election.id,voter_uuid),scheme='https')
            message = message_replace(election.vote_email,
                              title=election.title,link=link)
            if not mail.send(to=email,subject=election.title,message=message):
                failures.append(email)
        if not failures:
            session.flash = T('Emails sent successfully')
            redirect(URL('elections'),client_side=True)
    return dict(form=form,failures=failures,election=election)
Example #8
0
def reminders_callback():
    election = db.election(request.args(0, cast=int)) or redirect(URL('index'))
    owner_email = election.created_by.email
    failures = []
    emails = []
    fields = []
    for email in regex_email.findall(election.voters):
        voter = db(db.voter.election_id==election.id)\
            (db.voter.email==email).select().first()
        voter_uuid = voter.voter_uuid
        key = 'voter_%s' % voter.id
        fields.append(
            Field(key, 'boolean', default=not voter.voted, label=voter.email))
        if key in request.post_vars:
            link = URL('vote', args=(election.id, voter_uuid), scheme=SCHEME)
            link_ballots = URL('ballots', args=election.id, scheme=SCHEME)
            link_results = URL('results', args=election.id, scheme=SCHEME)
            message = message_replace(election.vote_email,
                                      election_id=election.id,
                                      owner_email=owner_email,
                                      title=election.title,
                                      link=link,
                                      link_ballots=link_ballots,
                                      link_results=link_results)
            subject = '%s [%s]' % (election.title, election.id)
            emails.append((email, subject, message))
    form = SQLFORM.factory(*fields).process()
    if form.accepted:
        sender = election.email_sender or mail.settings.sender
        for to, subject, message in emails:
            if not meta_send2(to=to,
                              subject=subject,
                              message=message,
                              sender=sender,
                              reply_to=sender):
                failures.append(email)
        if not failures:
            session.flash = T('Emails sent successfully')
            redirect(URL('elections'), client_side=True)
    return dict(form=form, failures=failures, election=election)
Example #9
0
def email_voter_and_managers(election, voter, ballot, message):
    import cStringIO

    attachment = mail.Attachment(
        filename=ballot.ballot_uuid + ".html", payload=cStringIO.StringIO(ballot.ballot_content)
    )
    sender = election.email_sender or mail.settings.sender
    ret = meta_send(
        to=voter.email,
        subject="Receipt for %s" % election.title,
        message=message,
        attachments=[attachment],
        sender=sender,
        reply_to=sender,
    )
    meta_send(
        to=regex_email.findall(election.managers),
        subject="Copy of Receipt for %s" % election.title,
        message=message,
        attachments=[attachment],
        sender=sender,
        reply_to=sender,
    )
    return ret