import logging from django.http import HttpResponse, JsonResponse from django.utils.html import format_html from django_nepkit.conf import nepkit_settings from django_nepkit.utils import ( get_districts_by_province, get_municipalities_by_district, ) logger = logging.getLogger(__name__) # Accepted values for ``?ne=`` / ``?en=`` query params. Anything else is # either treated as "not provided" (default) or, with ``strict=True``, # rejected. _TRUE_VALUES = {"true", "1", "yes", "on"} _FALSE_VALUES = {"false", "0", "no", "off"} def _coerce_bool(raw): """Validate a boolean query string value. Returns: ``True``/``False`` if the value is recognised, ``None`` otherwise. """ if raw is None: return None lowered = raw.lower() if lowered in _TRUE_VALUES: return True if lowered in _FALSE_VALUES: return False return None def _render_options(data, placeholder): """Render a list of location options as HTML. Each ``