django-nepkit 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. django_nepkit/__init__.py +20 -0
  2. django_nepkit/admin.py +243 -93
  3. django_nepkit/conf.py +34 -0
  4. django_nepkit/filters.py +113 -0
  5. django_nepkit/forms.py +9 -9
  6. django_nepkit/models.py +143 -162
  7. django_nepkit/serializers.py +127 -28
  8. django_nepkit/static/django_nepkit/js/address-chaining.js +105 -18
  9. django_nepkit/static/django_nepkit/js/nepal-data.js +1 -0
  10. django_nepkit/static/django_nepkit/js/nepali-datepicker-init.js +55 -46
  11. django_nepkit/utils.py +396 -46
  12. django_nepkit/validators.py +1 -1
  13. django_nepkit/views.py +66 -3
  14. django_nepkit/widgets.py +100 -31
  15. django_nepkit-0.2.0.dist-info/METADATA +308 -0
  16. django_nepkit-0.2.0.dist-info/RECORD +35 -0
  17. example/demo/admin.py +45 -21
  18. example/demo/models.py +41 -4
  19. example/demo/serializers.py +39 -0
  20. example/demo/urls.py +13 -2
  21. example/demo/views.py +125 -3
  22. example/example_project/settings.py +10 -0
  23. example/example_project/urls.py +1 -1
  24. example/manage.py +2 -2
  25. django_nepkit/templatetags/__init__.py +0 -0
  26. django_nepkit/templatetags/nepali.py +0 -74
  27. django_nepkit-0.1.0.dist-info/METADATA +0 -377
  28. django_nepkit-0.1.0.dist-info/RECORD +0 -39
  29. example/demo/migrations/0001_initial.py +0 -2113
  30. example/demo/migrations/0002_alter_person_phone_number.py +0 -18
  31. example/demo/migrations/0003_person_created_at_person_updated_at.py +0 -27
  32. example/demo/migrations/0004_alter_person_created_at_alter_person_updated_at.py +0 -23
  33. example/demo/migrations/0005_alter_person_created_at_alter_person_updated_at.py +0 -27
  34. example/demo/migrations/__init__.py +0 -0
  35. {django_nepkit-0.1.0.dist-info → django_nepkit-0.2.0.dist-info}/WHEEL +0 -0
  36. {django_nepkit-0.1.0.dist-info → django_nepkit-0.2.0.dist-info}/licenses/LICENSE +0 -0
  37. {django_nepkit-0.1.0.dist-info → django_nepkit-0.2.0.dist-info}/top_level.txt +0 -0
@@ -18,47 +18,134 @@
18
18
  selectElement.dispatchEvent(new Event('change'));
19
19
  }
20
20
 
21
+ function getLocalData(type, parentId, isNepali) {
22
+ if (!window.NEPKIT_DATA) return null;
23
+ const lang = isNepali ? 'ne' : 'en';
24
+ const data = window.NEPKIT_DATA[lang];
25
+ if (!data) return null;
26
+
27
+ if (type === 'districts') {
28
+ return data.districts[parentId] || [];
29
+ } else if (type === 'municipalities') {
30
+ return data.municipalities[parentId] || [];
31
+ }
32
+ return null;
33
+ }
34
+
35
+ function getMatchingSelect(container, selector, isNepali) {
36
+ const matches = container.querySelectorAll(selector);
37
+ for (let el of matches) {
38
+ const elIsNepali = el.dataset.ne === 'true';
39
+ if (elIsNepali === isNepali) {
40
+ return el;
41
+ }
42
+ }
43
+ return null;
44
+ }
45
+
46
+ function init() {
47
+ document.querySelectorAll('.nepkit-province-select').forEach(provinceSelect => {
48
+ const isNepali = provinceSelect.dataset.ne === 'true';
49
+ const container = provinceSelect.closest('form') || document;
50
+ const districtSelect = getMatchingSelect(container, '.nepkit-district-select', isNepali);
51
+ const municipalitySelect = getMatchingSelect(container, '.nepkit-municipality-select', isNepali);
52
+
53
+ if (!provinceSelect.value) {
54
+ if (districtSelect && !districtSelect.value) {
55
+ updateOptions(districtSelect, [], isNepali ? 'जिल्ला छान्नुहोस्' : 'Select District');
56
+ }
57
+ if (municipalitySelect && !municipalitySelect.value) {
58
+ updateOptions(municipalitySelect, [], isNepali ? 'नगरपालिका छान्नुहोस्' : 'Select Municipality');
59
+ }
60
+ }
61
+ });
62
+
63
+ document.querySelectorAll('.nepkit-district-select').forEach(districtSelect => {
64
+ const isNepali = districtSelect.dataset.ne === 'true';
65
+ const container = districtSelect.closest('form') || document;
66
+ const municipalitySelect = getMatchingSelect(container, '.nepkit-municipality-select', isNepali);
67
+
68
+ if (!districtSelect.value) {
69
+ if (municipalitySelect && !municipalitySelect.value) {
70
+ updateOptions(municipalitySelect, [], isNepali ? 'नगरपालिका छान्नुहोस्' : 'Select Municipality');
71
+ }
72
+ }
73
+ });
74
+ }
75
+
21
76
  document.addEventListener('change', function(e) {
22
77
  if (e.target.matches('.nepkit-province-select')) {
23
78
  const province = e.target.value;
79
+ const isNepali = e.target.dataset.ne === 'true';
24
80
  const container = e.target.closest('form') || document;
25
- const districtSelect = container.querySelector('.nepkit-district-select');
26
- const municipalitySelect = container.querySelector('.nepkit-municipality-select');
81
+ const districtSelect = getMatchingSelect(container, '.nepkit-district-select', isNepali);
82
+ const municipalitySelect = getMatchingSelect(container, '.nepkit-municipality-select', isNepali);
83
+
84
+ // Always clear municipality if province changes
85
+ if (municipalitySelect) {
86
+ updateOptions(municipalitySelect, [], isNepali ? 'नगरपालिका छान्नुहोस्' : 'Select Municipality');
87
+ }
27
88
 
28
89
  if (districtSelect) {
29
90
  if (!province) {
30
- updateOptions(districtSelect, [], 'Select District');
31
- if (municipalitySelect) updateOptions(municipalitySelect, [], 'Select Municipality');
91
+ updateOptions(districtSelect, [], isNepali ? 'जिल्ला छान्नुहोस्' : 'Select District');
32
92
  return;
33
93
  }
34
94
 
35
- const url = districtSelect.dataset.url + '?province=' + encodeURIComponent(province);
36
- fetch(url)
37
- .then(response => response.json())
38
- .then(data => {
39
- updateOptions(districtSelect, data, 'Select District');
40
- });
95
+ const localData = getLocalData('districts', province, isNepali);
96
+
97
+ if (localData) {
98
+ updateOptions(districtSelect, localData, isNepali ? 'जिल्ला छान्नुहोस्' : 'Select District');
99
+ } else if (districtSelect.dataset.url) {
100
+ // Fallback to AJAX
101
+ let url = districtSelect.dataset.url + '?province=' + encodeURIComponent(province);
102
+ if (isNepali) url += '&ne=true';
103
+ if (districtSelect.dataset.en === 'true') url += '&en=true';
104
+
105
+ fetch(url)
106
+ .then(response => response.json())
107
+ .then(data => {
108
+ updateOptions(districtSelect, data, isNepali ? 'जिल्ला छान्नुहोस्' : 'Select District');
109
+ });
110
+ }
41
111
  }
42
112
  }
43
113
 
44
114
  if (e.target.matches('.nepkit-district-select')) {
45
115
  const district = e.target.value;
116
+ const isNepali = e.target.dataset.ne === 'true';
46
117
  const container = e.target.closest('form') || document;
47
- const municipalitySelect = container.querySelector('.nepkit-municipality-select');
118
+ const municipalitySelect = getMatchingSelect(container, '.nepkit-municipality-select', isNepali);
48
119
 
49
120
  if (municipalitySelect) {
50
121
  if (!district) {
51
- updateOptions(municipalitySelect, [], 'Select Municipality');
122
+ updateOptions(municipalitySelect, [], isNepali ? 'नगरपालिका छान्नुहोस्' : 'Select Municipality');
52
123
  return;
53
124
  }
54
125
 
55
- const url = municipalitySelect.dataset.url + '?district=' + encodeURIComponent(district);
56
- fetch(url)
57
- .then(response => response.json())
58
- .then(data => {
59
- updateOptions(municipalitySelect, data, 'Select Municipality');
60
- });
126
+ const localData = getLocalData('municipalities', district, isNepali);
127
+
128
+ if (localData) {
129
+ updateOptions(municipalitySelect, localData, isNepali ? 'नगरपालिका छान्नुहोस्' : 'Select Municipality');
130
+ } else if (municipalitySelect.dataset.url) {
131
+ // Fallback to AJAX
132
+ let url = municipalitySelect.dataset.url + '?district=' + encodeURIComponent(district);
133
+ if (isNepali) url += '&ne=true';
134
+ if (municipalitySelect.dataset.en === 'true') url += '&en=true';
135
+
136
+ fetch(url)
137
+ .then(response => response.json())
138
+ .then(data => {
139
+ updateOptions(municipalitySelect, data, isNepali ? 'नगरपालिका छान्नुहोस्' : 'Select Municipality');
140
+ });
141
+ }
61
142
  }
62
143
  }
63
144
  });
145
+
146
+ if (document.readyState === 'loading') {
147
+ document.addEventListener('DOMContentLoaded', init);
148
+ } else {
149
+ init();
150
+ }
64
151
  })();