当前位置: 首页>>代码示例>>Python>>正文


Python MobileBackend.get方法代码示例

本文整理汇总了Python中corehq.apps.sms.mixin.MobileBackend.get方法的典型用法代码示例。如果您正苦于以下问题:Python MobileBackend.get方法的具体用法?Python MobileBackend.get怎么用?Python MobileBackend.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corehq.apps.sms.mixin.MobileBackend的用法示例。


在下文中一共展示了MobileBackend.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_ivr_backend

# 需要导入模块: from corehq.apps.sms.mixin import MobileBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.MobileBackend import get [as 别名]
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
开发者ID:nnestle,项目名称:commcare-hq,代码行数:14,代码来源:api.py

示例2: send_sms_with_backend

# 需要导入模块: from corehq.apps.sms.mixin import MobileBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.MobileBackend import get [as 别名]
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
开发者ID:mchampanis,项目名称:core-hq,代码行数:53,代码来源:api.py


注:本文中的corehq.apps.sms.mixin.MobileBackend.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。