Skip to content

Commit

Permalink
feat(generic): adapt importer to rdf parser list style return values
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Dec 17, 2024
1 parent 63f9e83 commit b4c0f27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apis_core/generic/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from django.core.exceptions import ImproperlyConfigured

from apis_core.utils.helpers import flatten_if_single
from apis_core.utils.normalize import clean_uri
from apis_core.utils.rdf import get_definition_and_attributes_from_uri

Expand Down Expand Up @@ -70,6 +71,7 @@ def get_data(self, drop_unknown_fields=True):
# we are dropping all fields that are not part of the model
modelfields = [field.name for field in self.model._meta.fields]
data = {key: data[key] for key in data if key in modelfields}
data = {key: flatten_if_single(value) for key, value in data.items()}
if not data:
raise ImproperlyConfigured(
f"Could not import {self.import_uri}. Data fetched was: {data}"
Expand Down
6 changes: 6 additions & 0 deletions apis_core/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,9 @@ def construct_lookup(value: str) -> tuple[str, str]:
if value.startswith("*") and value.endswith("*"):
value = value[1:-1]
return "__icontains", value


def flatten_if_single(value: list):
if len(value) == 1:
return value[0]
return value

0 comments on commit b4c0f27

Please sign in to comment.