예제 #1
0
def ba_from_request(request, ba=None):
    """
    Given a GET request with location info, return balancing authority
       name and model queryset.
    Location info can be st (state), or ba (balancing authority).
    Future support for lat+lng, zipcode, country code, etc.
    Returns tuple of (string, QuerySet)
    """
    if ba:
        # use supplied ba
        ba = ba.upper()
        
    else:
        # try state
        state = request.GET.get('st', None)
        if state:
          state = state.upper()
          ba = BALANCING_AUTHORITIES.get(state, None)
    
        # try BA
        else:
            ba = request.GET.get('ba', None)
            if ba:
              ba = ba.upper()
      
    # got nothing
    try:
        return ba, BA_MODELS[ba].objects.all()
    except:
        logging.debug('returning null BA')
        return ba, None
예제 #2
0
 def test_supported_states(self):
     for st in ['CA',
                'CT', 'MA', 'ME', 'NH', 'RI', 'VT', 
                'ID', 'OR', 'WA',
                'MN', 'MI', 'IA', 'IL', 'IN', 'ND', 'SD', 'WI',
                'PA', 'NJ', 'MD', 'DE', 'DC', 'VA', 'WV', 'KY']:
         self.assertIn(st, BALANCING_AUTHORITIES.keys())