Skip to content

Commit

Permalink
Bones: continue form data
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Jan 28, 2025
1 parent e9c8e03 commit cdacc56
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
12 changes: 4 additions & 8 deletions openatlas/database/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@ def delete_sex_types(entity_id: int) -> None:
{'id': entity_id})


def remove_bone_preservation_type(entity_id: int, bone_name: str) -> None:
def remove_bone_preservation_type(entity_id: int, type_ids: list[int]) -> None:
g.cursor.execute(
"""
DELETE FROM model.link WHERE id IN (
SELECT l.id
FROM model.entity e
JOIN model.link l ON
l.domain_id = %(entity_id)s AND
(l.range_id = e.id AND e.name = %(bone_name)s));
DELETE FROM model.link
WHERE domain_id = %(entity_id)s AND range_id IN %(type_ids)s;
""",
{'entity_id': entity_id, 'bone_name': bone_name})
{'entity_id': entity_id, 'type_ids': tuple(type_ids)})
14 changes: 13 additions & 1 deletion openatlas/models/bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@

from openatlas.database.tools import remove_bone_preservation_type
from openatlas.models.entity import Entity
from openatlas.models.type import Type


def create_bones(super_: Entity, name: str, category: dict[str, Any]):
add_bone(super_, name, category)


def get_bones(entity: Entity) -> dict[str, Any]:
inventory = bone_inventory
for sub in entity.get_linked_entities('P46'):
if sub.name in bone_inventory.keys():
if type_ := sub.get_linked_entity('P2'):
inventory[sub.name]['data'] = type_.name
return inventory


def add_bone(
super_: Entity,
name: str,
Expand All @@ -23,7 +33,9 @@ def add_bone(
bone = Entity.insert('bone', name)
bone.link('P46', super_, inverse=True)
else:
remove_bone_preservation_type(bone.id, name)
remove_bone_preservation_type(
bone.id,
Type.get_hierarchy('Bone preservation').subs)
if 'data' in category and category['data']:
bone.link('P2', Entity.get_by_id(int(category['data'])))
if 'subs' in category:
Expand Down
5 changes: 4 additions & 1 deletion openatlas/templates/tools/bones.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{% for name in data %}
{% for name, item in data.items() %}
<p>
{{ name }}
{% if 'contributor'|is_authorized %}
{{ _('edit')|button(url_for('bones_update', id_=entity.id, category=name|replace(' ', '_')))|safe }}
{% endif %}<br>
{% if item.data %}
{{ item.data }}
{% endif %}
</p>
{% endfor %}
11 changes: 3 additions & 8 deletions openatlas/views/bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from openatlas.display.util import required_group
from openatlas.display.util2 import is_authorized, manual
from openatlas.forms.field import SubmitField
from openatlas.models.bones import bone_inventory, create_bones
from openatlas.models.bones import bone_inventory, create_bones, get_bones
from openatlas.models.entity import Entity
from openatlas.models.type import Type
from openatlas.views.tools import tools_start_crumbs
Expand All @@ -26,6 +26,7 @@ def bones(id_: int) -> str:
buttons = [manual('tools/anthropological_analyses')]
if is_authorized('contributor'):
pass
inventory = get_bones(entity)
return render_template(
'tabs.html',
entity=entity,
Expand All @@ -35,7 +36,7 @@ def bones(id_: int) -> str:
render_template(
'tools/bones.html',
entity=entity,
data=bone_inventory),
data=inventory),
buttons=buttons)},
crumbs=tools_start_crumbs(entity) + [
[_('tools'), url_for('tools_index', id_=entity.id)],
Expand All @@ -62,8 +63,6 @@ def bones_update(id_: int, category: str) -> str | Response:
Transaction.rollback()
g.logger.log('error', 'database', 'transaction failed', e)
flash(_('error transaction'), 'error')
else:
add_data_to_structure(entity, structure)
return render_template(
'tabs.html',
entity=entity,
Expand All @@ -81,10 +80,6 @@ def bones_update(id_: int, category: str) -> str | Response:
_('edit')])


def add_data_to_structure(entity: Entity, structure_: dict[str, Any]) -> None:
pass


def add_form_data_to_structure(
form: FlaskForm,
structure_: dict[str, Any]) -> None:
Expand Down

0 comments on commit cdacc56

Please sign in to comment.