refactor: global project refinement, DRY consolidation, and documentation overhaul

This commit represents a comprehensive improvement of the library's architecture, developer experience, and documentation accuracy.

Core Refactoring:
- apply DRY principle to models.py by introducing BaseNepaliBSField and BaseLocationField
- standardize widget logic in widgets.py using NepaliWidgetMixin
- centralize admin filtering logic into BaseNepaliDateFilter

New Features & API:
- add NepaliMonthFilter for Django Admin and NepaliDateMonthFilter for DRF
- implementation of HTMX-driven location chaining for dynamic address selects
- extend demo project with comprehensive DRF search, ordering, and filter examples

Configuration & Sync:
- implement global NEPKIT settings in conf.py (DEFAULT_LANGUAGE, ADMIN_DATEPICKER, etc.)
- universalize BS_DATE_FORMAT/BS_DATETIME_FORMAT across the entire stack
- synchronize frontend datepicker initialization with backend date formats

Documentation & DX:
- complete rewrite of README.md into high-energy, factual, English-only guides
- project-wide audit and simplification of comments/docstrings for beginner accessibility
- expanded 'Technical Design' and 'FAQ' sections covering data integrity and storage
- added docs/migration_guide.py for bulk AD-to-BS data transitions

Quality & Maintenance:
- fixed all E402 module-level import errors across the library
- verified codebase with project-wide ruff checks (all checks passed)
This commit is contained in:
sankalp committed 2026-01-30 17:00:33 +05:45
1 parent 09f302ceaa
commit 1338f9e5fe
32 files changed
+3002 -531

No files matched your search

+9 -19
View File
@@ -7,12 +7,12 @@ from nepali.locations import districts, provinces
from django_nepkit.conf import nepkit_settings
BS_DATE_FORMAT = "%Y-%m-%d"
BS_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
BS_DATE_FORMAT = nepkit_settings.BS_DATE_FORMAT
BS_DATETIME_FORMAT = nepkit_settings.BS_DATETIME_FORMAT
def _try_parse_nepali(value: Any, cls: Any, fallback_fmt: str) -> Any:
"""Internal helper to parse Nepali date/datetime."""
"""Helper to turn a string into a Nepali date object."""
if value in (None, ""):
return None
if isinstance(value, cls):
@@ -31,29 +31,23 @@ def _try_parse_nepali(value: Any, cls: Any, fallback_fmt: str) -> Any:
def try_parse_nepali_date(value: Any) -> Optional[nepalidate]:
"""
Best-effort conversion to `nepalidate`.
"""
"""Convert any value to a Nepali Date."""
return _try_parse_nepali(value, nepalidate, BS_DATE_FORMAT)
def try_parse_nepali_datetime(value: Any) -> Optional[nepalidatetime]:
"""
Best-effort conversion to `nepalidatetime`.
"""
"""Convert any value to a Nepali Date and Time."""
return _try_parse_nepali(value, nepalidatetime, BS_DATETIME_FORMAT)
def _get_location_children(parent_list, parent_name, child_attr, ne=False):
"""
Internal helper to finding a parent in a list and returning its children (districts/municipalities).
"""
"""Find children (like districts) of a parent (like a province)."""
selected_parent = None
for p in parent_list:
p_name = p.name
p_name_ne = getattr(p, "name_nepali", None)
# Mapping fix for lookups
# Handle province name variations
if parent_name == "Koshi Province":
if p_name == "Province 1":
selected_parent = p
@@ -85,15 +79,11 @@ def _get_location_children(parent_list, parent_name, child_attr, ne=False):
def get_districts_by_province(province_name, ne=False, en=True):
"""
Returns a list of districts in the given province.
"""
"""Get all districts for a province."""
# Logic note: if ne=True is passed, we shouldn't care about en=True (handled by caller typically)
return _get_location_children(provinces, province_name, "districts", ne=ne)
def get_municipalities_by_district(district_name, ne=False, en=True):
"""
Returns a list of municipalities in the given district.
"""
"""Get all municipalities for a district."""
return _get_location_children(districts, district_name, "municipalities", ne=ne)