-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Gather UK counties * Refactor tests * Add county info to admin pages * Feedback
- Loading branch information
1 parent
0fab7a3
commit 6bd2c29
Showing
9 changed files
with
222 additions
and
97 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,18 @@ | ||
# Generated by Django 3.2.20 on 2023-08-04 14:35 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('common', '0039_copy_email_to_username'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='school', | ||
name='county', | ||
field=models.CharField(blank=True, max_length=50, null=True), | ||
), | ||
] |
This file contains 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,23 @@ | ||
import pgeocode | ||
from django.db import migrations | ||
|
||
from portal.helpers.organisation import sanitise_uk_postcode | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("common", "0040_school_county"), | ||
] | ||
|
||
def forwards(apps, schema_editor): | ||
"""Populate the county field for schools in GB""" | ||
School = apps.get_model("common", "School") | ||
gb_schools = School.objects.filter(country="GB") | ||
nomi = pgeocode.Nominatim("GB") | ||
|
||
for school in gb_schools: | ||
county = nomi.query_postal_code(sanitise_uk_postcode(school.postcode)).county_name | ||
school.county = county | ||
school.save() | ||
|
||
operations = [migrations.RunPython(forwards, reverse_code=migrations.RunPython.noop)] |
This file contains 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 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 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 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,10 @@ | ||
# TODO: Move to Address model once we create it | ||
def sanitise_uk_postcode(postcode): | ||
if len(postcode) >= 5: # Valid UK postcodes are at least 5 chars long | ||
outcode = postcode[:-3] # UK incodes are always 3 characters | ||
|
||
# Insert a space between outcode and incode if there isn't already one | ||
if not outcode.endswith(" "): | ||
postcode = postcode[:-3] + " " + postcode[-3:] | ||
|
||
return postcode |
This file contains 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 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