generated from dopt-python/py311
added functionality for consulting session saving, updating and soft deleting
This commit is contained in:
@@ -244,13 +244,16 @@ def page_consulting_to_db(
|
||||
with db.ENGINE.begin() as conn:
|
||||
if consultation_data.vorgang_id is None:
|
||||
# insert new "Vorgang"
|
||||
insert_data = consultation_data.model_dump(exclude={"vorgang_id", "beratungen"})
|
||||
insert_data_process = consultation_data.model_dump(
|
||||
exclude={"vorgang_id", "beratungen"}
|
||||
)
|
||||
logger.debug(
|
||||
"[Consulting Page] Call insert 'Vorgang' with data:\n%s", pformat(insert_data)
|
||||
"[Consulting Page] Call insert 'Vorgang' with data:\n%s",
|
||||
pformat(insert_data_process),
|
||||
)
|
||||
|
||||
stmt = db.beratung_vorgang.insert()
|
||||
ret = conn.execute(stmt, insert_data)
|
||||
ret = conn.execute(stmt, insert_data_process)
|
||||
if ret.rowcount == 0:
|
||||
raise IOError("Entry was not inserted correctly")
|
||||
prim_keys = ret.inserted_primary_key
|
||||
@@ -261,9 +264,14 @@ def page_consulting_to_db(
|
||||
|
||||
else:
|
||||
logger.debug(
|
||||
"[Consulting Page] VorgangID already set. ID: %d",
|
||||
"[Consulting Page] VorgangID already set. ID: %d. Update...",
|
||||
consultation_data.vorgang_id,
|
||||
)
|
||||
update_data_process = consultation_data.model_dump(exclude={"beratungen"})
|
||||
stmt = db.beratung_vorgang.update().where(
|
||||
db.beratung_vorgang.c.vorgang_id == consultation_data.vorgang_id
|
||||
)
|
||||
conn.execute(stmt, update_data_process)
|
||||
|
||||
rows_for_db_insert: list[dict[str, Any]] = []
|
||||
rows_for_db_update: list[dict[str, Any]] = []
|
||||
@@ -337,12 +345,24 @@ def page_consulting_from_db(
|
||||
beratungs_typ=consultation_data_db["beratungs_typ"],
|
||||
erstellt=consultation_data_db["erstellt"],
|
||||
aktualisiert=consultation_data_db["aktualisiert"],
|
||||
geloescht=consultation_data_db["geloescht"],
|
||||
beratungen=[],
|
||||
)
|
||||
|
||||
# get all consultation sessions of this process
|
||||
if consultation_data.geloescht is not None:
|
||||
logger.info(
|
||||
(
|
||||
"[Consulting Page] Obtained entry for ID=%d. This entry was marked "
|
||||
"as deleted."
|
||||
),
|
||||
cons_id,
|
||||
)
|
||||
|
||||
# get all consultation sessions of this process, only the ones
|
||||
# which are not marked as deleted
|
||||
stmt = db.beratung_einzelberatung.select().where(
|
||||
db.beratung_einzelberatung.c.vorgang_id == cons_id
|
||||
db.beratung_einzelberatung.c.vorgang_id == cons_id,
|
||||
db.beratung_einzelberatung.c.geloescht.is_(None),
|
||||
)
|
||||
ret = conn.execute(stmt)
|
||||
# empty results possible
|
||||
|
||||
Reference in New Issue
Block a user