Skip to content
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

Import-script-process-improvements #7066

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions polling_stations/apps/data_importers/base_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,19 @@ class BaseCsvStationsCsvAddressesImporter(BaseStationsAddressesImporter, CsvMixi
stations_filetype = "csv"
addresses_filetype = "csv"

def should_ignore_uprns(self, record, *uprns_to_ignore):
record_uprn = getattr(record, self.residential_uprn_field).strip().lstrip("0")

return record_uprn in uprns_to_ignore

def should_ignore_postcode(self, record, postcodes_to_ignore):
record_postcode = (
getattr(record, self.residential_postcode_field)
.strip()
.replace("\xa0", " ")
)
return record_postcode in postcodes_to_ignore

def get_station_postcode(self, record):
return getattr(record, self.station_postcode_field).strip()

Expand Down
21 changes: 12 additions & 9 deletions polling_stations/apps/data_importers/ems_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ class BaseXpressDemocracyClubCsvImporter(BaseXpressCsvImporter, metaclass=abc.AB
easting_field = "polling_place_easting"
northing_field = "polling_place_northing"
residential_uprn_field = "property_urn"
residential_postcode_field = "addressline6"

def address_record_to_dict(self, record):
if record.addressline6.strip() == "":
if getattr(record, self.residential_postcode_field).strip() == "":
return None

address = format_residential_address(
Expand All @@ -240,7 +241,7 @@ def address_record_to_dict(self, record):

return {
"address": address.strip(),
"postcode": record.addressline6.strip(),
"postcode": getattr(record, self.residential_postcode_field).strip(),
"polling_station_id": getattr(record, self.station_id_field).strip(),
"uprn": uprn,
}
Expand Down Expand Up @@ -318,6 +319,7 @@ class BaseHalaroseCsvImporter(
"pollingstationaddress_5",
]
residential_uprn_field = "uprn"
residential_postcode_field = "housepostcode"

def get_station_hash(self, record):
return "-".join(
Expand Down Expand Up @@ -415,7 +417,7 @@ def address_record_to_dict(self, record):
if record.streetname.lower().strip() == "other electors address":
return None

if record.housepostcode.strip() == "":
if getattr(record, self.residential_postcode_field).strip() == "":
return None

address = self.get_residential_address(record)
Expand All @@ -429,7 +431,7 @@ def address_record_to_dict(self, record):

return {
"address": address,
"postcode": record.housepostcode.strip(),
"postcode": getattr(record, self.residential_postcode_field).strip(),
"polling_station_id": station_id,
"uprn": uprn,
}
Expand All @@ -452,16 +454,17 @@ class BaseDemocracyCountsCsvImporter(
csv_delimiter = ","
station_name_field = "placename"
address_fields = ["add1", "add2", "add3", "add4", "add5", "add6"]
postcode_field = "postcode"
station_postcode_field = "postcode"
station_id_field = "stationcode"
residential_uprn_field = "uprn"
residential_postcode_field = "postcode"

def address_record_to_dict(self, record):
if getattr(record, self.postcode_field).strip() == "A1 1AA":
if getattr(record, self.residential_postcode_field).strip() == "A1 1AA":
# this is a dummy record
return None

if not getattr(record, self.postcode_field).strip():
if not getattr(record, self.residential_postcode_field).strip():
return None

address = format_residential_address(
Expand All @@ -475,7 +478,7 @@ def address_record_to_dict(self, record):

return {
"address": address,
"postcode": getattr(record, self.postcode_field).strip(),
"postcode": getattr(record, self.residential_postcode_field).strip(),
"polling_station_id": getattr(record, self.station_id_field).strip(),
"uprn": uprn,
}
Expand Down Expand Up @@ -518,7 +521,7 @@ def station_record_to_dict(self, record):

return {
"internal_council_id": getattr(record, self.station_id_field).strip(),
"postcode": getattr(record, self.postcode_field).strip(),
"postcode": getattr(record, self.station_postcode_field).strip(),
"address": address,
"location": location,
}
Expand Down