def get_opt_keywords(msg): backend_class = get_sms_backend_classes().get(msg.backend_api, SQLSMSBackend) return ( backend_class.get_opt_in_keywords(), backend_class.get_opt_out_keywords(), backend_class.get_pass_through_opt_in_keywords(), )
def __init__(self, is_superuser=False, *args, **kwargs): super(InitiateAddSMSBackendForm, self).__init__(*args, **kwargs) from corehq.messaging.smsbackends.telerivet.models import SQLTelerivetBackend backend_classes = get_sms_backend_classes() backend_choices = [] for api_id, klass in backend_classes.items(): if is_superuser or api_id == SQLTelerivetBackend.get_api_id(): friendly_name = klass.get_generic_name() backend_choices.append((api_id, friendly_name)) self.fields['hq_api_id'].choices = backend_choices self.helper = FormHelper() self.helper.label_class = 'col-sm-3 col-md-4 col-lg-2' self.helper.field_class = 'col-sm-9 col-md-8 col-lg-6' self.helper.form_class = "form form-horizontal" self.helper.layout = crispy.Layout( hqcrispy.B3MultiField( _("Create Another Gateway"), InlineField('action'), Div(InlineField('hq_api_id'), css_class='col-sm-6 col-md-6 col-lg-4'), Div(StrictButton( mark_safe('<i class="fa fa-plus"></i> Add Another Gateway'), css_class='btn-success', type='submit', style="margin-left:5px;" ), css_class='col-sm-3 col-md-2 col-lg-2'), ), )
def _available_gateway_fee_backends(): return [ backend for backend in get_sms_backend_classes().values() if backend.get_api_id() not in [SQLTwilioBackend.get_api_id(), InfobipBackend.get_api_id()] ]
def __init__(self, is_superuser=False, *args, **kwargs): super(InitiateAddSMSBackendForm, self).__init__(*args, **kwargs) from corehq.messaging.smsbackends.telerivet.models import SQLTelerivetBackend backend_classes = get_sms_backend_classes() backend_choices = [] for api_id, klass in backend_classes.items(): if is_superuser or api_id == SQLTelerivetBackend.get_api_id(): friendly_name = klass.get_generic_name() backend_choices.append((api_id, friendly_name)) backend_choices = sorted(backend_choices, key=lambda backend: backend[1]) self.fields['hq_api_id'].choices = backend_choices self.helper = HQFormHelper() self.helper.layout = crispy.Layout( hqcrispy.B3MultiField( _("Create Another Gateway"), InlineField('action'), Div(InlineField('hq_api_id', css_class="ko-select2"), css_class='col-sm-6 col-md-6 col-lg-4'), Div(StrictButton(mark_safe( '<i class="fa fa-plus"></i> Add Another Gateway'), css_class='btn-primary', type='submit', style="margin-left:5px;"), css_class='col-sm-3 col-md-2 col-lg-2'), ), )
def arbitrary_fees_by_backend_instance(backend_ids): fees = {} for direction in DIRECTIONS: fees_by_backend = {} for backend in get_sms_backend_classes().values(): fees_by_backend[backend.get_api_id()] = (backend_ids[backend.get_api_id()], arbitrary_fee()) fees[direction] = fees_by_backend return fees
def arbitrary_fees_by_direction_and_backend(): fees = {} for direction in DIRECTIONS: fees_by_backend = {} for backend in get_sms_backend_classes().values(): fees_by_backend[backend.get_api_id()] = arbitrary_fee() fees[direction] = fees_by_backend return fees
def arbitrary_fees_by_all(backend_ids): fees = {} for direction in DIRECTIONS: fees_by_backend = {} for backend in get_sms_backend_classes().values(): fees_by_country = {} for country in TEST_COUNTRY_CODES: fees_by_country[country] = (backend_ids[backend.get_api_id()], arbitrary_fee()) fees_by_backend[backend.get_api_id()] = fees_by_country fees[direction] = fees_by_backend return fees
def arbitrary_backend_ids(): backend_ids = {} for backend in get_sms_backend_classes().values(): backend_instance = data_gen.arbitrary_unique_name("back") backend_ids[backend.get_api_id()] = backend_instance sms_backend = backend() sms_backend.hq_api_id = backend.get_api_id() sms_backend.couch_id = backend_instance sms_backend.name = backend_instance sms_backend.is_global = True sms_backend.save() return backend_ids
def handle(self, gateway_api_id, **kwargs): backend_class = get_sms_backend_classes()[gateway_api_id] amount = kwargs['amount'] country = kwargs['country'] decimal_pattern = re.compile("[0-9.]+") if amount is not None and decimal_pattern.fullmatch(amount) is None: raise CommandError('the amount option must be a number') number_pattern = re.compile("[0-9]+") if country is not None and number_pattern.fullmatch(country) is None: raise CommandError('the country option must be a whole number') _bootstrap_gateway(None, backend_class, amount, country)
def get_opt_keywords(msg): backend_class = get_sms_backend_classes().get(msg.backend_api, SQLSMSBackend) try: backend_model = msg.outbound_backend except (BadSMSConfigException, SQLMobileBackend.DoesNotExist): # Backend not found, we will just use the default custom_opt_out = [] custom_opt_in = [] else: custom_opt_out = backend_model.opt_out_keywords custom_opt_in = backend_model.opt_in_keywords return ( backend_class.get_opt_in_keywords() + custom_opt_in, backend_class.get_opt_out_keywords() + custom_opt_out, backend_class.get_pass_through_opt_in_keywords(), )
def arbitrary_fees_by_prefix(backend_ids, country_codes_and_prefixes): fees = {} for direction in DIRECTIONS: fees_by_backend = {} for backend in get_sms_backend_classes().values(): fees_by_country_code = {} for country_code, _ in country_codes_and_prefixes: fees_by_country_code[country_code] = {} for country_code, prefix in country_codes_and_prefixes: fees_by_prefix = { backend_instance: arbitrary_fee() for backend_instance in [backend_ids[backend.get_api_id()], None] } fees_by_country_code[country_code][prefix] = fees_by_prefix fees_by_backend[backend.get_api_id()] = fees_by_country_code fees[direction] = fees_by_backend return fees
def handle(self, gateway_api_id, **kwargs): backend_class = get_sms_backend_classes()[gateway_api_id] _bootstrap_gateway(None, backend_class)
def _available_direct_fee_backends(): return [ backend for backend in get_sms_backend_classes().values() if backend.using_api_to_get_fees ]
def _available_gateway_fee_backends(): return filter( lambda backend: backend.get_api_id() != SQLTwilioBackend.get_api_id(), get_sms_backend_classes().values())
def _available_gateway_fee_backends(): return [ backend for backend in get_sms_backend_classes().values() if backend.get_api_id() != SQLTwilioBackend.get_api_id() ]
def _available_gateway_fee_backends(): return filter( lambda backend: backend.get_api_id() != SQLTwilioBackend.get_api_id(), get_sms_backend_classes().values() )
def _available_gateway_fee_backends(): return [ backend for backend in get_sms_backend_classes().values() if not backend.using_api_to_get_fees ]