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


Python SiteConfiguration.get_twilio_settings方法代码示例

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


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

示例1: calculate_cost

# 需要导入模块: from site_config.models import SiteConfiguration [as 别名]
# 或者: from site_config.models.SiteConfiguration import get_twilio_settings [as 别名]
 def calculate_cost(self):
     """Calculate the cost of sending to this group."""
     try:
         cost = SiteConfiguration.get_twilio_settings()['sending_cost']
     except ConfigurationError:
         cost = 0
     return cost * self.all_recipients.count()
开发者ID:nikolay,项目名称:apostello,代码行数:9,代码来源:models.py

示例2: check_user_cost_limit

# 需要导入模块: from site_config.models import SiteConfiguration [as 别名]
# 或者: from site_config.models.SiteConfiguration import get_twilio_settings [as 别名]
 def check_user_cost_limit(recipients, limit, msg):
     """Check the user has not exceeded their per SMS cost limit."""
     cost = SiteConfiguration.get_twilio_settings()['sending_cost']
     num_sms = ceil(len(msg) / 160)
     if limit == 0:
         return
     if limit < len(recipients) * cost * num_sms:
         raise ValidationError('Sorry, you can only send messages that cost no more than ${0}.'.format(limit))
开发者ID:nikolay,项目名称:apostello,代码行数:10,代码来源:models.py

示例3: decorator

# 需要导入模块: from site_config.models import SiteConfiguration [as 别名]
# 或者: from site_config.models.SiteConfiguration import get_twilio_settings [as 别名]
    def decorator(request_or_self, *args, **kwargs):

        class_based_view = not isinstance(request_or_self, HttpRequest)
        if not class_based_view:
            request = request_or_self
        else:
            assert len(args) >= 1
            request = args[0]

        # Turn off Twilio authentication when explicitly requested, or
        # in debug mode. Otherwise things do not work properly. For
        # more information, see the docs.
        use_forgery_protection = getattr(
            settings,
            'DJANGO_TWILIO_FORGERY_PROTECTION',
            not settings.DEBUG,
        )
        if use_forgery_protection:

            if request.method not in ['GET', 'POST']:
                return HttpResponseNotAllowed(request.method)

            # Forgery check
            try:
                twilio_settings = SiteConfiguration.get_twilio_settings()
                validator = RequestValidator(twilio_settings['auth_token'])
                url = request.build_absolute_uri()
                signature = request.META['HTTP_X_TWILIO_SIGNATURE']
            except (AttributeError, KeyError, ConfigurationError):
                return HttpResponseForbidden()

            if request.method == 'POST':
                if not validator.validate(url, request.POST, signature):
                    return HttpResponseForbidden()
            if request.method == 'GET':
                if not validator.validate(url, request.GET, signature):
                    return HttpResponseForbidden()

        response = f(request_or_self, *args, **kwargs)

        return response
开发者ID:nikolay,项目名称:apostello,代码行数:43,代码来源:twilio.py

示例4: test_upper_chars

# 需要导入模块: from site_config.models import SiteConfiguration [as 别名]
# 或者: from site_config.models.SiteConfiguration import get_twilio_settings [as 别名]
 def test_upper_chars(self):
     with pytest.raises(ValidationError):
         not_twilio_num(SiteConfiguration.get_twilio_settings()['from_num'])
开发者ID:nikolay,项目名称:apostello,代码行数:5,代码来源:test_validators.py

示例5: get_twilio_client

# 需要导入模块: from site_config.models import SiteConfiguration [as 别名]
# 或者: from site_config.models.SiteConfiguration import get_twilio_settings [as 别名]
def get_twilio_client():
    twilio_settings = SiteConfiguration.get_twilio_settings()
    return Client(twilio_settings['sid'], twilio_settings['auth_token'])
开发者ID:nikolay,项目名称:apostello,代码行数:5,代码来源:twilio.py


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