This commit is contained in:
@@ -20,8 +20,7 @@ class GeocodeProvider(Protocol):
|
||||
confidence: float
|
||||
metadata: dict[str, Any]
|
||||
|
||||
def resolve(self, query: str) -> list["LocationMatch"]:
|
||||
...
|
||||
def resolve(self, query: str) -> list[LocationMatch]: ...
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -63,10 +62,7 @@ def parse_belgian_location_query(raw: str) -> tuple[str | None, str | None]:
|
||||
for chunk in re.findall(r"\b\d{4}\b", normalized):
|
||||
postal = chunk
|
||||
break
|
||||
if "," in normalized:
|
||||
municipality_part = normalized.split(",", 1)[0]
|
||||
else:
|
||||
municipality_part = normalized
|
||||
municipality_part = normalized.split(",", 1)[0] if "," in normalized else normalized
|
||||
municipality_part = re.sub(r"\b\d{4}\b", " ", municipality_part)
|
||||
municipality_part = re.sub(r"[^a-z0-9 ]", " ", municipality_part)
|
||||
municipality = " ".join(municipality_part.split())
|
||||
@@ -100,11 +96,12 @@ def _read_rows(path: str | Path) -> list[_ParsedRow]:
|
||||
|
||||
with csv_path.open("r", encoding="utf-8-sig", newline="") as handle:
|
||||
reader = csv.DictReader(handle)
|
||||
headers = set((reader.fieldnames or []))
|
||||
headers = set(reader.fieldnames or [])
|
||||
required = {"postal_code", "municipality", "region", "latitude", "longitude"}
|
||||
if not required.issubset(headers):
|
||||
raise CommandError(
|
||||
"Verplichte kolommen ontbreken: postal_code, municipality, region, latitude, longitude"
|
||||
"Verplichte kolommen ontbreken: postal_code, municipality, region, "
|
||||
"latitude, longitude"
|
||||
)
|
||||
|
||||
for row_number, raw_row in enumerate(reader, start=2):
|
||||
@@ -116,7 +113,9 @@ def _read_rows(path: str | Path) -> list[_ParsedRow]:
|
||||
if not postal_code:
|
||||
raise CommandError(f"regel {row_number}: postal_code mag niet leeg zijn")
|
||||
if len(postal_code) != 4 or not postal_code.isdigit():
|
||||
raise CommandError(f"regel {row_number}: ongeldige Belgische postcode {postal_code}")
|
||||
raise CommandError(
|
||||
f"regel {row_number}: ongeldige Belgische postcode {postal_code}"
|
||||
)
|
||||
if not municipality:
|
||||
raise CommandError(f"regel {row_number}: municipality mag niet leeg zijn")
|
||||
|
||||
@@ -136,7 +135,8 @@ def _read_rows(path: str | Path) -> list[_ParsedRow]:
|
||||
row_key = (postal_code, normalized_municipality)
|
||||
if row_key in seen:
|
||||
raise CommandError(
|
||||
f"regel {row_number}: dubbel record in bestand voor {postal_code} {municipality}"
|
||||
f"regel {row_number}: dubbel record in bestand voor "
|
||||
f"{postal_code} {municipality}"
|
||||
)
|
||||
seen.add(row_key)
|
||||
|
||||
@@ -171,7 +171,9 @@ class CsvGeocodeProvider:
|
||||
self.metadata: dict[str, Any] = metadata or {}
|
||||
|
||||
@staticmethod
|
||||
def _load_candidates(query_value: str, query_kind: str, *, source_name: str, source_version: str):
|
||||
def _load_candidates(
|
||||
query_value: str, query_kind: str, *, source_name: str, source_version: str
|
||||
):
|
||||
return GeocodeLocationLookup.objects.filter(
|
||||
source_name=source_name,
|
||||
source_version=source_version,
|
||||
@@ -307,7 +309,9 @@ def import_csv_geodata(
|
||||
rows = _read_rows(path)
|
||||
|
||||
if len(rows) > 50000:
|
||||
raise CommandError("Importbestand bevat meer dan 50.000 records; import in delen aanbevolen.")
|
||||
raise CommandError(
|
||||
"Importbestand bevat meer dan 50.000 records; import in delen aanbevolen."
|
||||
)
|
||||
|
||||
existing_rows = GeocodeLocationLookup.objects.filter(
|
||||
source_name=source_name,
|
||||
@@ -347,10 +351,7 @@ def import_csv_geodata(
|
||||
row.postal_code,
|
||||
row.municipality,
|
||||
)
|
||||
if (not replace) and (
|
||||
municipal_key in existing_keys
|
||||
or postal_key in existing_keys
|
||||
):
|
||||
if (not replace) and (municipal_key in existing_keys or postal_key in existing_keys):
|
||||
raise CommandError(
|
||||
"Import zou bestaande lookuprecords overschrijven zonder --replace."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user