本文整理汇总了Python中corehq.apps.sms.mixin.MobileBackend类的典型用法代码示例。如果您正苦于以下问题:Python MobileBackend类的具体用法?Python MobileBackend怎么用?Python MobileBackend使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MobileBackend类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_verification
def process_verification(phone_number, msg, backend_id=None):
v = VerifiedNumber.by_phone(phone_number, True)
if not v:
return
if not verification_response_ok(msg.text):
return
msg.domain = v.domain
msg.couch_recipient_doc_type = v.owner_doc_type
msg.couch_recipient = v.owner_id
msg.save()
if not domain_has_privilege(msg.domain, privileges.INBOUND_SMS):
return
if backend_id:
backend = MobileBackend.load(backend_id)
else:
backend = MobileBackend.auto_load(phone_number, v.domain)
# i don't know how to dynamically instantiate this object, which may be any number of doc types...
#owner = CommCareMobileContactMixin.get(v.owner_id)
assert v.owner_doc_type == 'CommCareUser'
owner = CommCareUser.get(v.owner_id)
v = owner.save_verified_number(v.domain, phone_number, True, backend.name)
with localize(owner.language):
send_sms_to_verified_number(v, _(CONFIRM))
示例2: get_ivr_backend
def get_ivr_backend(recipient, verified_number=None, unverified_number=None):
if verified_number and verified_number.ivr_backend_id:
return MobileBackend.get(verified_number.ivr_backend_id)
else:
phone_number = verified_number.phone_number if verified_number else unverified_number
phone_number = strip_plus(str(phone_number))
prefixes = settings.IVR_BACKEND_MAP.keys()
prefixes = sorted(prefixes, key=lambda x: len(x), reverse=True)
for prefix in prefixes:
if phone_number.startswith(prefix):
return MobileBackend.get(settings.IVR_BACKEND_MAP[prefix])
return None
示例3: tearDownClass
def tearDownClass(cls):
MobileBackend.load_by_name(TEST_DOMAIN, TEST_BACKEND).delete()
CommCareUser.get_by_username('stella').delete()
CommCareUser.get_by_username('super').delete()
delete_all_locations()
LocationType.objects.all().delete()
for product in Product.by_domain(TEST_DOMAIN):
product.delete()
SQLProduct.objects.all().delete()
EWSGhanaConfig.for_domain(TEST_DOMAIN).delete()
DocDomainMapping.objects.all().delete()
generator.delete_all_subscriptions()
Domain.get_by_name(TEST_DOMAIN).delete()
示例4: bootstrap
def bootstrap(id=None, to_console=''):
"""
Create an instance of the test backend in the database
"""
backend = MobileBackend(
domain=[],
description='test backend',
outbound_module='corehq.apps.sms.backend.test',
outbound_params={'to_console': True}
)
if id:
backend._id = id
backend.save(**get_safe_write_kwargs())
return backend
示例5: send_verification
def send_verification(domain, user, phone_number):
module = MobileBackend.auto_load(phone_number, domain).backend_module
reply_phone = getattr(module, 'receive_phone_number', lambda: None)()
message = OUTGOING % {
'name': user.username.split('@')[0],
'replyto': ' to %s' % util.clean_phone_number(reply_phone) if reply_phone else '',
}
api.send_sms(domain, user._id, phone_number, message)
示例6: send_verification
def send_verification(domain, user, phone_number):
backend = MobileBackend.auto_load(phone_number, domain)
reply_phone = backend.reply_to_phone_number
message = OUTGOING % {
"name": user.username.split("@")[0],
"replyto": " to %s" % util.clean_phone_number(reply_phone) if reply_phone else "",
}
send_sms(domain, user, phone_number, message)
示例7: tearDownClass
def tearDownClass(cls):
MobileBackend.load_by_name(TEST_DOMAIN, TEST_BACKEND).delete()
CommCareUser.get_by_username('stella').delete()
CommCareUser.get_by_username('bella').delete()
CommCareUser.get_by_username('trella').delete()
CommCareUser.get_by_username('msd_person').delete()
for product in Product.by_domain(TEST_DOMAIN):
product.delete()
SQLProduct.objects.all().delete()
ILSGatewayConfig.for_domain(TEST_DOMAIN).delete()
DocDomainMapping.objects.all().delete()
Location.by_site_code(TEST_DOMAIN, 'loc1').delete()
Location.by_site_code(TEST_DOMAIN, 'loc2').delete()
Location.by_site_code(TEST_DOMAIN, 'dis1').delete()
Location.by_site_code(TEST_DOMAIN, 'reg1').delete()
Location.by_site_code(TEST_DOMAIN, 'moh1').delete()
SQLLocation.objects.all().delete()
generator.delete_all_subscriptions()
Domain.get_by_name(TEST_DOMAIN).delete()
示例8: send_verification
def send_verification(domain, user, phone_number):
backend = MobileBackend.auto_load(phone_number, domain)
reply_phone = backend.reply_to_phone_number
with localize(user.language):
message = _(OUTGOING) % {
'name': user.username.split('@')[0],
'replyto': ' to %s' % util.clean_phone_number(reply_phone) if reply_phone else '',
}
send_sms(domain, user, phone_number, message)
示例9: process_verification
def process_verification(phone_number, text, backend_id=None):
v = VerifiedNumber.by_phone(phone_number, True)
if not v:
return
if not verification_response_ok(text):
return
if backend_id:
backend = MobileBackend.load(backend_id)
else:
backend = MobileBackend.auto_load(phone_number, v.domain)
# i don't know how to dynamically instantiate this object, which may be any number of doc types...
#owner = CommCareMobileContactMixin.get(v.owner_id)
assert v.owner_doc_type == 'CommCareUser'
owner = CommCareUser.get(v.owner_id)
owner.save_verified_number(v.domain, phone_number, True, backend._id)
api.send_sms(v.domain, owner._id, phone_number, CONFIRM)
示例10: send_sms_with_backend_name
def send_sms_with_backend_name(domain, phone_number, text, backend_name):
phone_number = clean_phone_number(phone_number)
msg = SMSLog(
domain=domain,
phone_number=phone_number,
direction=OUTGOING,
date=datetime.utcnow(),
text=text
)
def onerror():
logging.exception("Exception while sending SMS to %s with backend name %s from domain %s" % (phone_number, backend_name, domain))
return send_message_via_backend(msg, MobileBackend.load_by_name(domain, backend_name), onerror=onerror)
示例11: send_sms_with_backend
def send_sms_with_backend(domain, phone_number, text, backend_id):
msg = SMSLog(domain = domain,
phone_number = phone_number,
direction = OUTGOING,
date = datetime.utcnow(),
text = text)
if backend_id == "MOBILE_BACKEND_MACH":
try:
try:
msg.backend_api = mach_api.API_ID
except Exception:
pass
mach_api.send(msg)
msg.save()
return True
except Exception:
logging.exception("Exception while sending SMS to %s with backend %s" % (phone_number, backend_id))
return False
elif backend_id == "MOBILE_BACKEND_UNICEL":
try:
try:
msg.backend_api = unicel_api.API_ID
except Exception:
pass
unicel_api.send(msg)
msg.save()
return True
except Exception:
logging.exception("Exception while sending SMS to %s with backend %s" % (phone_number, backend_id))
return False
else:
try:
backend = MobileBackend.get(backend_id)
except Exception:
backend = None
if backend is None:
return False
try:
module = __import__(backend.outbound_module, fromlist=["send"])
try:
msg.backend_api = module.API_ID
except Exception:
pass
kwargs = backend.outbound_params
module.send(msg, **kwargs)
msg.save()
return True
except Exception as e:
logging.exception("Exception while sending SMS to %s with backend %s" % (phone_number, backend_id))
return False
示例12: get_backend_name
def get_backend_name(backend_id):
"""
Returns None if the backend is not found, otherwise
returns the backend's name.
"""
if not backend_id:
return None
try:
doc = MobileBackend.get_db().get(backend_id)
except ResourceNotFound:
return None
return doc.get("name", None)
示例13: send_sms_with_backend_name
def send_sms_with_backend_name(domain, phone_number, text, backend_name, metadata=None):
phone_number = clean_phone_number(phone_number)
backend = MobileBackend.load_by_name(domain, backend_name)
msg = SMSLog(
domain=domain,
phone_number=phone_number,
direction=OUTGOING,
date=datetime.utcnow(),
backend_id=backend._id,
text=text
)
add_msg_tags(msg, metadata)
return queue_outgoing_sms(msg)
示例14: send_sms_with_backend_name
def send_sms_with_backend_name(domain, phone_number, text, backend_name, metadata=None):
phone_number = clean_phone_number(phone_number)
backend = MobileBackend.load_by_name(domain, backend_name)
msg = SMSLog(
domain=domain,
phone_number=phone_number,
direction=OUTGOING,
date=datetime.utcnow(),
backend_id=backend._id,
text=text
)
add_msg_tags(msg, metadata)
def onerror():
logging.exception("Exception while sending SMS to %s with backend name %s from domain %s" % (phone_number, backend_name, domain))
return queue_outgoing_sms(msg, onerror=onerror)
示例15: send_verification
def send_verification(domain, user, phone_number, logged_event):
backend = MobileBackend.auto_load(phone_number, domain)
reply_phone = backend.reply_to_phone_number
subevent = logged_event.create_subevent_for_single_sms(
user.doc_type,
user.get_id
)
with localize(user.language):
message = _(OUTGOING) % {
'name': user.username.split('@')[0],
'replyto': ' to %s' % util.clean_phone_number(reply_phone) if reply_phone else '',
}
send_sms(domain, user, phone_number, message,
metadata=MessageMetadata(messaging_subevent_id=subevent.pk))
subevent.completed()