diff --git a/download/__pycache__/models.cpython-38.pyc b/download/__pycache__/models.cpython-38.pyc index 7d4ef18..e7b4814 100644 Binary files a/download/__pycache__/models.cpython-38.pyc and b/download/__pycache__/models.cpython-38.pyc differ diff --git a/download/__pycache__/urls.cpython-38.pyc b/download/__pycache__/urls.cpython-38.pyc index 754f5f8..2b230db 100644 Binary files a/download/__pycache__/urls.cpython-38.pyc and b/download/__pycache__/urls.cpython-38.pyc differ diff --git a/download/__pycache__/views.cpython-38.pyc b/download/__pycache__/views.cpython-38.pyc index 51e73f9..96ff520 100644 Binary files a/download/__pycache__/views.cpython-38.pyc and b/download/__pycache__/views.cpython-38.pyc differ diff --git a/download/models.py b/download/models.py index 8e266ef..0e880b2 100644 --- a/download/models.py +++ b/download/models.py @@ -7,6 +7,11 @@ class Address(models.Model): address = models.CharField(max_length=128) # TODO: add validation columns in relation to city city = models.CharField(max_length=32) + def toDict(self): + return { + 'address': self.address, + 'id': self.id + } class PDF(models.Model): path = models.CharField(max_length=64) diff --git a/download/templates/common/master.html b/download/templates/common/master.html index 1adb4f2..cbc928b 100644 --- a/download/templates/common/master.html +++ b/download/templates/common/master.html @@ -2,8 +2,17 @@ {% block title %}{% endblock %} + + + {% include 'common/navbar.html' %} {% block body %} {% endblock %} diff --git a/download/templates/common/navbar.html b/download/templates/common/navbar.html new file mode 100644 index 0000000..b2e9e82 --- /dev/null +++ b/download/templates/common/navbar.html @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/download/templates/download/download-page.html b/download/templates/download/download-page.html index f5a5c2d..bbc50f5 100644 --- a/download/templates/download/download-page.html +++ b/download/templates/download/download-page.html @@ -1,7 +1,29 @@ {% extends 'common/master.html' %} {% block body %}

Download Your Quote

- {% for thing in things %} -

{{ thing.address }}

- {% endfor %} + + + + {% endblock %} diff --git a/download/urls.py b/download/urls.py index e495319..f4351ee 100644 --- a/download/urls.py +++ b/download/urls.py @@ -4,4 +4,5 @@ from . import views urlpatterns = [ path('', views.starter, name='download'), path('d//', views.download, name='download_f'), + path('search//', views.search, name='search'), ] diff --git a/download/views.py b/download/views.py index 84a0190..294a351 100644 --- a/download/views.py +++ b/download/views.py @@ -1,7 +1,8 @@ -from django.shortcuts import render, HttpResponse +from django.shortcuts import render, HttpResponse from django.http import FileResponse from .models import Address, PDF from .forms import CodeForm +import json # Create your views here. def starter(request): @@ -9,6 +10,13 @@ def starter(request): 'things': list(Address.objects.all()) }) +def search(request, addr): + if len(addr) <= 3: + return HttpResponse(json.dumps([])) + return HttpResponse(json.dumps( + [x.toDict() for x in Address.objects.filter(address__startswith=addr)] + )) + def download(request, pdfid): if request.method == 'POST': form = CodeForm(request.POST)