refactor: remove code redundancy and improve maintainability

- Extract duplicate view logic into reusable helper functions in views.py
- Move circular import from module level to method scope in models.py
- Create constants.py for centralized hardcoded values (Nepali words, placeholders)
- Simplify number_to_nepali_words function from 157 to 42 lines
- Refactor normalize_address with extracted helper functions
- Add lang_utils.py for consistent language parameter handling
- Reduce JavaScript duplication in address-chaining.js with helper functions
- Remove ~160+ lines of redundant code while preserving all logic
- All 79 tests passing, ruff linting passes
This commit is contained in:
sankalp committed 2026-02-05 20:49:26 +05:45
1 parent 74936ddabd
commit 718cff2951
8 files changed
+509 -309

No files matched your search

+3 -1
View File
@@ -7,7 +7,6 @@ from django.utils.translation import gettext_lazy as _
from nepali.datetime import nepalidate, nepalidatetime
from nepali.locations import districts, municipalities, provinces
from django_nepkit.forms import NepaliDateFormField
from django_nepkit.utils import (
BS_DATE_FORMAT,
BS_DATETIME_FORMAT,
@@ -172,6 +171,9 @@ class NepaliDateField(BaseNepaliBSField):
parse_func = staticmethod(try_parse_nepali_date)
def formfield(self, **kwargs):
# Import here to avoid circular dependency
from django_nepkit.forms import NepaliDateFormField
kwargs.setdefault("form_class", NepaliDateFormField)
return super().formfield(**kwargs)