Skip to content

Commit

Permalink
Bones: add bone entities (if not existing)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Jan 24, 2025
1 parent 8f3bd1a commit 797b208
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
29 changes: 28 additions & 1 deletion openatlas/models/bones.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
from __future__ import annotations

from typing import Any

from openatlas.models.entity import Entity


def create_bones(entity: Entity, category: str):
def create_bones(super_: Entity, name: str, category: dict[str, Any]):
bones_exist = False
for sub in super_.get_linked_entities('P46'):
if sub.name == name:
bones_exist = True
break
if not bones_exist:
add_bone(super_, name, category)
add_values()
else:
update_values()


def add_bone(super_: Entity, name: str, category: dict[str, Any]):
entity = Entity.insert('bone', name)
entity.link('P46', super_, inverse=True)
if 'subs' in category:
for name, sub in category['subs'].items():
add_bone(entity, name, sub)


def add_values():
pass


def update_values():
pass


Expand Down
10 changes: 9 additions & 1 deletion openatlas/views/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,15 @@ def bones_update(id_: int, category: str) -> str | Response:
if current_bones['preservation']:
current_bones['data'] = getattr(form, category).data
bones_add_form_data_to_structure(form, current_bones)
create_bones(entity, current_bones)
try:
Transaction.begin()
create_bones(entity, category.replace('_', ' '), current_bones)
Transaction.commit()
except Exception as e: # pragma: no cover
Transaction.rollback()
g.logger.log('error', 'database', 'transaction failed', e)
flash(_('error transaction'), 'error')

return render_template(
'tabs.html',
entity=entity,
Expand Down

0 comments on commit 797b208

Please sign in to comment.