Skip to content

Commit

Permalink
Bones: additional categories, number fields
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Jan 21, 2025
1 parent 04187bf commit 2247dc9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 55 deletions.
108 changes: 60 additions & 48 deletions openatlas/models/bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
'preservation': None,
'subs': {
'Arm R': {
'preservation': None,
'preservation': 'percent',
'subs': {
'Humerus R': {
'preservation': 'percent',
Expand Down Expand Up @@ -276,7 +276,7 @@
'Scaphoid lat. R': {'preservation': 'percent'},
'Lunate mes. R': {'preservation': 'percent'}}}}},
'Arm L': {
'preservation': None,
'preservation': 'percent',
'subs': {
'Humerus L': {
'preservation': 'percent',
Expand Down Expand Up @@ -334,56 +334,68 @@
{'preservation': 'percent'},
'Scaphoid lat. L': {'preservation': 'percent'},
'Lunate mes. L': {'preservation': 'percent'}}}}},
'Hand R': {
'preservation': 'percent',
'subs': {
'Carpals R': {
'preservation': None,
'subs': {
'Scaphoid R': {'preservation': 'percent'},
'Lunate R': {'preservation': 'percent'},
'Triquetrum R': {'preservation': 'percent'},
'Capitulum R': {'preservation': 'percent'},
'Hamatum R': {'preservation': 'percent'},
'Trapezoideum R': {'preservation': 'percent'},
'Trapezium R': {'preservation': 'percent'},
'Pisiforme R': {'preservation': 'percent'}}},
'Metacarpals R': {
'preservation': None,
'subs': {
'Metacarpal 1 R': {'preservation': 'percent'},
'Metacarpal 2 R': {'preservation': 'percent'},
'Metacarpal 3 R': {'preservation': 'percent'},
'Metacarpal 4 R': {'preservation': 'percent'},
'Metacarpal 5 R': {'preservation': 'percent'}}},
'Phalanges R': {
'preservation': 'percent',
'subs': {
'Proximal phalanges R': {'preservation': 'number'},
'Medial phalanges R': {'preservation': 'number'},
'Distal phalanges R': {'preservation': 'number'},
'Sesamoid R': {'preservation': 'number'}}}}},
'Hand L': {
'preservation': 'percent',
'subs': {
'Carpals L': {
'preservation': None,
'subs': {
'Scaphoid L': {'preservation': 'percent'},
'Lunate L': {'preservation': 'percent'},
'Triquetrum L': {'preservation': 'percent'},
'Capitulum L': {'preservation': 'percent'},
'Hamatum L': {'preservation': 'percent'},
'Trapezoideum L': {'preservation': 'percent'},
'Trapezium L': {'preservation': 'percent'},
'Pisiforme L': {'preservation': 'percent'}}},
'Metacarpals R': {
'preservation': None,
'subs': {
'Metacarpal 1 L': {'preservation': 'percent'},
'Metacarpal 2 L': {'preservation': 'percent'},
'Metacarpal 3 L': {'preservation': 'percent'},
'Metacarpal 4 L': {'preservation': 'percent'},
'Metacarpal 5 L': {'preservation': 'percent'}}},
'Phalanges R': {
'preservation': 'percent',
'subs': {
'Proximal phalanges L': {'preservation': 'number'},
'Medial phalanges L': {'preservation': 'number'},
'Distal phalanges L': {'preservation': 'number'},
'Sesamoid L': {'preservation': 'number'}}}}},

}}}

"""
Inventory: Arms and hands
Hand R
Carpals R
Scaphoid R
Lunate R
Triquetrum R
Capitulum R
Hamatum R
Trapezoideum R
Trapezium R
Pisiforme R
Metacarpals R
Metacarpal 1 R
Metacarpal 2 R
Metacarpal 3 R
Metacarpal 4 R
Metacarpal 5 R
Phalanges R
Proximal phalanges R (no)
Medial phalanges R (no)
Distal phalanges R (no)
Sesamoid R (no)
Hand L
Carpals L
Scaphoid L
Lunate L
Triquetrum L
Capitulum L
Hamatum L
Trapezoideum L
Trapezium L
Pisiforme L
Metacarpals L
Metacarpal 1 L
Metacarpal 2 L
Metacarpal 3 L
Metacarpal 4 L
Metacarpal 5 L
Phalanges L
Proximal phalanges L (no)
Medial phalanges L (no)
Distal phalanges L (no)
Sesamoid L (no)
Axial skeleton
Sternum
Expand Down
2 changes: 1 addition & 1 deletion openatlas/templates/tools/bones.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% for name in data %}
<p>
{{ name }}
{% 'contributor'|is_authorized %}
{% if 'contributor'|is_authorized %}
{{ _('edit')|button(url_for('bones_update', id_=entity.id, category=name|replace(' ', '_')))|safe }}
{% endif %}
</p>
Expand Down
16 changes: 10 additions & 6 deletions openatlas/views/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,11 @@ def bones_update(id_: int, category) -> str | Response:
'info': Tab(
'bones',
content=
Markup('<form method="post">{form.csrf_token}') +
bone_row(form, category, structure[category]) +
Markup(f'<form method="post">{form.csrf_token}') +
bone_row(
form,
category,
structure[category.replace('_', ' ')]) +
Markup('</form>'),
buttons=[manual('tools/anthropological_analyses')])},
crumbs=tools_start_crumbs(entity) + [
Expand All @@ -321,7 +324,7 @@ def bones_form(entity: Entity, category: str) -> Any:
class Form(FlaskForm):
pass

inventory = structure[category.replace('-', ' ')]
inventory = structure[category.replace('_', ' ')]
options = {
g.types[id_].name: id_ for id_
in Type.get_hierarchy('Bone preservation').subs}
Expand Down Expand Up @@ -350,21 +353,22 @@ def bone_fields_recursive(form, label, item, choices):
form,
label.replace(' ', '-'),
SelectField(label, choices=choices))
elif item['preservation'] == 'number':
setattr(form, label.replace(' ', '-'), IntegerField())
if 'subs' in item:
for label, sub in item['subs'].items():
bone_fields_recursive(form, label, sub, choices)



def bone_row(
form: Any,
label: str,
item: dict[str, Any],
offset: float = 0):
html = Markup(
f'<div style="margin:0.5em;margin-left:{0.5 + offset * 2}em">'
f'<span style="margin-right:2em;">{label}</span>')
if item['preservation'] == 'percent':
f'<span style="margin-right:2em;">{label.replace("_", " ")}</span>')
if item['preservation']:
html += str(getattr(form, label.replace(' ', '-')))
html += Markup('</div>')
if 'subs' in item:
Expand Down

0 comments on commit 2247dc9

Please sign in to comment.