diff options
author | SveterCZE <petr.smerkl@live.com> | 2021-02-09 23:45:56 +0100 |
---|---|---|
committer | SveterCZE <petr.smerkl@live.com> | 2021-02-09 23:45:56 +0100 |
commit | 83b0b2e72d775279ba8ac8bc218ba76128fca1c9 (patch) | |
tree | 26a8c113278d0f82fe0b567c46cd92ec30754659 | |
parent | 704e9119803350aa1b666231289faab0deab0f64 (diff) | |
download | justice-83b0b2e72d775279ba8ac8bc218ba76128fca1c9.tar.gz |
Updating the search ffunctions, adding "predmet c"
-rw-r--r-- | main.py | 2 | ||||
-rw-r--r-- | models.py | 91 | ||||
-rw-r--r-- | templates/extract.html | 72 |
3 files changed, 130 insertions, 35 deletions
@@ -4,7 +4,7 @@ from db_setup import init_db, db_session from forms import JusticeSearchForm, CompanyForm from flask import flash, render_template, request, redirect # from models import Company, Soud -from models import Company, Obce, Ulice, Pravni_Forma, Insolvency_Events, Predmet_Podnikani, Predmety_Podnikani_Association +from models import Company, Obce, Ulice, Pravni_Forma, Insolvency_Events, Predmet_Podnikani, Predmety_Podnikani_Association, Predmet_Cinnosti, Predmety_Cinnosti_Association from tables import Results init_db() @@ -8,15 +8,62 @@ Created on Sun Jan 17 09:56:14 2021 from app import db from sqlalchemy.orm import relationship, backref +import sqlalchemy.types as types + + +def convert_date_to_string(converted_date): + if converted_date == 0: + return converted_date + else: + separated_string = converted_date.split("-") + converted_string = "".join([separated_string[2], ". ", convert_month_to_string(separated_string[1]), " ", separated_string[0]]) + return converted_string + +def convert_month_to_string(my_month): + if my_month == "01": + return "ledna" + elif my_month == "02": + return "února" + elif my_month == "03": + return "března" + elif my_month == "04": + return "dubna" + elif my_month == "05": + return "května" + elif my_month == "06": + return "června" + elif my_month == "07": + return "července" + elif my_month == "08": + return "srpna" + elif my_month == "09": + return "září" + elif my_month == "10": + return "října" + elif my_month == "11": + return "listopadu" + elif my_month == "12": + return "prosince" + else: + return "podivného měsíce" + +class MyType(types.TypeDecorator): + '''Prefixes Unicode values with "PREFIX:" on the way in and + strips it off on the way out. + ''' + + impl = types.Unicode + + def process_bind_param(self, value, dialect): + return convert_date_to_string(value) + + def process_result_value(self, value, dialect): + # return "PREFIX:" + value + return convert_date_to_string(value) + + def copy(self, **kw): + return MyType(self.impl.length) -# class Soud(db.Model): -# __tablename__ = "soudy" -# id = db.Column(db.Integer, primary_key=True) -# name = db.Column(db.String) - -# def __repr__(self): -# # return "<soud: {}="">".format(self.name) -# return self.name association_table = db.Table("obce_relation", db.Column("company_id", db.Integer, db.ForeignKey("companies.id"), primary_key=True, nullable=False), @@ -47,9 +94,19 @@ class Predmety_Podnikani_Association(db.Model): __tablename__ = 'predmety_podnikani_relation' company_id = db.Column(db.Integer, db.ForeignKey('companies.id'), nullable=False) predmet_podnikani_id = db.Column(db.Integer, db.ForeignKey('predmety_podnikani.id'), nullable=False, primary_key=True) - zapis_datum = db.Column(db.String) - child = db.relationship("Predmet_Podnikani", back_populates="company_predmet_podnikani") - parent = db.relationship("Company", back_populates="predmet_podnikani") + zapis_datum = db.Column(MyType) + vymaz_datum = db.Column(MyType) + predmet_podnikani = db.relationship("Predmet_Podnikani", back_populates="company_predmet_podnikani") + company = db.relationship("Company", back_populates="predmet_podnikani") + +class Predmety_Cinnosti_Association(db.Model): + __tablename__ = 'predmety_cinnosti_relation' + company_id = db.Column(db.Integer, db.ForeignKey('companies.id'), nullable=False) + predmet_cinnosti_id = db.Column(db.Integer, db.ForeignKey('predmety_cinnosti.id'), nullable=False, primary_key=True) + zapis_datum = db.Column(MyType) + vymaz_datum = db.Column(MyType) + predmet_cinnosti = db.relationship("Predmet_Cinnosti", back_populates="company_predmet_cinnosti") + company = db.relationship("Company", back_populates="predmet_cinnosti") class Company(db.Model): @@ -66,7 +123,8 @@ class Company(db.Model): ulice = db.relationship("Ulice", secondary=ulice_association, backref="companies") pravni_forma = db.relationship("Pravni_Forma", secondary=pravni_forma_association, backref="companies") insolvence = db.relationship("Insolvency_Events", backref="companies") - predmet_podnikani = db.relationship("Predmety_Podnikani_Association", back_populates="parent", lazy="joined") + predmet_podnikani = db.relationship("Predmety_Podnikani_Association", back_populates="company", lazy="joined") + predmet_cinnosti = db.relationship("Predmety_Cinnosti_Association", back_populates="company", lazy="joined") class Obce(db.Model): @@ -94,9 +152,14 @@ class Insolvency_Events(db.Model): company = relationship("Company", backref="insolvency_events") insolvency_event = db.Column(db.String) - class Predmet_Podnikani(db.Model): __tablename__ = "predmety_podnikani" id = db.Column(db.Integer, primary_key=True) predmet_podnikani = db.Column(db.String) - company_predmet_podnikani = db.relationship("Predmety_Podnikani_Association", back_populates="child", lazy="joined") + company_predmet_podnikani = db.relationship("Predmety_Podnikani_Association", back_populates="predmet_podnikani", lazy="joined") + +class Predmet_Cinnosti(db.Model): + __tablename__ = "predmety_cinnosti" + id = db.Column(db.Integer, primary_key=True) + predmet_cinnosti = db.Column(db.String) + company_predmet_cinnosti = db.relationship("Predmety_Cinnosti_Association", back_populates="predmet_cinnosti", lazy="joined") diff --git a/templates/extract.html b/templates/extract.html index eed67ba..63c362c 100644 --- a/templates/extract.html +++ b/templates/extract.html @@ -74,12 +74,13 @@ {% set ico_buffer = "" %} {% endif %} +{% set undedrline_open_deleted = "<u>" %} +{% set undedrline_closed_deleted = "</u>" %} + <h1>Výpis z obchodního rejstříku</h1> <h2>{{ row.nazev }}, {{ row.oddil }} {{ row.vlozka }} vedená u {{ soud }}</h2> <p><a href="/">Zpět na vyhledání.</a></p> -{{ row.predmet_podnikani }} - <table class= "table" style="width: 100%"> <tr> <td style="width:15%">Datum vzniku a zápisu:</td> @@ -111,34 +112,65 @@ <td>{{ row.pravni_forma[0].pravni_forma }}</td> <td></td> </tr> - - <tr> - <td>Předmět podnikání - test:</td> - <td>{{ row.predmet_podnikani[0].child.predmet_podnikani }}</td> - <td>Zapsáno: {{ row.predmet_podnikani[0].zapis_datum }} <br> Vymazáno: {{ row.predmet_podnikani[0].vymaz_datum }} </td> - <td></td> - </tr> - {% if row.predmet_podnikani|length == 1 %} + {% if row.predmet_podnikani|length > 0 %} <tr> <td>Předmět podnikání:</td> - <td>{{ row.predmet_podnikani }}</td> - <td>Zapsáno: {{ row.predmet_podnikani[0] }} <br> Vymazáno: {{ row.predmet_podnikani[0].vymaz_datum }} </td> + {% if row.predmet_podnikani[0].vymaz_datum != 0 %} + {% set underlne_style_open = undedrline_open_deleted %} + {% set underlne_style_close = undedrline_closed_deleted %} + {% else %} + {% set underlne_style_open = "" %} + {% set underlne_style_close = "" %} + {% endif %} + <td>{{ underlne_style_open|safe }} {{ row.predmet_podnikani[0].predmet_podnikani.predmet_podnikani }} {{ underlne_style_close|safe }}</td> + <td>{{ underlne_style_open|safe }} Zapsáno: {{ row.predmet_podnikani[0].zapis_datum }} {% if row.predmet_podnikani[0].vymaz_datum != 0 %} <br> Vymazáno: {{ row.predmet_podnikani[0].vymaz_datum }} {% endif %} {{ underlne_style_close|safe }}</td> </tr> - {% elif row.predmet_podnikani|length > 1 %} + {% for i in range (1, row.predmet_podnikani|length) %} <tr> - <td>Předmět podnikání:</td> - <td>{{ row.predmet_podnikani }}</td> - <td>Zapsáno: {{ row.predmet_podnikani[0].zapis_datum }} <br> Vymazáno: {{ row.predmet_podnikani[0].vymaz_datum }} </td> + <td></td> + {% if row.predmet_podnikani[i].vymaz_datum != 0 %} + {% set underlne_style_open = undedrline_open_deleted %} + {% set underlne_style_close = undedrline_closed_deleted %} + {% else %} + {% set underlne_style_open = "" %} + {% set underlne_style_close = "" %} + {% endif %} + <td>{{ underlne_style_open|safe }} {{ row.predmet_podnikani[i].predmet_podnikani.predmet_podnikani }} {{ underlne_style_close|safe }}</td> + <td>{{ underlne_style_open|safe }} Zapsáno: {{ row.predmet_podnikani[i].zapis_datum }} {% if row.predmet_podnikani[i].vymaz_datum != 0 %} <br> Vymazáno: {{ row.predmet_podnikani[i].vymaz_datum }} {% endif %} {{ underlne_style_close|safe }}</td> + </tr> + {% endfor %} + {% endif %} + + {% if row.predmet_cinnosti|length > 0 %} + <tr> + <td>Předmět činnosti:</td> + {% if row.predmet_cinnosti[0].vymaz_datum != 0 %} + {% set underlne_style_open = undedrline_open_deleted %} + {% set underlne_style_close = undedrline_closed_deleted %} + {% else %} + {% set underlne_style_open = "" %} + {% set underlne_style_close = "" %} + {% endif %} + <td>{{ underlne_style_open|safe }} {{ row.predmet_cinnosti[0].predmet_cinnosti.predmet_cinnosti }} {{ underlne_style_close|safe }}</td> + <td>{{ underlne_style_open|safe }} Zapsáno: {{ row.predmet_cinnosti[0].zapis_datum }} {% if row.predmet_cinnosti[0].vymaz_datum != 0 %} <br> Vymazáno: {{ row.predmet_cinnosti[0].vymaz_datum }} {% endif %} {{ underlne_style_close|safe }}</td> </tr> - {% for i in range (1, row.predmet_podnikani|length) %} + {% for i in range (1, row.predmet_cinnosti|length) %} <tr> <td></td> - <td>{{ row.predmet_podnikani[i].predmet_podnikani }}</td> - <td>Zapsáno: {{ row.predmet_podnikani[i].zapis_datum.company_id }} <br> Vymazáno: {{ row.predmet_podnikani[i].vymaz_datum }} </td> - </tr> + {% if row.predmet_cinnosti[i].vymaz_datum != 0 %} + {% set underlne_style_open = undedrline_open_deleted %} + {% set underlne_style_close = undedrline_closed_deleted %} + {% else %} + {% set underlne_style_open = "" %} + {% set underlne_style_close = "" %} + {% endif %} + <td>{{ underlne_style_open|safe }} {{ row.predmet_cinnosti[i].predmet_cinnosti.predmet_cinnosti }} {{ underlne_style_close|safe }}</td> + <td>{{ underlne_style_open|safe }} Zapsáno: {{ row.predmet_cinnosti[i].zapis_datum }} {% if row.predmet_cinnosti[i].vymaz_datum != 0 %} <br> Vymazáno: {{ row.predmet_cinnosti[i].vymaz_datum }} {% endif %} {{ underlne_style_close|safe }}</td> + </tr> {% endfor %} {% endif %} + {% if insolvency_notes|length > 0 %} <tr> |