feat: implement address normalization and demo

- Add utility to parse raw address strings into structured Province, District, and Municipality data.
- Support both English and Nepali (Devanagari) inputs with smart matching for character variations.
- Implement comprehensive test suite for address normalization logic.
- Add real-time address normalization demo to the example app using HTMX.
- Update README with documentation and usage examples for the new utility.
This commit is contained in:
sankalp committed 2026-01-30 20:23:18 +05:45
1 parent c6301686cc
commit ef8c75bf36
11 files changed
+322 -33

No files matched your search

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<title>Address Normalization Demo</title>
<style>
body { font-family: sans-serif; margin: 20px; }
.form-group { margin-bottom: 15px; }
label { display: block; margin-bottom: 5px; }
input { width: 400px; padding: 8px; }
.result-box { margin-top: 20px; border: 1px solid #ddd; padding: 15px; background: #f9f9f9; }
</style>
<script src="https://unpkg.com/htmx.org@1.9.5"></script>
</head>
<body>
<h1>Address Normalization Demo</h1>
<p>Enter an address string to extract Province, District, and Municipality.</p>
<form hx-get="{% url 'demo:address-normalize' %}" hx-target="#result-area" hx-trigger="keyup changed delay:300ms from:#address-input">
<div class="form-group">
<label for="address-input">Address String:</label>
<input type="text" id="address-input" name="address" placeholder="e.g. Kathmandu or काठमाडौँ" value="{{ address }}">
</div>
</form>
<div id="result-area">
{% include "demo/address_normalize_partial.html" %}
</div>
<br>
<a href="{% url 'demo:person-list' %}">Back to List</a>
</body>
</html>
@@ -0,0 +1,14 @@
{% if result %}
<div class="result-box">
<h3>Normalized Result:</h3>
<ul>
<li><strong>Province:</strong> {{ result.province|default:"Not found" }}</li>
<li><strong>District:</strong> {{ result.district|default:"Not found" }}</li>
<li><strong>Municipality:</strong> {{ result.municipality|default:"Not found" }}</li>
</ul>
</div>
{% elif address %}
<div style="color: darkorange; margin-top: 20px;">
No matching location found for "{{ address }}". Try typing a specific name.
</div>
{% endif %}
+3 -2
View File
@@ -12,8 +12,9 @@
</head>
<body>
<h1>Person List</h1>
<a href="{% url 'demo:person-create' %}">Add New Person</a> |
<a href="{% url 'demo:transaction-create' %}">Add New Transaction</a>
<a href="{% url 'demo:person-create' %}">Add New Person</a> |
<a href="{% url 'demo:transaction-create' %}">Add New Transaction</a> |
<a href="{% url 'demo:address-normalize' %}">Address Normalization Demo</a>
<hr>
<table>
<thead>