Skip to content

Commit

Permalink
Merge branch 'develop' into feature/api_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardKoschicek committed Sep 9, 2024
2 parents df1b6c3 + 099e806 commit ab7a879
Show file tree
Hide file tree
Showing 5 changed files with 12 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

3 changes: 2 additions & 1 deletion openatlas/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "OpenAtlas API",
"description": "An API that allows user to access data from an OpenAtlas instance.",
"version": "0.4.4c",
"version": "0.4.4d",
"contact": {
"name": "OpenAtlas",
"url": "https://openatlas.eu",
Expand Down Expand Up @@ -4045,6 +4045,7 @@
"type": "object",
"required": [
"move",
"external_reference",
"bibliography",
"person",
"acquisition",
Expand Down
1 change: 1 addition & 0 deletions openatlas/api/resources/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def subunit_template(id_: str) -> dict[str, List]:
def overview_template() -> dict[str, Type[String | Integer]]:
return {
'move': fields.Integer,
'external_reference': fields.Integer,
'bibliography': fields.Integer,
'person': fields.Integer,
'acquisition': fields.Integer,
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 ab7a879

Please sign in to comment.