예제 #1
0
    def country_code_response(self):
        gateway = self.data.get('gateway')
        try:
            backend_api_id = SQLMobileBackend.get_backend_api_id(gateway, is_couch_id=True)
        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
예제 #2
0
    def country_code_response(self):
        gateway = self.data.get('gateway')
        try:
            backend_api_id = SQLMobileBackend.get_backend_api_id(
                gateway, is_couch_id=True)
        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 = [
                x for x in final_codes if str(x[0]).startswith(search_term)
                or x[1].lower().startswith(search_term)
            ]
        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