-
Notifications
You must be signed in to change notification settings - Fork 56
Zip #2012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Zip #2012
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
065c7a1
Added leading zeros to postal code for w/ and w/o extension cases.
lainsworth8801 c5c2d0b
Modify data properties excel with postal codes for testing
lainsworth8801 212bcbf
clean up
lainsworth8801 2283bf4
mapper cleanup
lainsworth8801 691844b
Merge branch 'develop' of https://github.com/SEED-platform/seed into zip
lainsworth8801 4c5f944
Modify postal excel file and util.py for testing; added test cases fo…
lainsworth8801 d2c39ec
Added leading zeros to 0 zip; modified test to do explicit check
lainsworth8801 a9bc1d7
Added owner postal for filling zeros
lainsworth8801 e970d47
Db rehash with zero-packed zips
lainsworth8801 a8a52cd
Merge branch 'develop' of https://github.com/SEED-platform/seed into zip
lainsworth8801 8da33ee
rerun travis
lainsworth8801 3f76064
Merge branch 'develop' of https://github.com/SEED-platform/seed into zip
lainsworth8801 a751163
Merge branch 'develop' of https://github.com/SEED-platform/seed into zip
lainsworth8801 1b7b06f
Minor tweak
lainsworth8801 88993b3
Merge branch 'develop' of https://github.com/SEED-platform/seed into zip
lainsworth8801 1dd389c
Merge branch 'develop' into zip
nllong 024c3eb
Merge branch 'develop' into zip
nllong 5e8115f
fix migration order
nllong 1864338
fix migration to only find postal codes of length 4 to fix
nllong 86af8b5
Merge branch 'develop' into zip
nllong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| # This rehashing file should be used in the future if needed as it has been optimized. Rehashing takes | ||
| # awhile and should be avoided if possible. | ||
| from __future__ import unicode_literals | ||
|
|
||
| import re | ||
|
|
||
| from django.db import migrations, transaction | ||
| from django.db.models import Q | ||
|
|
||
|
|
||
| def zero_fill(postal): | ||
| if postal: | ||
| if bool(re.compile(r'(\b\d{1,5}-\d{1,4}\b)').match(postal)): | ||
| return postal.split('-')[0].zfill(5) + '-' + postal.split('-')[1].zfill(4) | ||
| elif bool(re.compile(r'(\b\d{1,5}\b)').match(postal)): | ||
| return postal.zfill(5) | ||
|
|
||
|
|
||
| # Go through every property and tax lot and simply save it to create the hash_object | ||
| def update_postal_codes(apps, schema_editor): | ||
| PropertyState = apps.get_model('seed', 'PropertyState') | ||
| TaxLotState = apps.get_model('seed', 'TaxLotState') | ||
|
|
||
| with transaction.atomic(): | ||
| print('Checking for short postal codes in property states') | ||
| objs = PropertyState.objects.filter( | ||
| Q(postal_code__iregex=r'^\d{4}-\d{3,4}$') | Q(postal_code__iregex=r'^\d{4}$') | | ||
| Q(owner_postal_code__iregex=r'^\d{4}-\d{3,4}$') | Q(owner_postal_code__iregex=r'^\d{4}$') | ||
| ) | ||
| for obj in objs: | ||
| # print( | ||
| # f'fixing zip for {obj} -- postal_code | owner_postal_code = {obj.postal_code} | {obj.owner_postal_code}') | ||
| obj.postal_code = zero_fill(obj.postal_code) | ||
| obj.owner_postal_code = zero_fill(obj.owner_postal_code) | ||
| obj.save() | ||
|
|
||
| print('Checking for short postal codes in tax lot states') | ||
| objs = TaxLotState.objects.filter( | ||
| Q(postal_code__iregex=r'^\d{4}-\d{3,4}$') | Q(postal_code__iregex=r'^\d{4}$') | ||
| ) | ||
| for obj in objs: | ||
| # print( | ||
| # f'fixing zip for {obj} -- postal_code | owner_postal_code = {obj.postal_code} | {obj.owner_postal_code}') | ||
| obj.postal_code = zero_fill(obj.postal_code) | ||
| obj.save() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ('seed', '0114_auto_20191211_0958'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(update_postal_codes), | ||
| ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.