Skip to content

Commit

Permalink
Improved filtering of sub/preceding events
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Sep 7, 2024
1 parent b95f8d9 commit 099e806
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
1 change: 0 additions & 1 deletion openatlas/api/endpoints/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,3 @@ def get() -> tuple[Resource, int] | Response:
else:
overview = ApiEntity.get_overview_counts()
return marshal(overview, overview_template()), 200

1 change: 0 additions & 1 deletion openatlas/api/resources/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import datetime
from typing import Any, Optional, Tuple

from flask import g
Expand Down
21 changes: 9 additions & 12 deletions openatlas/forms/base_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def add_description(self) -> None:
setattr(
self.form_class,
'description',
TextAreaField(_('description'), render_kw={'rows':5}))
TextAreaField(_('description'), render_kw={'rows': 5}))

def add_name_fields(self) -> None:
if 'name' in self.fields:
Expand Down Expand Up @@ -372,21 +372,18 @@ def process_form(self) -> None:
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', sort=True):
ids.append(sub.id)
self.get_sub_ids(sub, ids)
return ids

def additional_fields(self) -> dict[str, Any]:
sub_filter_ids = []
place = None
super_event = None
event_preceding = None
place = None
filter_ids = []
if not self.insert:
sub_filter_ids = self.get_sub_ids(self.entity, [self.entity.id])
super_event = self.entity.get_linked_entity('P9', inverse=True)
event_preceding = self.entity.get_linked_entity('P134')
filter_ids = [self.entity.id] + [
e.id for e in self.entity.get_linked_entities_recursive('P9') +
self.entity.get_linked_entities_recursive('P134', inverse=True)
]
if self.class_.name != 'move':
if place_ := self.entity.get_linked_entity('P7'):
place = place_.get_linked_entity_safe('P53', True)
Expand All @@ -401,12 +398,12 @@ def additional_fields(self) -> dict[str, Any]:
TableField(
self.table_items['event_view'],
super_event,
sub_filter_ids)}
filter_ids)}
if self.class_.name != 'event':
fields['event_preceding'] = TableField(
self.table_items['event_preceding'],
event_preceding,
sub_filter_ids)
filter_ids)
if self.class_.name != 'move':
fields['location'] = TableField(
self.table_items['place'],
Expand Down
4 changes: 0 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,10 @@ def test_api(self) -> None:
url_for('api_04.export_database', format_='xml'))
assert b'Shire' in rv.data
assert 'application/xml' in rv.headers.get('Content-Type')

rv = self.app.get(
url_for('api_04.export_database', format_='json'))
assert b'Shire' in rv.data
assert 'application/json' in rv.headers.get('Content-Type')

rv = self.app.get(url_for('api_04.export_database', format_='csv'))
assert b'Shire' in rv.data
assert 'application/zip' in rv.headers.get('Content-Type')
Expand Down Expand Up @@ -255,7 +253,6 @@ def test_api(self) -> None:
assert self.get_bool(rv['geometry'], 'coordinates')
for key in geojson_checklist:
assert self.get_bool(rv['properties'], key)

rv = self.app.get(url_for(
'api_04.entity', id_=place.id, format='geojson-v2'))
assert 'application/json' in rv.headers.get('Content-Type')
Expand Down Expand Up @@ -313,7 +310,6 @@ def test_api(self) -> None:
export='csvNetwork'))]:
assert b'Shire' in rv.data
assert 'application/zip' in rv.headers.get('Content-Type')

rv = self.app.get(url_for(
'api_04.linked_entities_by_properties_recursive',
id_=place.id,
Expand Down

0 comments on commit 099e806

Please sign in to comment.