Skip to content

Commit

Permalink
Bones: layout and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Jan 21, 2025
1 parent 50f3ef7 commit 04187bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
4 changes: 3 additions & 1 deletion openatlas/templates/tools/bones.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% for name in data %}
<p>
{{ name }}
<a href="{{ url_for('bones_update', id_=entity.id, category=name|replace(' ', '_')) }}">{{ _('edit') }}</a>
{% 'contributor'|is_authorized %}
{{ _('edit')|button(url_for('bones_update', id_=entity.id, category=name|replace(' ', '_')))|safe }}
{% endif %}
</p>
{% endfor %}
34 changes: 13 additions & 21 deletions openatlas/views/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,28 +296,28 @@ def bones(id_: int) -> str | Response:


@app.route('/tools/bones_update/<int:id_>/<category>')
@required_group('readonly')
@required_group('contributor')
def bones_update(id_: int, category) -> str | Response:
entity = Entity.get_by_id(id_, types=True)
buttons = [manual('tools/anthropological_analyses')]
form = get_bones_form(entity, category)
if is_authorized('contributor'):
pass
form = bones_form(entity, category)
return render_template(
'tabs.html',
entity=entity,
tabs={
'info': Tab(
'bones',
content=display_bone_form(form, category),
buttons=buttons)},
content=
Markup('<form method="post">{form.csrf_token}') +
bone_row(form, category, structure[category]) +
Markup('</form>'),
buttons=[manual('tools/anthropological_analyses')])},
crumbs=tools_start_crumbs(entity) + [
[_('tools'), url_for('tools_index', id_=entity.id)],
[_('bone inventory'), url_for('bones', id_=entity.id)],
_('edit')])


def get_bones_form(entity: Entity, category: str) -> Any:
def bones_form(entity: Entity, category: str) -> Any:
class Form(FlaskForm):
pass

Expand All @@ -339,32 +339,24 @@ class Form(FlaskForm):
category.replace(' ', '-'),
SelectField(category, choices=choices))
for label, sub in inventory['subs'].items():
add_bone_fields_recursive(Form, label, sub, choices)
bone_fields_recursive(Form, label, sub, choices)
setattr(Form, 'save', SubmitField(_('insert')))
return Form()


def add_bone_fields_recursive(form, label, item, choices):
def bone_fields_recursive(form, label, item, choices):
if item['preservation'] == 'percent':
setattr(
form,
label.replace(' ', '-'),
SelectField(label, choices=choices))
if 'subs' in item:
for label, sub in item['subs'].items():
add_bone_fields_recursive(form, label, sub, choices)
bone_fields_recursive(form, label, sub, choices)


def display_bone_form(form: Any, category: str) -> str:
# Todo: add manual page
html = Markup(
'<form method="post">'
f'{form.csrf_token}')
html += display_bone_row(form, category, structure[category])
return html + Markup('</form>')


def display_bone_row(
def bone_row(
form: Any,
label: str,
item: dict[str, Any],
Expand All @@ -377,5 +369,5 @@ def display_bone_row(
html += Markup('</div>')
if 'subs' in item:
for label, sub in item['subs'].items():
html += display_bone_row(form, label, sub, offset + 0.5)
html += bone_row(form, label, sub, offset + 0.5)
return html

0 comments on commit 04187bf

Please sign in to comment.