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:
8 files changed
+509
-309
No files matched your search
@@ -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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user