From 3ffebe7318838781d02a2231de0dd16f404940cf Mon Sep 17 00:00:00 2001 From: SveterCZE Date: Mon, 8 Feb 2021 23:58:26 +0100 Subject: minor tweaks - does not work so far --- justice_main.py | 6 +++--- main.py | 3 ++- models.py | 37 +++++++++++++++++++++++-------------- templates/extract.html | 41 ++++++++++++++++++++++++++++++++++++++++- templates/results2.html | 1 + 5 files changed, 69 insertions(+), 19 deletions(-) diff --git a/justice_main.py b/justice_main.py index 9c09f62..ae38927 100644 --- a/justice_main.py +++ b/justice_main.py @@ -10,7 +10,7 @@ from datetime import datetime # The function opens a file and parses the extracted data into the database def parse_to_DB(file): print("Processing ", str(file)) - conn = sqlite3.connect('justice-testing.db') + conn = sqlite3.connect('justice.db') c = conn.cursor() for event, element in etree.iterparse(file, tag="Subjekt"): # Bugfix for companies which have been deleted but appear in the list of existing companies @@ -573,7 +573,7 @@ def delete_archive(file): send2trash.send2trash(file) -parse_to_DB("as-actual-ostrava-2021.xml") +# parse_to_DB("as-actual-ostrava-2021.xml") # parse_to_DB("ks-actual-ostrava-2021.xml") @@ -583,6 +583,6 @@ def do_both(): general_update("down") general_update("db_update") -# do_both() +do_both() # cProfile.run('do_both()') diff --git a/main.py b/main.py index c743eb6..eeb1cc9 100644 --- a/main.py +++ b/main.py @@ -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 +from models import Company, Obce, Ulice, Pravni_Forma, Insolvency_Events, Predmet_Podnikani, Predmety_Podnikani_Association from tables import Results init_db() @@ -97,6 +97,7 @@ def search_results(search): qry = qry.filter(Company.zapis >= zapsano_od) if zapsano_do: qry = qry.filter(Company.zapis <= zapsano_do) + results = qry.all() # else: # qry = db_session.query(Company) diff --git a/models.py b/models.py index b90d01f..9ef9d5d 100644 --- a/models.py +++ b/models.py @@ -35,8 +35,24 @@ pravni_forma_association=db.Table("pravni_formy_relation", db.Column("pravni_forma_id", db.Integer, db.ForeignKey("pravni_formy.id"), nullable=False), ) -class Company(db.Model): +# predmety_podnikani_association = db.Table("predmety_podnikani_relation", +# db.Column("company_id", db.Integer, db.ForeignKey("companies.id"), primary_key=True, nullable=False), +# db.Column("predmet_podnikani_id", db.Integer, db.ForeignKey("predmety_podnikani.id"), nullable=False), +# db.Column("zapis_datum", db.String), +# db.Column("vymaz_datum", db.String), +# ) + + +class Predmety_Podnikani_Association(db.Model): + __tablename__ = 'predmety_podnikani_relation' + company_id = db.Column(db.Integer, db.ForeignKey('companies.id'), primary_key=True, nullable=False) + predmet_podnikani_id = db.Column(db.Integer, db.ForeignKey('predmety_podnikani.id'), nullable=False) + zapis_datum = db.Column(db.String) + child = db.relationship("Predmet_Podnikani", back_populates="company_predmet_podnikani", lazy="joined") + parent = db.relationship("Company", back_populates="predmet_podnikani", lazy="joined") + +class Company(db.Model): __tablename__ = "companies" id = db.Column(db.Integer, primary_key=True) ico = db.Column(db.String) @@ -50,6 +66,7 @@ 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") class Obce(db.Model): @@ -78,16 +95,8 @@ class Insolvency_Events(db.Model): insolvency_event = db.Column(db.String) -# class Association(db.Model): -# __tablename__ = "obce_relation" -# company_id = db.Column(db.Integer, db.ForeignKey('companies.id'), primary_key=True) -# obec_id = db.Column(db.Integer, db.ForeignKey('obce.id')) - -# company = relationship("Company", back_populates = "Obce") -# obec = relationship("Obce", back_populates = "Company") - - - - - -# \ No newline at end of file +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") diff --git a/templates/extract.html b/templates/extract.html index b4f75fb..eed67ba 100644 --- a/templates/extract.html +++ b/templates/extract.html @@ -78,40 +78,79 @@

{{ row.nazev }}, {{ row.oddil }} {{ row.vlozka }} vedená u {{ soud }}

Zpět na vyhledání.

+{{ row.predmet_podnikani }} + - + + + + + + + + + + + + + + + + + {% if row.predmet_podnikani|length == 1 %} + + + + + {% elif row.predmet_podnikani|length > 1 %} + + + + + + {% for i in range (1, row.predmet_podnikani|length) %} + + + + + + {% endfor %} + {% endif %} + {% if insolvency_notes|length > 0 %} + {% for i in range (1, insolvency_notes|length) %} + {% endfor %} {% endif %} diff --git a/templates/results2.html b/templates/results2.html index e0c62b6..9bed615 100644 --- a/templates/results2.html +++ b/templates/results2.html @@ -100,6 +100,7 @@ + {% if insolvency_notes|length > 0 %} {% for i in range (insolvency_notes|length) %} -- cgit
Datum vzniku a zápisu:{{den}}. {{mesic}} {{zapis_split[0]}}{{den}}. {{mesic}} {{zapis_split[0]}}
Spisová značka: {{ row.oddil }} {{ row.vlozka }} vedená u {{ soud }}
Obchodní firma: {{ row.nazev }}
Sídlo: {{ row.sidlo }}
Identifikační číslo: {{ ico_buffer|join("") }}{{ row.ico }}
Právní forma: {{ row.pravni_forma[0].pravni_forma }}
Předmět podnikání - test:{{ row.predmet_podnikani[0].child.predmet_podnikani }}Zapsáno: {{ row.predmet_podnikani[0].zapis_datum }}
Vymazáno: {{ row.predmet_podnikani[0].vymaz_datum }}
Předmět podnikání:{{ row.predmet_podnikani }}Zapsáno: {{ row.predmet_podnikani[0] }}
Vymazáno: {{ row.predmet_podnikani[0].vymaz_datum }}
Předmět podnikání:{{ row.predmet_podnikani }}Zapsáno: {{ row.predmet_podnikani[0].zapis_datum }}
Vymazáno: {{ row.predmet_podnikani[0].vymaz_datum }}
{{ row.predmet_podnikani[i].predmet_podnikani }}Zapsáno: {{ row.predmet_podnikani[i].zapis_datum.company_id }}
Vymazáno: {{ row.predmet_podnikani[i].vymaz_datum }}
Údaje o insolvencích: {{ insolvency_notes[0] }}
{{ insolvency_notes[i] }}
Úplný výpis