Compare commits
5 Commits
c7f89a9ab4
...
filter-lis
| Author | SHA1 | Date | |
|---|---|---|---|
| 33ae8fe124 | |||
| d3471d54ea | |||
| b1ecdd1f0c | |||
| 163f59844f | |||
| 929e16e2ec |
0
db.template.sqlite3
Normal file
0
db.template.sqlite3
Normal file
6775
media/postanski-brojevi.csv
Normal file
6775
media/postanski-brojevi.csv
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,4 +3,4 @@ from django.apps import AppConfig
|
||||
|
||||
class MainConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "main"
|
||||
name = "project.main"
|
||||
|
||||
84
project/main/migrations/0001_initial.py
Normal file
84
project/main/migrations/0001_initial.py
Normal file
@ -0,0 +1,84 @@
|
||||
# Generated by Django 5.0.4 on 2024-04-10 19:31
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="County",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("name", models.CharField(max_length=100)),
|
||||
],
|
||||
options={
|
||||
"db_table": "counties",
|
||||
"ordering": ["name"],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="PostOffice",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("zip", models.PositiveIntegerField()),
|
||||
("name", models.CharField(max_length=100)),
|
||||
],
|
||||
options={
|
||||
"db_table": "post_offices",
|
||||
"ordering": ["zip"],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="Area",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("name", models.CharField(max_length=100)),
|
||||
(
|
||||
"county",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="main.county"
|
||||
),
|
||||
),
|
||||
(
|
||||
"post_office",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="main.postoffice",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"db_table": "areas",
|
||||
"ordering": ["name"],
|
||||
},
|
||||
),
|
||||
]
|
||||
48
project/main/migrations/0002_auto_20240410_1942.py
Normal file
48
project/main/migrations/0002_auto_20240410_1942.py
Normal file
@ -0,0 +1,48 @@
|
||||
# Generated by Django 5.0.4 on 2024-04-10 19:42
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
counties = [
|
||||
'Koprivničko-križevačka',
|
||||
'Međimurska',
|
||||
'Dubrovačko-neretvanska',
|
||||
'Zagrebačka',
|
||||
'Primorsko-goranska',
|
||||
'Požeško-slavonska',
|
||||
'Vukovarsko-srijemska',
|
||||
'Karlovačka',
|
||||
'Zadarska',
|
||||
'Bjelovarsko-bilogorska',
|
||||
'Splitsko-dalmatinska',
|
||||
'Virovitičko-podravska',
|
||||
'Ličko-senjska',
|
||||
'Grad Zagreb',
|
||||
'Brodsko-posavska',
|
||||
'Osječko-baranjska',
|
||||
'Sisačko-moslavačka',
|
||||
'Krapinsko-zagorska',
|
||||
'Istarska',
|
||||
'Šibensko-kninska',
|
||||
'Varaždinska',
|
||||
]
|
||||
|
||||
|
||||
def create_counties(apps, schema_editor):
|
||||
County = apps.get_model("main", "County")
|
||||
|
||||
bulk = []
|
||||
|
||||
for county in counties:
|
||||
bulk.append(County(name=county))
|
||||
|
||||
County.objects.bulk_create(bulk)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("main", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_counties),
|
||||
]
|
||||
333
project/main/migrations/0003_auto_20240410_1959.py
Normal file
333
project/main/migrations/0003_auto_20240410_1959.py
Normal file
@ -0,0 +1,333 @@
|
||||
# Generated by Django 5.0.4 on 2024-04-10 19:59
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
post_offices = {
|
||||
10000: 'Zagreb',
|
||||
10010: 'Zagreb-Sloboština',
|
||||
10020: 'Zagreb-Novi Zagreb',
|
||||
10040: 'Zagreb-Dubrava',
|
||||
10090: 'Zagreb-Susedgrad',
|
||||
10104: 'Zagreb',
|
||||
10105: 'Zagreb',
|
||||
10108: 'Zagreb',
|
||||
10109: 'Zagreb',
|
||||
10110: 'Zagreb',
|
||||
10135: 'Zagreb',
|
||||
10172: 'Zagreb',
|
||||
10250: 'Lučko',
|
||||
10255: 'Gornji Stupnik',
|
||||
10257: 'Brezovica',
|
||||
10290: 'Zaprešić',
|
||||
10291: 'Prigorje Brdovečko',
|
||||
10292: 'Šenkovec',
|
||||
10295: 'Kupljenovo',
|
||||
10297: 'Jakovlje',
|
||||
10298: 'Bistra',
|
||||
10310: 'Ivanić Grad',
|
||||
10315: 'Novoselec',
|
||||
10340: 'Vrbovec',
|
||||
10342: 'Dubrava',
|
||||
10360: 'Sesvete',
|
||||
10361: 'Sesvete Kraljevec',
|
||||
10362: 'Kašina',
|
||||
10370: 'Dugo Selo',
|
||||
10380: 'Sveti Ivan Zelina',
|
||||
10410: 'Velika Gorica',
|
||||
10413: 'Kravarsko',
|
||||
10414: 'Pokupsko',
|
||||
10430: 'Samobor',
|
||||
10431: 'Sveta Nedelja',
|
||||
10435: 'Sveti Martin pod Okićem',
|
||||
10437: 'Bestovje',
|
||||
10450: 'Jastrebarsko',
|
||||
10451: 'Pisarovina',
|
||||
10454: 'Krašić',
|
||||
20000: 'Dubrovnik',
|
||||
20207: 'Mlini',
|
||||
20210: 'Cavtat',
|
||||
20215: 'Gruda',
|
||||
20221: 'Koločep',
|
||||
20222: 'Lopud',
|
||||
20223: 'Šipanska Luka',
|
||||
20225: 'Babino Polje',
|
||||
20230: 'Ston',
|
||||
20232: 'Slano',
|
||||
20235: 'Zaton Veliki',
|
||||
20236: 'Mokošica',
|
||||
20240: 'Trpanj',
|
||||
20244: 'Potomje',
|
||||
20246: 'Janjina',
|
||||
20250: 'Orebić',
|
||||
20260: 'Korčula',
|
||||
20270: 'Vela Luka',
|
||||
20271: 'Blato',
|
||||
20290: 'Lastovo',
|
||||
20340: 'Ploče',
|
||||
20350: 'Metković',
|
||||
20355: 'Opuzen',
|
||||
21000: 'Split',
|
||||
21203: 'Donji Muć',
|
||||
21204: 'Dugopolje',
|
||||
21210: 'Solin',
|
||||
21212: 'Kaštel Sućurac',
|
||||
21214: 'Kaštel Kambelovac',
|
||||
21217: 'Kaštel Štafilić',
|
||||
21220: 'Trogir',
|
||||
21222: 'Marina',
|
||||
21225: 'Drvenik Veliki',
|
||||
21230: 'Sinj',
|
||||
21240: 'Trilj',
|
||||
21232: 'Dicmo',
|
||||
21233: 'Hrvace',
|
||||
21236: 'Vrlika',
|
||||
21238: 'Otok (Dalmacija)',
|
||||
21250: 'Šestanovac',
|
||||
21256: 'Cista Provo',
|
||||
21260: 'Imotski',
|
||||
21270: 'Zagvozd',
|
||||
21276: 'Vrgorac',
|
||||
21300: 'Makarska',
|
||||
21310: 'Omiš',
|
||||
21311: 'Stobreč',
|
||||
21315: 'Dugi Rat',
|
||||
21320: 'Baška Voda',
|
||||
21327: 'Podgora',
|
||||
21330: 'Gradac',
|
||||
21400: 'Supetar',
|
||||
21405: 'Milna',
|
||||
21412: 'Pučišća',
|
||||
21420: 'Bol',
|
||||
21425: 'Selca',
|
||||
21430: 'Grohote',
|
||||
21450: 'Hvar',
|
||||
21460: 'Stari Grad',
|
||||
21465: 'Jelsa',
|
||||
21469: 'Sućuraj',
|
||||
21480: 'Vis',
|
||||
21485: 'Komiža',
|
||||
22000: 'Šibenik',
|
||||
22202: 'Primošten',
|
||||
22211: 'Vodice',
|
||||
22213: 'Pirovac',
|
||||
22222: 'Skradin',
|
||||
22232: 'Zlarin',
|
||||
22233: 'Prvić Luka',
|
||||
22234: 'Prvić Šepurine',
|
||||
22235: 'Kaprije',
|
||||
22236: 'Žirje',
|
||||
22240: 'Tisno',
|
||||
22243: 'Murter',
|
||||
22300: 'Knin',
|
||||
22320: 'Drniš',
|
||||
22323: 'Unešić',
|
||||
23000: 'Zadar',
|
||||
23205: 'Bibinje',
|
||||
23206: 'Sukošan',
|
||||
23210: 'Biograd na Moru',
|
||||
23212: 'Tkon',
|
||||
23222: 'Zemunik',
|
||||
23223: 'Škabrnja',
|
||||
23232: 'Nin',
|
||||
23233: 'Privlaka',
|
||||
23234: 'Vir',
|
||||
23235: 'Vrsi',
|
||||
23241: 'Poličnik',
|
||||
23242: 'Posedarje',
|
||||
23244: 'Starigrad Paklenica',
|
||||
23248: 'Ražanac',
|
||||
23250: 'Pag',
|
||||
23271: 'Kukljica',
|
||||
23273: 'Preko',
|
||||
23281: 'Sali',
|
||||
23283: 'Rava',
|
||||
23284: 'Veli Iž',
|
||||
23286: 'Božava',
|
||||
23287: 'Veli Rat',
|
||||
23291: 'Sestrunj',
|
||||
23292: 'Molat',
|
||||
23293: 'Ist',
|
||||
23294: 'Premuda',
|
||||
23295: 'Silba',
|
||||
23296: 'Olib',
|
||||
23312: 'Novigrad (Dalmacija)',
|
||||
23420: 'Benkovac',
|
||||
23422: 'Stankovci',
|
||||
23440: 'Gračac',
|
||||
23450: 'Obrovac',
|
||||
31000: 'Osijek',
|
||||
31200: 'Osijek',
|
||||
31207: 'Tenja',
|
||||
31226: 'Dalj',
|
||||
31300: 'Beli Manastir',
|
||||
31326: 'Darda',
|
||||
31400: 'Đakovo',
|
||||
31431: 'Čepin',
|
||||
31500: 'Našice',
|
||||
31540: 'Donji Miholjac',
|
||||
31550: 'Valpovo',
|
||||
31551: 'Belišće',
|
||||
32000: 'Vukovar',
|
||||
32100: 'Vinkovci',
|
||||
32236: 'Ilok',
|
||||
32242: 'Slakovci',
|
||||
32249: 'Tovarnik',
|
||||
32252: 'Otok',
|
||||
32257: 'Drenovci',
|
||||
32270: 'Županja',
|
||||
32284: 'Stari Mikanovci',
|
||||
33000: 'Virovitica',
|
||||
33405: 'Pitomača',
|
||||
33410: 'Suhopolje',
|
||||
33515: 'Orahovica',
|
||||
33520: 'Slatina',
|
||||
34000: 'Požega',
|
||||
34310: 'Pleternica',
|
||||
34340: 'Kutjevo',
|
||||
34550: 'Pakrac',
|
||||
35000: 'Slavonski Brod',
|
||||
35212: 'Garčin',
|
||||
35214: 'Donji Andrijevci',
|
||||
35220: 'Slavonski Šamac',
|
||||
35222: 'Gundinci',
|
||||
35250: 'Oriovac',
|
||||
35252: 'Sibinj',
|
||||
35400: 'Nova Gradiška',
|
||||
35410: 'Nova Kapela',
|
||||
35420: 'Staro Petrovo Selo',
|
||||
35430: 'Okučani',
|
||||
40000: 'Čakovec',
|
||||
40313: 'Sveti Martin na Muri',
|
||||
40315: 'Mursko Središče',
|
||||
40320: 'Donji Kraljevec',
|
||||
40323: 'Prelog',
|
||||
42000: 'Varaždin',
|
||||
42202: 'Trnovec Bartolovečki',
|
||||
42204: 'Turčin',
|
||||
42208: 'Cestica',
|
||||
42220: 'Novi Marof',
|
||||
42223: 'Varaždinske Toplice',
|
||||
42230: 'Ludbreg',
|
||||
42240: 'Ivanec',
|
||||
42243: 'Maruševec',
|
||||
42250: 'Lepoglava',
|
||||
43000: 'Bjelovar',
|
||||
43240: 'Čazma',
|
||||
43270: 'Veliki Grđevac',
|
||||
43280: 'Garešnica',
|
||||
43290: 'Grubišno Polje',
|
||||
43500: 'Daruvar',
|
||||
44000: 'Sisak',
|
||||
44010: 'Sisak-Caprag',
|
||||
44210: 'Sunja',
|
||||
44250: 'Petrinja',
|
||||
44317: 'Popovača',
|
||||
44320: 'Kutina',
|
||||
44330: 'Novska',
|
||||
44400: 'Glina',
|
||||
44410: 'Vrginmost',
|
||||
44430: 'Hrvatska Kostajnica',
|
||||
44440: 'Dvor',
|
||||
47000: 'Karlovac',
|
||||
47220: 'Vojnić',
|
||||
47240: 'Slunj',
|
||||
47250: 'Duga Resa',
|
||||
47280: 'Ozalj',
|
||||
47300: 'Ogulin',
|
||||
48000: 'Koprivnica',
|
||||
48214: 'Sveti Ivan Žabno',
|
||||
48260: 'Križevci',
|
||||
48316: 'Đelekovec',
|
||||
48350: 'Đurđevac',
|
||||
49000: 'Krapina',
|
||||
49210: 'Zabok',
|
||||
49216: 'Desinić',
|
||||
49217: 'Krapinske Toplice',
|
||||
49218: 'Pregrada',
|
||||
49221: 'Bedekovčina',
|
||||
49223: 'Sveti Križ Začretje',
|
||||
49225: 'Đurmanec',
|
||||
49231: 'Hum na Sutli',
|
||||
49240: 'Donja Stubica',
|
||||
49243: 'Oroslavje',
|
||||
49246: 'Marija Bistrica',
|
||||
49250: 'Zlatar',
|
||||
49252: 'Mihovljan',
|
||||
49282: 'Konjščina',
|
||||
49284: 'Budinščina',
|
||||
49290: 'Klanjec',
|
||||
51000: 'Rijeka',
|
||||
51211: 'Matulji',
|
||||
51215: 'Kastav',
|
||||
51216: 'Viškovo',
|
||||
51217: 'Klana',
|
||||
51218: 'Dražice',
|
||||
51224: 'Krasica',
|
||||
51226: 'Hreljin',
|
||||
51250: 'Novi Vinodolski',
|
||||
51260: 'Crikvenica',
|
||||
51262: 'Kraljevica',
|
||||
51280: 'Rab',
|
||||
51300: 'Delnice',
|
||||
51306: 'Čabar',
|
||||
51326: 'Vrbovsko',
|
||||
51410: 'Opatija',
|
||||
51415: 'Lovran',
|
||||
51417: 'Mošćenička Draga',
|
||||
51500: 'Krk',
|
||||
51511: 'Malinska',
|
||||
51523: 'Baška',
|
||||
51550: 'Mali Lošinj',
|
||||
51552: 'Ilovik',
|
||||
51556: 'Martinšćica',
|
||||
51557: 'Cres',
|
||||
51561: 'Susak',
|
||||
51562: 'Unije',
|
||||
52000: 'Pazin',
|
||||
52100: 'Pula (Pola)',
|
||||
52207: 'Barban',
|
||||
52210: 'Rovinj (Rovigno)',
|
||||
52220: 'Labin',
|
||||
52333: 'Podpićan',
|
||||
52341: 'Žminj',
|
||||
52420: 'Buzet',
|
||||
52424: 'Motovun (Montona)',
|
||||
52440: 'Poreč (Parenzo)',
|
||||
52460: 'Buje (Buie)',
|
||||
52466: 'Novigrad-Cittanova',
|
||||
52470: 'Umag (Umago)',
|
||||
53000: 'Gospić',
|
||||
53202: 'Perušić',
|
||||
53220: 'Otočac',
|
||||
53230: 'Korenica',
|
||||
53234: 'Udbina',
|
||||
53250: 'Donji Lapac',
|
||||
53260: 'Brinje',
|
||||
53270: 'Senj',
|
||||
53288: 'Karlobag',
|
||||
53291: 'Novalja',
|
||||
}
|
||||
|
||||
|
||||
def create_post_offices(apps, schema_editor):
|
||||
PostOffice = apps.get_model("main", "PostOffice")
|
||||
|
||||
bulk = []
|
||||
|
||||
for key, name in post_offices.items():
|
||||
bulk.append(PostOffice(
|
||||
zip=key,
|
||||
name=name,
|
||||
))
|
||||
|
||||
PostOffice.objects.bulk_create(bulk)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("main", "0002_auto_20240410_1942"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(create_post_offices),
|
||||
]
|
||||
6863
project/main/migrations/0004_auto_20240411_0605.py
Normal file
6863
project/main/migrations/0004_auto_20240411_0605.py
Normal file
File diff suppressed because it is too large
Load Diff
3
project/main/models/__init__.py
Normal file
3
project/main/models/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .area import Area
|
||||
from .county import County
|
||||
from .post_office import PostOffice
|
||||
11
project/main/models/area.py
Normal file
11
project/main/models/area.py
Normal file
@ -0,0 +1,11 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Area(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
post_office = models.ForeignKey("PostOffice", on_delete=models.CASCADE)
|
||||
county = models.ForeignKey("County", on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
db_table = "areas"
|
||||
ordering = ["name"]
|
||||
9
project/main/models/county.py
Normal file
9
project/main/models/county.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class County(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
class Meta:
|
||||
db_table = "counties"
|
||||
ordering = ["name"]
|
||||
10
project/main/models/post_office.py
Normal file
10
project/main/models/post_office.py
Normal file
@ -0,0 +1,10 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class PostOffice(models.Model):
|
||||
zip = models.PositiveIntegerField()
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
class Meta:
|
||||
db_table = "post_offices"
|
||||
ordering = ["zip"]
|
||||
53
project/main/templates/main/components/pagination.html
Normal file
53
project/main/templates/main/components/pagination.html
Normal file
@ -0,0 +1,53 @@
|
||||
{% macro pagination(page) %}
|
||||
{% macro render_link(title, page_number) %}
|
||||
<a
|
||||
class="page-link"
|
||||
href="#"
|
||||
hx-get="{{ url("filter-list-filter") }}"
|
||||
hx-trigger="click"
|
||||
hx-target="#filter-list-container"
|
||||
hx-include="[name='zip'],[name='area'],[name='county']"
|
||||
hx-vals='{"page": "{{ page_number }}"}'
|
||||
>
|
||||
{{ title }}
|
||||
</a>
|
||||
{% endmacro %}
|
||||
|
||||
{% if page.has_other_pages() %}
|
||||
<nav aria-label="Page navigation example">
|
||||
<ul class="pagination">
|
||||
{% if page.has_previous() %}
|
||||
<li class="page-item">
|
||||
{{ render_link(title="Previous", page_number=page.number - 1) }}
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
<a class="page-link" href="#">Previous</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% for p in page.paginator.get_elided_page_range(page.number, on_each_side=2, on_ends=3) %}
|
||||
{% if p != page.paginator.ELLIPSIS %}
|
||||
<li class="page-item {% if page.number == p %}active{% endif %}">
|
||||
{{ render_link(title=p, page_number=p) }}
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item">
|
||||
<span class="page-link border-top-0 border-bottom-0">{{ page.paginator.ELLIPSIS }}</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if page.has_next() %}
|
||||
<li class="page-item">
|
||||
{{ render_link(title="Next", page_number=page.number + 1) }}
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
<a class="page-link" href="#">Next</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
@ -3,5 +3,66 @@
|
||||
|
||||
|
||||
{% block content %}
|
||||
{{ js_alert_work_in_progress() }}
|
||||
<div class="card mb-2">
|
||||
<div class="card-body">
|
||||
<form id="filter-form"
|
||||
class="row g-2 align-items-center"
|
||||
>
|
||||
<div class="col-auto">
|
||||
<label class="form-label mb-0">ZIP:</label>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<input
|
||||
type="number"
|
||||
name="zip"
|
||||
class="form-control"
|
||||
hx-get="{{ url("filter-list-filter") }}"
|
||||
hx-trigger="keyup"
|
||||
hx-target="#filter-list-container"
|
||||
hx-include="[name='area'],[name='county']"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="form-label mb-0">Area:</label>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<input
|
||||
type="text"
|
||||
name="area"
|
||||
class="form-control"
|
||||
hx-get="{{ url("filter-list-filter") }}"
|
||||
hx-trigger="keyup"
|
||||
hx-target="#filter-list-container"
|
||||
hx-include="[name='zip'],[name='county']"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="form-label mb-0">County:</label>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<select
|
||||
name="county"
|
||||
class="form-select"
|
||||
hx-get="{{ url("filter-list-filter") }}"
|
||||
hx-trigger="change"
|
||||
hx-target="#filter-list-container"
|
||||
hx-include="[name='zip'],[name='area']"
|
||||
>
|
||||
<option value="">
|
||||
- All -
|
||||
</option>
|
||||
{% for county in counties %}
|
||||
<option value="{{ county.id }}">
|
||||
{{ county.name }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="filter-list-container">
|
||||
{% include "main/filter_list_content.html" %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
25
project/main/templates/main/filter_list_content.html
Normal file
25
project/main/templates/main/filter_list_content.html
Normal file
@ -0,0 +1,25 @@
|
||||
{% from "main/components/pagination.html" import pagination %}
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Zip Code</th>
|
||||
<th>Post Office</th>
|
||||
<th>Area</th>
|
||||
<th>County</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for area in page.object_list %}
|
||||
<tr>
|
||||
<td>{{ area.post_office.zip }}</td>
|
||||
<td>{{ area.post_office.name }}</td>
|
||||
<td>{{ area.name }}</td>
|
||||
<td>{{ area.county.name }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
{{ pagination(page) }}
|
||||
@ -4,7 +4,7 @@ from .complex_form.views import (
|
||||
RouteModuleHandleView,
|
||||
WarehouseManagementHandleView,
|
||||
)
|
||||
from .filter_list import FilterListView
|
||||
from .filter_list import FilterListFilterView, FilterListView
|
||||
from .form_validation import FormValidationView
|
||||
from .home import HomeView
|
||||
from .swap import SwapView
|
||||
|
||||
@ -1,7 +1,76 @@
|
||||
from typing import Any
|
||||
|
||||
from django.core.paginator import Page, Paginator
|
||||
from django.db.models import Q, QuerySet
|
||||
|
||||
from project.main.models import Area, County
|
||||
from project.main.views.demo_view_base import DemoViewBase
|
||||
|
||||
PAGE_SIZE = 20
|
||||
|
||||
class FilterListView(DemoViewBase):
|
||||
|
||||
def get_all_counties() -> QuerySet[County]:
|
||||
return County.objects.all()
|
||||
|
||||
|
||||
class FilterListViewBase(DemoViewBase):
|
||||
def paginate(self, qs: QuerySet[Area]) -> Page:
|
||||
page = int(self.request.GET.get("page", 1))
|
||||
page_size = int(self.request.GET.get("page_size", PAGE_SIZE))
|
||||
|
||||
paginator = Paginator(
|
||||
object_list=qs,
|
||||
per_page=page_size,
|
||||
)
|
||||
return paginator.get_page(page)
|
||||
|
||||
|
||||
class FilterListView(FilterListViewBase):
|
||||
template_name = "main/filter_list.html"
|
||||
active_section = "filter-list"
|
||||
title = "Filter List"
|
||||
|
||||
def get_context_data(self, **kwargs) -> dict[str, Any]:
|
||||
context_data = super().get_context_data(**kwargs)
|
||||
|
||||
page = self.paginate(
|
||||
qs=Area.objects.select_related("county", "post_office").all(),
|
||||
)
|
||||
context_data.update(
|
||||
{
|
||||
"page": page,
|
||||
"counties": get_all_counties(),
|
||||
}
|
||||
)
|
||||
return context_data
|
||||
|
||||
|
||||
class FilterListFilterView(FilterListViewBase):
|
||||
template_name = "main/filter_list_content.html"
|
||||
|
||||
def get_context_data(self, **kwargs) -> dict[str, Any]:
|
||||
context_data = super().get_context_data(**kwargs)
|
||||
|
||||
q = Q()
|
||||
zip = self.request.GET.get("zip", None)
|
||||
area = self.request.GET.get("area", None)
|
||||
county = self.request.GET.get("county", None)
|
||||
|
||||
if zip:
|
||||
q &= Q(post_office__zip=zip)
|
||||
if area:
|
||||
q &= Q(name__icontains=area)
|
||||
if county:
|
||||
q &= Q(county_id=county)
|
||||
|
||||
page = self.paginate(
|
||||
qs=Area.objects.select_related("county", "post_office").filter(q),
|
||||
)
|
||||
|
||||
context_data.update(
|
||||
{
|
||||
"page": page,
|
||||
"counties": get_all_counties(),
|
||||
}
|
||||
)
|
||||
return context_data
|
||||
|
||||
@ -37,6 +37,7 @@ INSTALLED_APPS = [
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"project.main",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from django.conf import settings
|
||||
from django.urls import path
|
||||
|
||||
from project.main import views
|
||||
@ -6,10 +10,35 @@ urlpatterns = [
|
||||
path("", views.HomeView.as_view(), name="home"),
|
||||
path("swap", views.SwapView.as_view(), name="swap"),
|
||||
path("filter-list", views.FilterListView.as_view(), name="filter-list"),
|
||||
path(
|
||||
"filter-list/filter", views.FilterListFilterView.as_view(), name="filter-list-filter"
|
||||
),
|
||||
path("form-validation", views.FormValidationView.as_view(), name="form-validation"),
|
||||
path("complex-form", views.ComplexFormView.as_view(), name="complex-form"),
|
||||
path("complex-form/handle/route-module", views.RouteModuleHandleView.as_view(), name="complex-form-handle-route-module"),
|
||||
path("complex-form/handle/reports", views.ReportsHandleView.as_view(), name="complex-form-handle-reports"),
|
||||
path("complex-form/handle/warehouse-management", views.WarehouseManagementHandleView.as_view(), name="complex-form-handle-warehouse-management"),
|
||||
path("table-inline-edit", views.TableInlineEditView.as_view(), name="table-inline-edit"),
|
||||
path(
|
||||
"complex-form/handle/route-module",
|
||||
views.RouteModuleHandleView.as_view(),
|
||||
name="complex-form-handle-route-module",
|
||||
),
|
||||
path(
|
||||
"complex-form/handle/reports",
|
||||
views.ReportsHandleView.as_view(),
|
||||
name="complex-form-handle-reports",
|
||||
),
|
||||
path(
|
||||
"complex-form/handle/warehouse-management",
|
||||
views.WarehouseManagementHandleView.as_view(),
|
||||
name="complex-form-handle-warehouse-management",
|
||||
),
|
||||
path(
|
||||
"table-inline-edit",
|
||||
views.TableInlineEditView.as_view(),
|
||||
name="table-inline-edit",
|
||||
),
|
||||
]
|
||||
|
||||
# check if db exists, and copy from template if not
|
||||
if not Path.exists(settings.DATABASES["default"]["NAME"]):
|
||||
template_filename = settings.BASE_DIR / "db.template.sqlite3"
|
||||
shutil.copyfile(template_filename, settings.DATABASES["default"]["NAME"])
|
||||
print("Database copied from template.")
|
||||
|
||||
Reference in New Issue
Block a user