From 53e6b03b8f68b85c10a2c7c4412a792b5bd4755d Mon Sep 17 00:00:00 2001 From: Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> Date: Fri, 30 Apr 2021 23:37:02 +0200 Subject: work in progress on entity search in company role --- app.py | 3 +- forms.py | 24 ++++++++++++++-- main.py | 53 ++++++++++++++++++++++++++++++++++- templates/header.html | 2 +- templates/results_entities.html | 10 +++++++ templates/search_form_entity.html | 59 +++++++++++++++++++++++++++++++++++++++ templates/search_form_person.html | 1 - 7 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 templates/results_entities.html create mode 100644 templates/search_form_entity.html diff --git a/app.py b/app.py index c89b6e6..57572ab 100644 --- a/app.py +++ b/app.py @@ -14,7 +14,8 @@ from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///justice.db' app.config["SQLALCHEMY_ECHO"] = True -app.secret_key = "123456" app.debug = True +# CHANGE THIS FOR PRODUCTION :) +app.secret_key = "123456" toolbar = DebugToolbarExtension(app) db = SQLAlchemy(app) \ No newline at end of file diff --git a/forms.py b/forms.py index a482fd5..66ed90c 100644 --- a/forms.py +++ b/forms.py @@ -82,8 +82,7 @@ class JusticeSearchForm(Form): zapis_do = DateField(u'Zapsáno do:', format='%Y-%m-%d') zapis_od = DateField(u'Zapsáno od:', format='%Y-%m-%d') -class PersonSearchForm(Form): - +class PersonSearchForm(Form): # VYMAZAT DUPLICITU search_options = [("text_anywhere","Kedkoliv v textu"), ("text_beginning","Začátek výrazu"), @@ -103,7 +102,28 @@ class PersonSearchForm(Form): person_actual_selection = SelectField('', choices=actual_options) birthday = DateField(u'Datum narození:', format='%Y-%m-%d') + +class EntitySearchForm(Form): + # VYMAZAT DUPLICITU + search_options = [("text_anywhere","Kedkoliv v textu"), + ("text_beginning","Začátek výrazu"), + ("text_exact","Přesný výraz"), + ] + actual_options = [("actual_results","Jen platné"), + ("complete_results","Platné i neplatné"),] + + entity_name_search = StringField(u'Název:') + entity_name_search_selection = SelectField('', choices=search_options) + entity_name_search_actual = SelectField('', choices=actual_options) + entity_number_search = StringField(u'Identifikační číslo:') + entity_number_search_selection = SelectField('', choices=search_options) + entity_number_search_actual = SelectField('', choices=actual_options) + + foreign_entity_number_search = StringField(u'Zahraniční registrační číslo:') + foreign_entity_number_search_selection = SelectField('', choices=search_options) + foreign_entity_number_search_actual = SelectField('', choices=actual_options) + class CompanyForm(Form): oddil = [('A', 'A'), ('B', 'B'), diff --git a/main.py b/main.py index c0325eb..27f7d98 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ from app import app from db_setup import init_db, db_session -from forms import JusticeSearchForm, CompanyForm, PersonSearchForm +from forms import JusticeSearchForm, CompanyForm, PersonSearchForm, EntitySearchForm from flask import flash, render_template, request, redirect from models import Company, Insolvency_Events, Konkurz_Events, Predmet_Podnikani, Predmety_Podnikani_Association, Predmet_Cinnosti, Predmety_Cinnosti_Association from models import Zakladni_Kapital, Akcie, Nazvy, Sidlo, Sidlo_Association, Pravni_Forma_Association_v2, Pravni_Formy, Statutarni_Organ_Association, Statutarni_Organy, Pocty_Clenu_Organu @@ -32,6 +32,16 @@ def search_person(): return render_template('search_form_person.html', form=search) +@app.route('/entity', methods=['GET', 'POST']) +def search_entity(): + search = EntitySearchForm(request.form) + print(search) + if request.method == 'POST': + return search_results_entity(search) + + return render_template('search_form_entity.html', form=search) + + @app.route('/results_person') def search_results_person(search): result = [] @@ -79,6 +89,47 @@ def search_results_person(search): table.border = True return render_template("results_persons.html", results=results, form=search, show_form = True, selection_method = actual_selection) +@app.route('/results_entity') +def search_results_entity(search): + entity_name = search.entity_name_search.data + entity_name_search_method = search.entity_name_search_selection.data + entity_name_actual_or_full = search.entity_name_search_actual.data + + entity_number = search.entity_number_search.data + entity_number_search_method = search.entity_number_search_selection.data + entity_number_actual_or_full = search.entity_name_search_actual.data + + qry = Pravnicka_Osoba.query + + if entity_number: + if entity_number_search_method == "text_anywhere": + qry = qry.filter(Pravnicka_Osoba.ico.contains(entity_number)) + elif entity_number_search_method == "text_beginning": + qry = qry.filter(Pravnicka_Osoba.ico.like(f'{entity_number}%')) + elif entity_number_search_method == "text_exact": + qry = qry.filter(Pravnicka_Osoba.ico == entity_number) + + if entity_name: + if entity_name_search_method == "text_anywhere": + qry = qry.filter(Pravnicka_Osoba.nazev.contains(entity_name)) + elif entity_name_search_method == "text_beginning": + qry = qry.filter(Pravnicka_Osoba.nazev.like(f'{entity_name}%')) + elif entity_name_search_method == "text_exact": + qry = qry.filter(Pravnicka_Osoba.nazev == entity_name) + + results = qry.all() + print(results) + + if not results: + flash('No results found!') + return redirect('/osoby') + + else: + table = Results(results) + table.border = True + return render_template("results_entities.html", results=results, form=search, show_form = True) + + @app.route('/results') def search_results(search): results = [] diff --git a/templates/header.html b/templates/header.html index 14b8bda..5b50d1a 100644 --- a/templates/header.html +++ b/templates/header.html @@ -13,7 +13,7 @@
+ +{% with messages = get_flashed_messages() %} + {% if messages %} +