From d76ce8e91389e50cd4628ae69bcb5731bb26fd86 Mon Sep 17 00:00:00 2001 From: jgenero Date: Tue, 18 Oct 2022 14:05:03 +0200 Subject: [PATCH] + table intervention_type --- app/cmd/db.py | 28 +++++++++++++++++----------- app/data_actes/__init__.py | 3 ++- app/data_actes/intervention_data.py | 5 +++++ app/modeles/__init__.py | 4 ++-- app/modeles/data.py | 8 ++++++++ app/routes.py | 2 +- 6 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 app/data_actes/intervention_data.py diff --git a/app/cmd/db.py b/app/cmd/db.py index addd171..72335c2 100644 --- a/app/cmd/db.py +++ b/app/cmd/db.py @@ -9,8 +9,8 @@ from lxml import etree from tqdm import tqdm from app.app import APPPATH, db -from app.data_actes import diplomatic_type, institution, state, houses -from app.modeles import Institution, State, House, Production_place, Diplo_type, Document, Acte, Individual, Produced_by, Signed_by +from app.data_actes import diplomatic_type, institution, state, houses, interventions +from app.modeles import Institution, State, House, Intervention_type, Production_place, Diplo_type, Document, Acte, Individual, Produced_by db_cli = AppGroup("db") @@ -50,6 +50,11 @@ def _create_house(data_lst: list)-> None: for data in tqdm(data_lst, desc="Populating House..."): House.create(**data) +def _create_interv_type(data_lst: list)-> None: + """create state table""" + for data in tqdm(data_lst, desc="Populating Intervention_type..."): + Intervention_type.create(**data) + def _create_diplo_type(data_lst: list)-> None: """create diplo type table""" for data in tqdm(data_lst, desc="Populating Diplo_type..."): @@ -171,6 +176,7 @@ def _create_produced_by(xml_file: str, folder: str): for acte in os.listdir(folder): acte_q = [t.id_acte for t in Acte.select().where( Acte.numb_acte == acte.replace(".xml", ""))] + # print("----") # print(acte, "==", acte_q[0]) soup = make_soup(os.path.join(folder, acte)) princes = soup.sourceDesc.find_all("listPerson", {"type": "prince"}) @@ -205,10 +211,10 @@ def _create_signed_by(xml_file: str, folder: str): sign_q = [t.id_indiv for t in Individual.select().where( Individual.name_indiv == signator)] # print(signator, "==", sign_q) - sign_actes.append({"produced_by_acte": acte_q[0], - "produced_by_prince": sign_q[0]}) + sign_actes.append({"signed_by_acte": acte_q[0], + "signed_by_prince": sign_q[0]}) for data in tqdm(sign_actes, desc="Populating Signed_by..."): - Produced_by.create(**data) + Signed_by.create(**data) @db_cli.command() @@ -220,15 +226,16 @@ def init() -> None: "Bourbon", "Brb_5_Charles_Ier") print("Dropping existing DB...") - db.drop_tables([Institution, State, House, Production_place, - Diplo_type, Document, Acte, Individual, - Produced_by, Signed_by]) + db.drop_tables([Institution, State, House, Intervention_type, + Production_place, Diplo_type, Document, Acte, Individual, + Produced_by]) print("Re-creating schema...") - db.create_tables([Institution, State, House, Production_place, - Diplo_type, Document, Acte, Individual, Produced_by, Signed_by]) + db.create_tables([Institution, State, House, Intervention_type, + Production_place, Diplo_type, Document, Acte, Individual, Produced_by]) _create_institution(institution) _create_state(state) _create_house(houses) + _create_interv_type(interventions) _create_diplo_type(diplomatic_type) _create_produc_place(xml, xml_folder) _create_doc(xml, xml_folder) @@ -241,4 +248,3 @@ def init() -> None: print("!! name " + name + " not found in /app/static/csv/actors.csv") _create_indiv(actors) _create_produced_by(xml, xml_folder) - _create_signed_by(xml, xml_folder) diff --git a/app/data_actes/__init__.py b/app/data_actes/__init__.py index 090f40b..7a385ac 100644 --- a/app/data_actes/__init__.py +++ b/app/data_actes/__init__.py @@ -2,5 +2,6 @@ from .diplo_type_data import diplomatic_type from .institution_data import institution from .state_data import state from .house_data import houses +from .intervention_data import interventions -__all__ = ["diplomatic_type", "institution", "state", "houses"] +__all__ = ["diplomatic_type", "institution", "state", "houses", "interventions"] diff --git a/app/data_actes/intervention_data.py b/app/data_actes/intervention_data.py new file mode 100644 index 0000000..2d5dfc1 --- /dev/null +++ b/app/data_actes/intervention_data.py @@ -0,0 +1,5 @@ +interventions = [ + {"interv_label": "producer"}, + {"interv_label": "signatory"}, + {"interv_label": "witness"}, +] \ No newline at end of file diff --git a/app/modeles/__init__.py b/app/modeles/__init__.py index 7cf26e9..5891a1c 100644 --- a/app/modeles/__init__.py +++ b/app/modeles/__init__.py @@ -1,3 +1,3 @@ -from .data import Institution, State, House, Production_place, Diplo_type, Document, Acte, Individual, Produced_by, Signed_by +from .data import Institution, State, House, Intervention_type, Production_place, Diplo_type, Document, Acte, Individual, Produced_by -__all__ = ["Institution", "State", "House", "Production_place", "Diplo_type", "Document", "Acte", "Individual", "Produced_by", "Signed_by"] +__all__ = ["Institution", "State", "House", "Intervention_type", "Production_place", "Diplo_type", "Document", "Acte", "Individual", "Produced_by"] diff --git a/app/modeles/data.py b/app/modeles/data.py index 3137fae..e513d8d 100644 --- a/app/modeles/data.py +++ b/app/modeles/data.py @@ -54,6 +54,14 @@ class House(BaseModel): database = db db_table = 'House' +class Intervention_type(BaseModel): + id_house = peewee.AutoField() + interv_label = peewee.TextField() + + class Meta: + database = db + db_table = 'Intervention_type' + class Production_place(BaseModel): id_place = peewee.AutoField() placename = peewee.TextField() diff --git a/app/routes.py b/app/routes.py index 5950ec2..c993a20 100644 --- a/app/routes.py +++ b/app/routes.py @@ -7,7 +7,7 @@ from flask import Blueprint, abort, render_template, request, send_from_director from playhouse.flask_utils import PaginatedQuery from .app import APPPATH -from .modeles import Institution, State, House, Production_place, Diplo_type, Document, Acte, Individual, Produced_by +from .modeles import Institution, State, House, Intervention_type, Production_place, Diplo_type, Document, Acte, Individual, Produced_by RESULT_PAR_PAGES = 5