From a831afb60cfaed5ec342fab1e4a7eb83feb9c4f7 Mon Sep 17 00:00:00 2001 From: Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> Date: Fri, 7 May 2021 21:03:33 +0200 Subject: Add search by additional properies --- forms.py | 8 ++++++++ main.py | 34 +++++++++++++++++++++++++++++++++- templates/search_form.html | 18 ++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/forms.py b/forms.py index 9cbad2f..73e576a 100644 --- a/forms.py +++ b/forms.py @@ -30,6 +30,14 @@ class JusticeSearchForm(Form): ulice_search = StringField(u'Ulice:') ulice_search_selection = SelectField('', choices=search_options) ulice_search_actual = SelectField('', choices=actual_options) + + cp_search = StringField(u'Číslo popisné:') + cp_search_selection = SelectField('', choices=search_options) + cp_search_actual = SelectField('', choices=actual_options) + + co_search = StringField(u'Číslo orientační:') + co_search_selection = SelectField('', choices=search_options) + co_search_actual = SelectField('', choices=actual_options) oddil_search = StringField(u'Oddíl:') oddil_search_selection = SelectField('', choices=search_options) diff --git a/main.py b/main.py index ee090d3..608e50f 100644 --- a/main.py +++ b/main.py @@ -178,6 +178,14 @@ def search_results(search): ulice_search_method = search.ulice_search_selection.data ulice_actual_or_full = search.ulice_search_actual.data + co = search.co_search.data + co_search_method = search.co_search_selection.data + co_actual_or_full = search.co_search_actual.data + + cp = search.cp_search.data + cp_search_method = search.cp_search_selection.data + cp_actual_or_full = search.cp_search_actual.data + pravni_forma = search.pravni_forma_search.data pravni_forma_actual_or_full = search.pravni_forma_actual.data @@ -263,7 +271,31 @@ def search_results(search): qry = qry.filter(Adresy_v2.ulice.like(f'{ulice}%')) elif ulice_search_method == "text_exact": qry = qry.filter(Adresy_v2.ulice == ulice) - + + if cp: + qry = qry.join(Sidlo_Association, Company.sidlo_text) + if cp_actual_or_full == "actual_results": + qry = qry.filter(Sidlo_Association.vymaz_datum == 0) + qry = qry.join(Adresy_v2, Sidlo_Association.sidlo_text) + if cp_search_method == "text_anywhere": + qry = qry.filter(Adresy_v2.cisloPo.contains(cp)) + elif cp_search_method == "text_beginning": + qry = qry.filter(Adresy_v2.cisloPo.like(f'{cp}%')) + elif cp_search_method == "text_exact": + qry = qry.filter(Adresy_v2.cisloPo == cp) + + if co: + qry = qry.join(Sidlo_Association, Company.sidlo_text) + if co_actual_or_full == "actual_results": + qry = qry.filter(Sidlo_Association.vymaz_datum == 0) + qry = qry.join(Adresy_v2, Sidlo_Association.sidlo_text) + if co_search_method == "text_anywhere": + qry = qry.filter(Adresy_v2.cisloOr.contains(co)) + elif co_search_method == "text_beginning": + qry = qry.filter(Adresy_v2.cisloOr.like(f'{co}%')) + elif co_search_method == "text_exact": + qry = qry.filter(Adresy_v2.cisloOr == co) + if pravni_forma: qry = qry.join(Pravni_Forma_Association_v2, Company.pravni_forma_text) if pravni_forma_actual_or_full == "actual_results": diff --git a/templates/search_form.html b/templates/search_form.html index 14c387d..f4fc7a9 100644 --- a/templates/search_form.html +++ b/templates/search_form.html @@ -55,6 +55,24 @@ +