def get_carrier_region(self, request): data = self.req_data() or self.request.GET if 'region' in data and 'carrier' in data: carrier = data['carrier'] region = data['region'] elif 'mnc' in data and 'mcc' in data: try: carrier = MOBILE_CODES[int(data['mcc'])][int(data['mnc'])] if isinstance(carrier, dict): carrier = carrier.get(data.get('spn', '__default')) if carrier is None: raise ParseError('Invalid mcc/mnc/spn triplet') region = REGIONS_BY_MCC[int(data['mcc'])] except (KeyError, ValueError): raise ParseError("Invalid mnc/mcc pair") else: raise ParseError("Both 'region' and 'carrier' or both " "'mnc' and 'mcc' parameters must be provided") try: carrier = int(carrier) except ValueError: c = CARRIER_MAP.get(carrier) if c is None: raise ParseError("No carrier " + repr(carrier)) carrier = c.id try: region = int(region) except ValueError: r = REGIONS_DICT.get(region) if r is None: raise ParseError("No region " + repr(region)) region = r.id return carrier, region
def get_queryset(self, *args, **kwargs): return REGIONS_DICT.values()
def get_queryset(self, *args, **kwargs): return sorted(REGIONS_DICT.values(), key=operator.attrgetter('name'))