Remove unused functions for adding and syncing named entities in settings; streamline entity processing logic
This commit is contained in:
parent
9a1dffcf8d
commit
87fa623cde
1 changed files with 0 additions and 33 deletions
33
routes.py
33
routes.py
|
@ -398,39 +398,6 @@ def search():
|
|||
|
||||
@main.route('/settings', methods=['GET', 'POST'])
|
||||
def settings():
|
||||
def add_named_entities(items: list[str], model, attr: str, mapper: dict | None = None):
|
||||
for name in items:
|
||||
clean = name.strip()
|
||||
if clean:
|
||||
new_obj = model(**{attr: clean}) # type: ignore
|
||||
db.session.add(new_obj)
|
||||
if mapper is not None:
|
||||
db.session.flush()
|
||||
mapper[clean] = new_obj.id
|
||||
|
||||
def sync_named_entities(
|
||||
submitted_items: list,
|
||||
existing_items: set,
|
||||
model,
|
||||
attr: str,
|
||||
label: str
|
||||
):
|
||||
submitted_names = {
|
||||
str(item.get("name", "")).strip()
|
||||
for item in submitted_items
|
||||
if isinstance(item, dict) and str(item.get("name", "")).strip()
|
||||
}
|
||||
|
||||
print(f"🔍 {label} in DB: {existing_items}")
|
||||
print(f"🆕 {label} submitted: {submitted_names}")
|
||||
print(f"➖ {label} to delete: {existing_items - submitted_names}")
|
||||
|
||||
for name in submitted_names - existing_items:
|
||||
db.session.add(model(**{attr: name}))
|
||||
for name in existing_items - submitted_names:
|
||||
print(f"🗑️ Deleting {label}: {name}")
|
||||
db.session.execute(delete(model).where(getattr(model, attr) == name))
|
||||
|
||||
def process_entities(entity_list, model, attr, key_name="name"):
|
||||
"""Upserts and deletes based on entity name field."""
|
||||
existing = {getattr(e, attr): e.id for e in db.session.query(model).all()}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue