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()
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))
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))
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
def test_upper_chars(self): with pytest.raises(ValidationError): not_twilio_num(SiteConfiguration.get_twilio_settings()['from_num'])
def get_twilio_client(): twilio_settings = SiteConfiguration.get_twilio_settings() return Client(twilio_settings["sid"], twilio_settings["auth_token"])
def get_twilio_client(): twilio_settings = SiteConfiguration.get_twilio_settings() return Client(twilio_settings['sid'], twilio_settings['auth_token'])