Skip to content

Commit

Permalink
Sorting of related entities at entity forms
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Apr 19, 2024
1 parent 9a8475c commit c94a965
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion openatlas/forms/base_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class EventBaseManager(BaseManager):
fields = ['name', 'date', 'description', 'continue']

def get_sub_ids(self, entity: Entity, ids: list[int]) -> list[int]:
for sub in entity.get_linked_entities('P9'):
for sub in entity.get_linked_entities('P9', sort=True):
ids.append(sub.id)
self.get_sub_ids(sub, ids)
return ids
Expand Down
6 changes: 4 additions & 2 deletions openatlas/forms/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ class Form(FlaskForm):
'coordinate',
HiddenField(_('coordinates'), validators=[InputRequired()]))
table = Table(['name', 'class', 'description'])
for item in Entity.get_by_id(image_id).get_linked_entities('P67'):
for item in Entity.get_by_id(image_id).get_linked_entities(
'P67',
sort=True):
table.rows.append([
format_name_and_aliases(item, 'entity'),
item.class_.name,
Expand Down Expand Up @@ -161,7 +163,7 @@ class Form(FlaskForm):
setattr(Form, str(root.id), TreeField(str(root.id)))
choices = []
if root.class_.name == 'administrative_unit':
for entity in type_.get_linked_entities('P89', True):
for entity in type_.get_linked_entities('P89', True, sort=True):
place = entity.get_linked_entity('P53', True)
if place:
choices.append((entity.id, place.name))
Expand Down
17 changes: 11 additions & 6 deletions openatlas/forms/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AcquisitionManager(EventBaseManager):
def additional_fields(self) -> dict[str, Any]:
data: dict[str, list[Any]] = {'place': [], 'artifact': []}
if not self.insert:
for entity in self.entity.get_linked_entities('P24'):
for entity in self.entity.get_linked_entities('P24', sort=True):
data[
'artifact' if entity.class_.name == 'artifact'
else 'place'].append(entity)
Expand Down Expand Up @@ -194,7 +194,7 @@ def additional_fields(self) -> dict[str, Any]:
if self.origin and self.origin.class_.name == 'file':
selection = [self.origin]
else:
selection = self.entity.get_linked_entities('P94')
selection = self.entity.get_linked_entities('P94', sort=True)
fields = super().additional_fields()
fields['document'] = TableMultiField(
table_multi(Entity.get_by_class('file'), selection),
Expand Down Expand Up @@ -392,7 +392,7 @@ def additional_fields(self) -> dict[str, Any]:
artifacts = []
places = []
if not self.insert:
for item in self.entity.get_linked_entities('P31'):
for item in self.entity.get_linked_entities('P31', sort=True):
if item.class_.name == 'artifact':
artifacts.append(item)
elif item.cidoc_class.code == 'E18':
Expand Down Expand Up @@ -431,7 +431,9 @@ def additional_fields(self) -> dict[str, Any]:
place_from = place.get_linked_entity_safe('P53', True)
if place := self.entity.get_linked_entity('P26'):
place_to = place.get_linked_entity_safe('P53', True)
for linked_entity in self.entity.get_linked_entities('P25'):
for linked_entity in self.entity.get_linked_entities(
'P25',
sort=True):
data[linked_entity.class_.name].append(linked_entity)
elif self.origin:
if self.origin.class_.view == 'artifact':
Expand Down Expand Up @@ -505,7 +507,7 @@ def additional_fields(self) -> dict[str, Any]:
fields = super().additional_fields()
selection = None
if not self.insert and self.entity:
selection = self.entity.get_linked_entities('P108')
selection = self.entity.get_linked_entities('P108', sort=True)
fields['artifact'] = TableMultiField(
table_multi(Entity.get_by_class('artifact', True), selection),
selection)
Expand Down Expand Up @@ -581,7 +583,10 @@ def add_description(self) -> None:
def additional_fields(self) -> dict[str, Any]:
selection = None
if not self.insert and self.entity:
selection = self.entity.get_linked_entities('P128', inverse=True)
selection = self.entity.get_linked_entities(
'P128',
inverse=True,
sort=True)
elif self.origin and self.origin.class_.name == 'artifact':
selection = [self.origin]
return {
Expand Down

0 comments on commit c94a965

Please sign in to comment.