Skip to content

Commit

Permalink
Bone inventory: forms
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Jan 17, 2025
1 parent 1774406 commit 2d8627d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
5 changes: 4 additions & 1 deletion openatlas/templates/tools/bones.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% for name in data %}
<p>{{ name }}</p>
<p>
{{ name }}
<a href="{{ url_for('bones_update', id_=entity.id, category=name|replace(' ', '')) }}">{{ _('edit') }}</a>
</p>
{% endfor %}
52 changes: 44 additions & 8 deletions openatlas/views/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def name_result(result: float) -> str:
return '' # pragma: no cover


def start_crumbs(entity: Entity) -> list[Any]:
def tools_start_crumbs(entity: Entity) -> list[Any]:
crumbs: list[Any] = [[_('place'), url_for('index', view='place')]]
for super_ in entity.get_structure()['supers']:
crumbs.append(link(super_))
Expand Down Expand Up @@ -81,7 +81,7 @@ def tools_index(id_: int) -> str | Response:
'tabs.html',
tabs=tabs,
entity=entity,
crumbs=start_crumbs(entity) + [_('tools')])
crumbs=tools_start_crumbs(entity) + [_('tools')])


@app.route('/tools/sex/<int:id_>')
Expand Down Expand Up @@ -118,7 +118,7 @@ def sex(id_: int) -> str | Response:
data=data,
result=sex_result(entity)),
buttons=buttons)},
crumbs=start_crumbs(entity) + [
crumbs=tools_start_crumbs(entity) + [
[_('tools'), url_for('tools_index', id_=entity.id)],
_('sex estimation')])

Expand Down Expand Up @@ -186,7 +186,7 @@ class Form(FlaskForm):
form,
manual_page='tools/anthropological_analyses'))},
entity=entity,
crumbs=start_crumbs(entity) + [
crumbs=tools_start_crumbs(entity) + [
[_('tools'), url_for('tools_index', id_=entity.id)],
[_('sex estimation'), url_for('sex', id_=entity.id)],
_('edit')])
Expand All @@ -211,7 +211,7 @@ def carbon(id_: int) -> str | Response:
'radiocarbon dating',
carbon_result(entity),
buttons=buttons)},
crumbs=start_crumbs(entity) + [
crumbs=tools_start_crumbs(entity) + [
[_('tools'), url_for('tools_index', id_=entity.id)],
_('radiocarbon dating')])

Expand Down Expand Up @@ -264,7 +264,7 @@ class Form(FlaskForm):
'tabs.html',
entity=entity,
tabs={'info': Tab('radiocarbon dating', display_form(form))},
crumbs=start_crumbs(entity) + [
crumbs=tools_start_crumbs(entity) + [
[_('tools'), url_for('tools_index', id_=entity.id)],
[_('radiocarbon dating'), url_for('carbon_update', id_=entity.id)],
_('edit')])
Expand All @@ -284,8 +284,44 @@ def bones(id_: int) -> str | Response:
tabs={
'info': Tab(
'bones',
render_template('tools/bones.html', data=structure),
render_template(
'tools/bones.html',
entity=entity,
data=structure),
buttons=buttons)},
crumbs=start_crumbs(entity) + [
crumbs=tools_start_crumbs(entity) + [
[_('tools'), url_for('tools_index', id_=entity.id)],
_('bone inventory')])


@app.route('/tools/bones_update/<int:id_>/<category>')
@required_group('readonly')
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)
# types = Bones.get_types(entity)
if is_authorized('contributor'):
pass
return render_template(
'tabs.html',
entity=entity,
tabs={
'info': Tab(
'bones',
content=category + display_form(form),
buttons=buttons)},
crumbs=tools_start_crumbs(entity) + [
[_('tools'), url_for('tools_index', id_=entity.id)],
_('bone inventory')])


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

inventory = structure[category.replace('_', ' ')]
for name, item in inventory['subs'].items():
setattr(Form, name.replace(' ', '_'), SelectField(name))
setattr(Form, 'save', SubmitField(_('insert')))
return Form()

0 comments on commit 2d8627d

Please sign in to comment.