Skip to content

Commit b67fa1b

Browse files
New classes: source translation
1 parent 9c63824 commit b67fa1b

File tree

7 files changed

+52
-33
lines changed

7 files changed

+52
-33
lines changed

config/model/classes/source.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
'inverse': True,
4848
'multiple': True}},
4949
'display': {
50+
'buttons': ['copy'],
5051
'form': {'insert_and_continue': True},
5152
'tabs': {
5253
'text': {},
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from flask_babel import lazy_gettext as _
2+
3+
model = {
4+
'attributes': {
5+
'name': {'required': True},
6+
'description': {'label': _('content'), 'annotated': True}},
7+
'relations': {
8+
'source': {
9+
'class': 'source',
10+
'property': 'P73',
11+
'inverse': True,
12+
'required': True,
13+
'mode': 'direct'}},
14+
'display': {
15+
'form': {'insert_and_continue': True},
16+
'tabs': {
17+
'note': {}}}}

config/model/model.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any
22

3-
from config.model.classes import source
3+
from config.model.classes import source, source_translation
44

55
model: dict[str, Any] = {
66
'acquisition': {
@@ -71,8 +71,7 @@
7171
'reference_system': {
7272
'attributes': {}},
7373
'source': source.model,
74-
'source_translation': {
75-
'attributes': {}},
74+
'source_translation': source_translation.model,
7675
'stratigraphic_unit': {
7776
'attributes': {},
7877
'display': {'buttons': ['network']}},

openatlas/display/classes.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from openatlas.display.tab import Tab
1010
from openatlas.display.table import Table
1111
from openatlas.display.util import (
12-
button, description, display_annotation_text_links, edit_link,
13-
format_entity_date, get_base_table_data, get_file_path, link, remove_link)
12+
button, description, edit_link, format_entity_date, get_base_table_data,
13+
get_file_path, link, remove_link)
1414
from openatlas.display.util2 import is_authorized, uc_first
1515
from openatlas.models.entity import Entity
1616
from openatlas.models.reference_system import ReferenceSystem
@@ -272,23 +272,6 @@ def add_tabs(self) -> None:
272272
class_name=name))]
273273

274274

275-
class SourceTranslationDisplay(BaseDisplay):
276-
277-
def add_button_copy(self) -> None:
278-
pass
279-
280-
def add_crumbs(self) -> None:
281-
self.crumbs = [
282-
[_('source'), url_for('index', view='source')],
283-
self.entity.get_linked_entity_safe('P73', True),
284-
self.entity.name]
285-
286-
def description_html(self) -> str:
287-
return description(
288-
display_annotation_text_links(self.entity),
289-
_('content'))
290-
291-
292275
class StratigraphicUnitDisplay(PlaceBaseDisplay):
293276

294277
def add_button_others(self) -> None:

openatlas/display/display.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def __init__(self, entity: Entity) -> None:
4747

4848
def add_crumbs(self) -> None:
4949
self.crumbs = [link(self.entity, index=True)]
50+
if self.entity.class_.name == 'source_translation':
51+
self.crumbs = [
52+
[_('source'), url_for('index', view='source')],
53+
self.entity.get_linked_entity_safe('P73', True)]
5054
if self.structure:
5155
for super_ in self.structure['supers']:
5256
self.crumbs.append(link(super_))
@@ -194,10 +198,11 @@ def add_buttons(self) -> None:
194198
self.add_button_sibling_pager()
195199

196200
def add_button_copy(self) -> None:
197-
self.buttons.append(
198-
button(
199-
_('copy'),
200-
url_for('update', id_=self.entity.id, copy='copy_')))
201+
if 'copy' in self.entity.class_.display['buttons']:
202+
self.buttons.append(
203+
button(
204+
_('copy'),
205+
url_for('update', id_=self.entity.id, copy='copy_')))
201206

202207
def add_button_delete(self) -> None:
203208
if current_user.group == 'contributor':
@@ -248,7 +253,7 @@ def add_data(self) -> None:
248253
self.data.update(self.get_type_data())
249254
for name, relation in self.entity.class_.relations.items():
250255
if relation['mode'] == 'direct':
251-
self.data[name] = [
256+
self.data[relation['label']] = [
252257
link(e) for e in self.entity.get_linked_entities(
253258
relation['property'],
254259
relation['class'],

openatlas/forms/entity_form.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Form(FlaskForm):
2828
add_name_fields(Form, entity)
2929
add_types(Form, entity.class_)
3030
add_relations(Form, entity, origin)
31-
add_description(Form, entity)
31+
add_description(Form, entity, origin)
3232
add_buttons(Form, entity)
3333
form: Any = Form(obj=entity)
3434
if request.method == 'GET' and entity.id:
@@ -62,7 +62,10 @@ def add_buttons(form: Any, entity: Entity) -> None:
6262
setattr(form, 'continue_', HiddenField())
6363

6464

65-
def add_description(form: Any, entity: Entity) -> None:
65+
def add_description(
66+
form: Any,
67+
entity: Entity,
68+
origin: Optional[Entity] = None) -> None:
6669
if 'description' not in entity.class_.attributes:
6770
return
6871
if 'annotated' not in entity.class_.attributes['description']:
@@ -71,10 +74,20 @@ def add_description(form: Any, entity: Entity) -> None:
7174
'description',
7275
TextAreaField(_('description'), render_kw={'rows': 8}))
7376
return
74-
text = ''
77+
text = entity.get_annotated_text() if entity.id else ''
7578
linked_entities = []
76-
if entity.id:
77-
text = entity.get_annotated_text()
79+
if entity.class_.name == 'source_translation':
80+
if origin:
81+
source = origin
82+
else:
83+
source = entity.get_linked_entity('P73', inverse=True)
84+
linked_entities = [
85+
{'id': e.id, 'name': e.name}
86+
for e in source.get_linked_entities('P67')]
87+
elif entity.id:
88+
linked_entities = [
89+
{'id': e.id, 'name': e.name}
90+
for e in entity.get_linked_entities('P67')]
7891
for e in entity.get_linked_entities('P67'):
7992
linked_entities.append({'id': e.id, 'name': e.name})
8093
setattr(
@@ -165,7 +178,7 @@ def add_relations(form: Any, entity: Entity, origin: Entity | None) -> None:
165178
TableField(
166179
items,
167180
selection,
168-
description=relation['description'],
181+
description=relation['tooltip'],
169182
validators=validators))
170183

171184

openatlas/models/openatlas_class.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,5 @@ def get_model(class_name: str) -> dict[str, Any]:
168168
relation['label'] = relation.get('label', name)
169169
relation['mode'] = relation.get('mode', 'tab')
170170
relation['selected'] = [] if relation['multiple'] else None
171+
relation['tooltip'] = relation.get('tooltip', None)
171172
return data

0 commit comments

Comments
 (0)