feat: implement HTMX support, DRF filters, and professionalized documentation

- Implement server-side location chaining with HTMX support via `htmx=True` in fields and widgets.
- Update location views to handle HTMX requests and return HTML <option> fragments.
- Add NepaliDateYearFilter and NepaliDateRangeFilter for robust DRF API filtering.
- Expand default `DATE_INPUT_FORMATS` in configuration to support multiple common Nepali date styles.
- Update DRF serializers to automatically respect global `NEPKIT` configuration settings.
- Add `django-filter` as an optional dependency under the `drf` extra in pyproject.toml.
- Correct underlying dependency references from `nepali-datetime` to nepali library.
- Complete overhaul of README.md for premium DX, including new sections for storage behavior, timezone awareness, and API usage.
This commit is contained in:
sankalp committed 2026-01-30 15:22:13 +05:45
1 parent 7b07835e0c
commit 09f302ceaa
18 files changed
+2644 -164

No files matched your search

+26 -18
View File
@@ -2,6 +2,8 @@ from django import forms
from django.urls import reverse_lazy
from nepali.datetime import nepalidate
from django_nepkit.conf import nepkit_settings
def _append_css_class(attrs, class_name: str):
"""
@@ -14,12 +16,11 @@ def _append_css_class(attrs, class_name: str):
class NepaliWidgetMixin:
def __init__(self, *args, **kwargs):
self.ne = kwargs.pop("ne", False)
en_value = kwargs.pop("en", True)
if self.ne:
self.en = False
else:
self.en = en_value
default_lang = nepkit_settings.DEFAULT_LANGUAGE
self.ne = kwargs.pop("ne", default_lang == "ne")
self.en = kwargs.pop("en", not self.ne)
self.htmx = kwargs.pop("htmx", False)
attrs = kwargs.get("attrs", {}) or {}
@@ -51,28 +52,35 @@ class ChainedSelectWidget(forms.Select):
class ProvinceSelectWidget(NepaliWidgetMixin, ChainedSelectWidget):
def _configure_attrs(self, attrs):
_append_css_class(attrs, "nepkit-province-select")
if self.htmx:
url = reverse_lazy("django_nepkit:district-list")
attrs.update({
"hx-get": url,
"hx-target": ".nepkit-district-select",
"hx-trigger": "change",
})
class DistrictSelectWidget(NepaliWidgetMixin, ChainedSelectWidget):
def _configure_attrs(self, attrs):
_append_css_class(attrs, "nepkit-district-select")
try:
url = reverse_lazy("django_nepkit:district-list")
str(url) # Force evaluation to catch NoReverseMatch
attrs["data-url"] = url
except Exception:
pass
url = reverse_lazy("django_nepkit:district-list")
attrs["data-url"] = url
if self.htmx:
url_muni = reverse_lazy("django_nepkit:municipality-list")
attrs.update({
"hx-get": url_muni,
"hx-target": ".nepkit-municipality-select",
"hx-trigger": "change",
})
class MunicipalitySelectWidget(NepaliWidgetMixin, ChainedSelectWidget):
def _configure_attrs(self, attrs):
_append_css_class(attrs, "nepkit-municipality-select")
try:
url = reverse_lazy("django_nepkit:municipality-list")
str(url) # Force evaluation to catch NoReverseMatch
attrs["data-url"] = url
except Exception:
pass
url = reverse_lazy("django_nepkit:municipality-list")
attrs["data-url"] = url
class NepaliDatePickerWidget(NepaliWidgetMixin, forms.TextInput):