diff --git a/README.md b/README.md index db95210..90707dd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Owning a Home API -This project feeds detailed mortgage market data to the Consumer Financial Protection Bureau's [Owning a Home suite of tools](http://www.consumerfinance.gov/owning-a-home/). Unfortunately, the raw data set it uses is not available publicly and is not in this repository. +This project feeds detailed mortgage market data to the Consumer Financial Protection Bureau's [Owning a Home suite of tools](http://www.consumerfinance.gov/owning-a-home/). Unfortunately, the main data set it uses is not available publicly and is not in this repository. What is included is the API code and some basic geographical data. If you want to give it a spin, here's how: @@ -47,7 +47,7 @@ pip install -r requirements/test.txt ```shell python manage.py migrate --noinput -python manage.py load_county_limits ~/workspace/owning-a-home-api/data/county_limit_data-flat.csv --confirm=y +python manage.py loaddata countylimits.json python manage.py runserver ``` diff --git a/countylimits/models.py b/countylimits/models.py index 505cf4e..5af0966 100644 --- a/countylimits/models.py +++ b/countylimits/models.py @@ -5,15 +5,18 @@ abbr_to_name = dict(STATE_CHOICES) -""" We are using Federal Information Processing Standard (FIPS) state and county codes. - More information can be found in the following articles: - http://en.wikipedia.org/wiki/Federal_Information_Processing_Standard_state_code - http://en.wikipedia.org/wiki/FIPS_county_code """ +""" +We use Federal Information Processing Standard (FIPS) state and county codes. +More information can be found in the following articles: +http://en.wikipedia.org/wiki/Federal_Information_Processing_Standard_state_code +http://en.wikipedia.org/wiki/FIPS_county_code +""" class State(models.Model): """ A basic State object. """ - state_fips = models.CharField(max_length=2, help_text='A two-digit FIPS code for the state') + state_fips = models.CharField( + max_length=2, help_text='A two-digit FIPS code for the state') state_abbr = USStateField(help_text='A two-letter state abbreviation') def __unicode__(self): @@ -22,7 +25,9 @@ def __unicode__(self): class County(models.Model): """ A basic state county object. """ - county_fips = models.CharField(max_length=3, help_text='A three-digit FIPS code for the state\'s county') + county_fips = models.CharField( + max_length=3, + help_text='A three-digit FIPS code for the state\'s county') county_name = models.CharField(max_length=100, help_text='The county name') state = models.ForeignKey(State) @@ -35,15 +40,18 @@ class CountyLimit(models.Model): fha_limit = models.DecimalField( max_digits=12, decimal_places=2, - help_text='Federal Housing Administration loan lending limit for the county') + help_text='Federal Housing Administration ' + 'loan lending limit for the county') gse_limit = models.DecimalField( max_digits=12, decimal_places=2, - help_text='Loan limit for mortgages acquired by the Government-Sponsored Enterprises') + help_text='Loan limit for mortgages acquired ' + 'by the Government-Sponsored Enterprises') va_limit = models.DecimalField( max_digits=12, decimal_places=2, - help_text='The Department of Veterans Affairs loan guaranty program limit') + help_text='The Department of Veterans Affairs ' + 'loan guaranty program limit') county = models.OneToOneField(County) def __unicode__(self): @@ -54,7 +62,10 @@ def county_limits_by_state(state): """ Get a list of state counties with limits. """ data = [] # state value can be a State FIPS or a state abbr. - result = County.objects.filter(models.Q(state__state_fips=state) | models.Q(state__state_abbr=state)) + result = County.objects.filter( + models.Q(state__state_fips=state) | + models.Q(state__state_abbr=state) + ) counties = {} state_abbr = '' state_fips = '' @@ -67,14 +78,20 @@ def county_limits_by_state(state): 'county_fips': county.county_fips } - result = CountyLimit.objects.filter(models.Q(county__state__state_fips=state) | models.Q(county__state__state_abbr=state)) + result = CountyLimit.objects.filter( + models.Q(county__state__state_fips=state) | + models.Q(county__state__state_abbr=state) + ) for countylimit in result: - data.append({ - 'state': abbr_to_name[state_abbr], - 'county': counties[countylimit.county_id]['county_name'], - 'complete_fips': '%s%s' % (state_fips, counties[countylimit.county_id]['county_fips']), - 'gse_limit': countylimit.gse_limit, - 'fha_limit': countylimit.fha_limit, - 'va_limit': countylimit.va_limit, - }) + data.append( + {'state': abbr_to_name[state_abbr], + 'county': counties[countylimit.county_id]['county_name'], + 'complete_fips': '{}{}'.format( + state_fips, + counties[countylimit.county_id]['county_fips'] + ), + 'gse_limit': countylimit.gse_limit, + 'fha_limit': countylimit.fha_limit, + 'va_limit': countylimit.va_limit} + ) return data