address-service/address/steps.py

22 lines
763 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Шаг поиска поверх уровня ГАР.
Уровень в базе совпадает с ФИАС. Исключение шага: посёлок ``п.`` на уровне улицы
(8) — это населённый пункт, например ``п. Аякс`` на острове Русский.
"""
from django.db.models import Q
STREET_LEVEL = 8
def normalize_type_name(value: str) -> str:
return value.casefold().replace("ё", "е").strip().rstrip(".")
def is_street_level_locality(level: int | None, type_name: str | None) -> bool:
return level == STREET_LEVEL and normalize_type_name(type_name or "") == "п"
def street_level_locality_q() -> Q:
return Q(level=STREET_LEVEL, type_name__in=("п", "п.", "П", "П."))