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


Python SMSBackend.get方法代码示例

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


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

示例1: paginated_list

# 需要导入模块: from corehq.apps.sms.mixin import SMSBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.SMSBackend import get [as 别名]
    def paginated_list(self):
        all_backends = []
        all_backends += SMSBackend.view(
            "sms/backend_by_domain",
            classes=self.backend_classes,
            startkey=[self.domain],
            endkey=[self.domain, {}],
            reduce=False,
            include_docs=True,
        ).all()
        all_backends += SMSBackend.view(
            "sms/global_backends", classes=self.backend_classes, reduce=False, include_docs=True
        ).all()

        if len(all_backends) > 0 and not self.domain_object.default_sms_backend_id:
            yield {
                "itemData": {"id": "nodefault", "name": "Automatic Choose", "status": "DEFAULT"},
                "template": "gateway-automatic-template",
            }
        elif self.domain_object.default_sms_backend_id:
            default_backend = SMSBackend.get(self.domain_object.default_sms_backend_id)
            yield {"itemData": self._fmt_backend_data(default_backend), "template": "gateway-default-template"}
        for backend in all_backends:
            if not backend._id == self.domain_object.default_sms_backend_id:
                yield {"itemData": self._fmt_backend_data(backend), "template": "gateway-template"}
开发者ID:rigambhir,项目名称:commcare-hq,代码行数:27,代码来源:views.py

示例2: get_rate_response

# 需要导入模块: from corehq.apps.sms.mixin import SMSBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.SMSBackend import get [as 别名]
    def get_rate_response(self):
        gateway = self.data.get('gateway')
        try:
            backend = SMSBackend.get(gateway)
            backend_api_id = get_backend_by_class_name(backend.doc_type).get_api_id()
        except Exception as e:
            logger.error("Failed to get backend for calculating an sms rate "
                         "due to: %s" % e)
            raise SMSRateCalculatorError("Could not obtain connection information.")

        country_code = self.data.get('country_code')
        if country_code == NONMATCHING_COUNTRY:
            country_code = None
        direction = self.data.get('direction')

        gateway_fee = SmsGatewayFee.get_by_criteria(
            backend_api_id, direction, backend_instance=gateway,
            country_code=country_code,
        )
        usage_fee = SmsUsageFee.get_by_criteria(direction, self.request.domain)
        usd_gateway_fee = gateway_fee.amount * gateway_fee.currency.rate_to_default
        usd_total = usage_fee.amount + usd_gateway_fee

        return {
            'rate': _("%s per 160 character SMS") % fmt_dollar_amount(usd_total),
        }
开发者ID:NoahCarnahan,项目名称:commcare-hq,代码行数:28,代码来源:async_handlers.py

示例3: country_code_response

# 需要导入模块: from corehq.apps.sms.mixin import SMSBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.SMSBackend import get [as 别名]
    def country_code_response(self):
        gateway = self.data.get('gateway')
        try:
            backend = SMSBackend.get(gateway)
            backend_api_id = get_backend_by_class_name(backend.doc_type).get_api_id()
        except Exception:
            return []
        direction = self.data.get('direction')
        criteria_query = SmsGatewayFeeCriteria.objects.filter(
            direction=direction, backend_api_id=backend_api_id
        )
        country_codes = criteria_query.exclude(
            country_code__exact=None
        ).values_list('country_code', flat=True).distinct()
        final_codes = []
        for code in country_codes:
            country_name = country_name_from_isd_code_or_empty(code)
            final_codes.append((code, country_name))

        search_term = self.data.get('searchString')
        if search_term:
            search_term = search_term.lower().replace('+', '')
            final_codes = filter(
                lambda x: (str(x[0]).startswith(search_term)
                           or x[1].lower().startswith(search_term)),
                final_codes
            )
        final_codes = [(c[0], "+%s%s" % (c[0], " (%s)" % c[1] if c[1] else '')) for c in final_codes]
        if criteria_query.filter(country_code__exact=None).exists():
            final_codes.append((
                NONMATCHING_COUNTRY,
                _('Any Country (Delivery not guaranteed via connection)')
            ))
        return final_codes
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:36,代码来源:async_handlers.py

示例4: _set_default_domain_backend

# 需要导入模块: from corehq.apps.sms.mixin import SMSBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.SMSBackend import get [as 别名]
def _set_default_domain_backend(request, domain, backend_id, unset=False):
    backend = SMSBackend.get(backend_id)
    if not backend.domain_is_authorized(domain):
        raise Http404
    domain_obj = Domain.get_by_name(domain, strict=True)
    domain_obj.default_sms_backend_id = None if unset else backend._id
    domain_obj.save()
    return HttpResponseRedirect(reverse("list_domain_backends", args=[domain]))
开发者ID:kennknowles,项目名称:commcare-hq,代码行数:10,代码来源:views.py

示例5: create

# 需要导入模块: from corehq.apps.sms.mixin import SMSBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.SMSBackend import get [as 别名]
    def create(cls, message_log, api_response=None):
        phone_number = clean_phone_number(message_log.phone_number)
        direction = message_log.direction

        billable = cls(
            log_id=message_log._id,
            phone_number=phone_number,
            direction=direction,
            date_sent=message_log.date,
            domain=message_log.domain,
        )

        # Fetch gateway_fee
        backend_api_id = message_log.backend_api
        backend_instance = message_log.backend_id

        country_code, national_number = get_country_code_and_national_number(phone_number)

        if backend_instance is None or SMSBackend.get(backend_instance).is_global:
            billable.gateway_fee = SmsGatewayFee.get_by_criteria(
                backend_api_id,
                direction,
                backend_instance=backend_instance,
                country_code=country_code,
                national_number=national_number,
            )
            if billable.gateway_fee is not None:
                conversion_rate = billable.gateway_fee.currency.rate_to_default
                if conversion_rate != 0:
                    billable.gateway_fee_conversion_rate = conversion_rate
                else:
                    smsbillables_logging.error("Gateway fee conversion rate for currency %s is 0",
                                               billable.gateway_fee.currency.code)
            else:
                smsbillables_logging.error(
                    "No matching gateway fee criteria for SMSLog %s" % message_log._id
                )

        # Fetch usage_fee todo
        domain = message_log.domain
        billable.usage_fee = SmsUsageFee.get_by_criteria(
            direction, domain=domain
        )

        if billable.usage_fee is None:
            smsbillables_logging.error("Did not find usage fee for direction %s and domain %s"
                                       % (direction, domain))

        if api_response is not None:
            billable.api_response = api_response

        if backend_api_id == TestSMSBackend.get_api_id():
            billable.is_valid = False

        billable.save()

        return billable
开发者ID:aristide,项目名称:commcare-hq,代码行数:59,代码来源:models.py

示例6: delete_domain_backend

# 需要导入模块: from corehq.apps.sms.mixin import SMSBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.SMSBackend import get [as 别名]
def delete_domain_backend(request, domain, backend_id):
    backend = SMSBackend.get(backend_id)
    if backend.domain != domain or backend.base_doc != "MobileBackend":
        raise Http404
    domain_obj = Domain.get_by_name(domain, strict=True)
    if domain_obj.default_sms_backend_id == backend._id:
        domain_obj.default_sms_backend_id = None
        domain_obj.save()
    backend.retire() # Do not actually delete so that linkage always exists between SMSLog and MobileBackend
    return HttpResponseRedirect(reverse("list_domain_backends", args=[domain]))
开发者ID:kennknowles,项目名称:commcare-hq,代码行数:12,代码来源:views.py

示例7: paginated_list

# 需要导入模块: from corehq.apps.sms.mixin import SMSBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.SMSBackend import get [as 别名]
    def paginated_list(self):
        all_backends = []
        all_backends += SMSBackend.view(
            "sms/backend_by_domain",
            classes=self.backend_classes,
            startkey=[self.domain],
            endkey=[self.domain, {}],
            reduce=False,
            include_docs=True
        ).all()
        all_backends += SMSBackend.view(
            'sms/global_backends',
            classes=self.backend_classes,
            reduce=False,
            include_docs=True
        ).all()

        if len(all_backends) > 0 and not self.domain_object.default_sms_backend_id:
            yield {
                'itemData': {
                    'id': 'nodefault',
                    'name': "Automatic Choose",
                    'status': 'DEFAULT',
                },
                'template': 'gateway-automatic-template',
            }
        elif self.domain_object.default_sms_backend_id:
            default_backend = SMSBackend.get(self.domain_object.default_sms_backend_id)
            yield {
                'itemData': self._fmt_backend_data(default_backend),
                'template': 'gateway-default-template',
            }
        for backend in all_backends:
            if not backend._id == self.domain_object.default_sms_backend_id:
                yield {
                    'itemData': self._fmt_backend_data(backend),
                    'template': 'gateway-template',
                }
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:40,代码来源:views.py

示例8: delete_backend

# 需要导入模块: from corehq.apps.sms.mixin import SMSBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.SMSBackend import get [as 别名]
def delete_backend(request, backend_id):
    backend = SMSBackend.get(backend_id)
    if not backend.is_global or backend.base_doc != "MobileBackend":
        raise Http404
    backend.retire() # Do not actually delete so that linkage always exists between SMSLog and MobileBackend
    return HttpResponseRedirect(reverse("list_backends"))
开发者ID:kennknowles,项目名称:commcare-hq,代码行数:8,代码来源:views.py

示例9: _sms_backend_is_global

# 需要导入模块: from corehq.apps.sms.mixin import SMSBackend [as 别名]
# 或者: from corehq.apps.sms.mixin.SMSBackend import get [as 别名]
def _sms_backend_is_global(sms_backend_id):
    return SMSBackend.get(sms_backend_id).is_global
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:4,代码来源:models.py


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