コード例 #1
0
ファイル: tasks.py プロジェクト: texnokrates/zeus
def single_voter_email(voter_uuid,
                       contact_methods,
                       contact_id,
                       subject_template_email,
                       body_template_email,
                       body_template_sms,
                       template_vars={},
                       update_date=True,
                       update_booth_invitation_date=False,
                       notify_once=False,
                       update_notification_date=False,
                       forum_notification=None):

    voter = Voter.objects.get(uuid=voter_uuid)
    lang = voter.poll.election.communication_language

    with translation.override(lang):
        template_vars = copy.copy(template_vars)
        template_vars.update({
            'voter': voter,
            'poll': voter.poll,
            'election': voter.poll.election
        })

        subject_tpls = {'email': subject_template_email, 'sms': ''}

        body_tpls = {'email': body_template_email, 'sms': body_template_sms}

        def sent_hook(voter, method, error=None):
            if error:
                return
            linked_voters = voter.linked_voters
            if method == 'email' and update_date:
                for voter in linked_voters:
                    voter.last_email_send_at = datetime.datetime.now()
                    voter.save()
            if method == 'sms' and update_date:
                for voter in linked_voters:
                    voter.last_sms_send_at = datetime.datetime.now()
                    voter.save()
            if update_booth_invitation_date:
                for voter in linked_voters:
                    voter.last_booth_invitation_send_at = datetime.datetime.now(
                    )
                    voter.save()
            if update_notification_date:
                notification = forum_notification
                notification.last_notified_at = datetime.datetime.now()
                notification.save()

        ContactBackend.notify_voter(voter.poll,
                                    voter,
                                    contact_id,
                                    contact_methods,
                                    subject_tpls,
                                    body_tpls,
                                    template_vars,
                                    sent_hook=sent_hook,
                                    notify_once=notify_once)
コード例 #2
0
ファイル: tasks.py プロジェクト: texnokrates/zeus
def send_cast_vote_email(poll_pk, voter_pk, signature, fingerprint):
    poll = Poll.objects.get(pk=poll_pk)
    election = poll.election
    lang = election.communication_language
    voter = poll.voters.filter().get(pk=voter_pk)

    with translation.override(lang):
        email_subject = "email/cast_done_subject.txt"
        email_body = "email/cast_done_body.txt"
        sms_body = "sms/cast_done_body.txt"
        # send it via the notification system associated with the auth system
        attachments = [
            ('vote.signature', signature['signature'].encode("utf8"),
             'application/octet-stream')
        ]

        subject_tpls = {'email': email_subject, 'sms': None}

        body_tpls = {'email': email_body, 'sms': sms_body}

        receipt_url = settings.SECURE_URL_HOST + reverse(
            'download_signature_short', args=(fingerprint, ))
        tpl_vars = {
            'voter': voter,
            'poll': poll,
            'election': election,
            'signature': signature,
            'date': voter.last_cast_vote().cast_at,
            'vote_receipt_url': receipt_url
        }
        ContactBackend.notify_voter(poll,
                                    voter,
                                    'cast_done',
                                    voter.contact_methods,
                                    subject_tpls,
                                    body_tpls,
                                    tpl_vars,
                                    attachments=attachments,
                                    notify_once=election.cast_notify_once)
コード例 #3
0
ファイル: tasks.py プロジェクト: grnet/zeus
def send_cast_vote_email(poll_pk, voter_pk, signature, fingerprint):
    poll = Poll.objects.get(pk=poll_pk)
    election = poll.election
    lang = election.communication_language
    voter = poll.voters.filter().get(pk=voter_pk)

    with translation.override(lang):
        email_subject = "email/cast_done_subject.txt"
        email_body = "email/cast_done_body.txt"
        sms_body = "sms/cast_done_body.txt"
        # send it via the notification system associated with the auth system
        attachments = [('vote.signature', signature['signature'].encode("utf8"), 'application/octet-stream')]

        subject_tpls = {
            'email': email_subject,
            'sms': None
        }

        body_tpls = {
            'email': email_body,
            'sms': sms_body
        }

        receipt_url = settings.SECURE_URL_HOST + reverse('download_signature_short', args=(fingerprint,))
        tpl_vars = {
            'voter': voter,
            'poll': poll,
            'election': election,
            'signature': signature,
            'date': voter.last_cast_vote().cast_at,
            'vote_receipt_url': receipt_url
        }
        ContactBackend.notify_voter(
            poll, voter, 'cast_done', voter.contact_methods, subject_tpls,
            body_tpls, tpl_vars, attachments=attachments,
            notify_once=election.cast_notify_once)
コード例 #4
0
ファイル: tasks.py プロジェクト: grnet/zeus
def single_voter_email(voter_uuid,
                       contact_methods,
                       contact_id,
                       subject_template_email,
                       body_template_email,
                       body_template_sms,
                       template_vars={},
                       update_date=True,
                       update_booth_invitation_date=False,
                       notify_once=False,
                       update_notification_date=False,
                       forum_notification=None):

    voter = Voter.objects.get(uuid=voter_uuid)
    lang = voter.poll.election.communication_language

    with translation.override(lang):
        template_vars= copy.copy(template_vars)
        template_vars.update({'voter' : voter, 'poll': voter.poll,
                              'election': voter.poll.election})

        subject_tpls = {
            'email': subject_template_email,
            'sms': ''
        }

        body_tpls = {
            'email': body_template_email,
            'sms': body_template_sms
        }


        def sent_hook(voter, method, error=None):
            if error:
                return
            linked_voters = voter.linked_voters
            if method == 'email' and update_date:
                for voter in linked_voters:
                    voter.last_email_send_at = datetime.datetime.now()
                    voter.save()
            if method == 'sms' and update_date:
                for voter in linked_voters:
                    voter.last_sms_send_at = datetime.datetime.now()
                    voter.save()
            if update_booth_invitation_date:
                for voter in linked_voters:
                    voter.last_booth_invitation_send_at = datetime.datetime.now()
                    voter.save()
            if update_notification_date:
                notification = forum_notification
                notification.last_notified_at = datetime.datetime.now()
                notification.save()


        ContactBackend.notify_voter(
            voter.poll,
            voter,
            contact_id,
            contact_methods,
            subject_tpls,
            body_tpls,
            template_vars,
            sent_hook=sent_hook,
            notify_once=notify_once)