Beispiel #1
0
def check_sms_status(voter_id, code, election_uuid=None):
    voter = Voter.objects.select_related().get(pk=voter_id)
    if voter.last_sms_status:
        return voter.last_sms_status

    client = mobile.get_client(election_uuid)
    return client.status(code)
Beispiel #2
0
    def do_notify(self, voter, id, subject, body, attachments):
        with transaction.atomic():
            data = self.get_data(update=True)
            if not self.has_available_deliveries():
                raise ContactBackend.Error("No sms deliveries available")
            self.logger.info("Notifying voter %r for '%s' via sms to '%s'" %
                             (voter.voter_login_id, id, voter.voter_mobile))
            dlr_url = settings.SECURE_URL_HOST + reverse(
                'election_poll_sms_delivery',
                args=(voter.poll.election.uuid, voter.poll.uuid))
            client = mobile.get_client(voter.poll.election,
                                       self.data,
                                       dlr_url=dlr_url)
            sent, error_or_code = client.send(voter.voter_mobile, body)
            msg_uid = client._last_uid

            if not sent:
                self.logger.error(
                    "SMS notification to voter '%s' failed (uid: %r, resp: %r)",
                    voter.voter_login_id, msg_uid, error_or_code)
            else:
                self.logger.info(
                    "SMS notification to voter '%s' sent (uid: %r, resp: %r)",
                    voter.voter_login_id, msg_uid, error_or_code)
            if sent:
                # store last notification date
                voter.last_sms_send_at = datetime.datetime.now()
                voter.last_sms_code = client.id + ":" + error_or_code
                if not client.remote_status:
                    voter.last_sms_status = 'sent'
                data.increase_sent(body)
                voter.save()
            return sent, error_or_code if not sent else None
Beispiel #3
0
def check_sms_status(voter_id, code, election_uuid=None):
    voter = Voter.objects.select_related().get(pk=voter_id)
    if voter.last_sms_status:
        return voter.last_sms_status

    client = mobile.get_client(election_uuid)
    return client.status(code)
Beispiel #4
0
def send_voter_sms(voter_id,
                   tpl,
                   override_mobile=None,
                   resend=False,
                   dry=True):
    voter = Voter.objects.select_related().get(pk=voter_id)
    if not voter.voter_mobile and not override_mobile:
        raise Exception("Voter mobile field not set")

    dlr_url = settings.SECURE_URL_HOST + reverse(
        'election_poll_sms_delivery',
        args=(voter.poll.election.uuid, voter.poll.uuid))
    client = mobile.get_client(voter.poll.election.uuid, dlr_url=dlr_url)
    message = ""
    context = Context({
        'voter': voter,
        'poll': voter.poll,
        'election': voter.poll.election,
        'reg_code': voter.voter_login_id,
        'login_code': voter.login_code,
        'email': voter.voter_email,
        'secret': voter.voter_password,
        'SECURE_URL_HOST': settings.SECURE_URL_HOST
    })
    t = Template(tpl)
    message = t.render(context)

    # identify and sanitize mobile number
    voter_mobile = override_mobile or voter.voter_mobile
    try:
        voter_mobile = utils.sanitize_mobile_number(voter_mobile)
    except Exception, e:
        return False, "Invalid number (%s)" % str(voter_mobile)
Beispiel #5
0
def send_voter_sms(voter_id, tpl, override_mobile=None, resend=False,
                   dry=True):
    voter = Voter.objects.select_related().get(pk=voter_id)
    if not voter.voter_mobile and not override_mobile:
        raise Exception("Voter mobile field not set")

    dlr_url = settings.SECURE_URL_HOST + reverse('election_poll_sms_delivery', args=(voter.poll.election.uuid, voter.poll.uuid))
    client = mobile.get_client(voter.poll.election.uuid, dlr_url=dlr_url)
    message = ""
    context = Context({
        'voter': voter,
        'poll': voter.poll,
        'election': voter.poll.election,
        'reg_code': voter.voter_login_id,
        'login_code': voter.login_code,
        'email': voter.voter_email,
        'secret': voter.voter_password,
        'SECURE_URL_HOST': settings.SECURE_URL_HOST
    })
    t = Template(tpl)
    message = t.render(context)

    # identify and sanitize mobile number
    voter_mobile = override_mobile or voter.voter_mobile
    try:
        voter_mobile = utils.sanitize_mobile_number(voter_mobile)
    except Exception, e:
        return False, "Invalid number (%s)" % str(voter_mobile)
Beispiel #6
0
    def do_notify(self, voter, id, subject, body, attachments):
        with transaction.atomic():
            data = self.get_data(update=True)
            if not self.has_available_deliveries():
                raise ContactBackend.Error("No sms deliveries available")
            self.logger.info("Notifying voter %r for '%s' via sms to '%s'" % (voter.voter_login_id, id, voter.voter_mobile))
            dlr_url = settings.SECURE_URL_HOST + reverse('election_poll_sms_delivery', args=(voter.poll.election.uuid, voter.poll.uuid))
            client = mobile.get_client(voter.poll.election, self.data, dlr_url=dlr_url)
            sent, error_or_code = client.send(voter.voter_mobile, body)
            msg_uid = client._last_uid

            if not sent:
                self.logger.error("SMS notification to voter '%s' failed (uid: %r, resp: %r)", voter.voter_login_id, msg_uid,
                                error_or_code)
            else:
                self.logger.info("SMS notification to voter '%s' sent (uid: %r, resp: %r)", voter.voter_login_id, msg_uid,
                                error_or_code)
            if sent:
                # store last notification date
                voter.last_sms_send_at = datetime.datetime.now()
                voter.last_sms_code = client.id + ":" + error_or_code
                if not client.remote_status:
                    voter.last_sms_status = 'sent'
                data.increase_sent(body)
                voter.save()
            return sent, error_or_code if not sent else None
Beispiel #7
0
def check_sms_status(code, election_uuid=None):
    client = mobile.get_client(election_uuid)
    return client.status(code)