Skip to content

Commit

Permalink
refactor: adapt use of datasource, use correct fields
Browse files Browse the repository at this point in the history
use single data source object for all base entities, use correct use fields for data source and property model
  • Loading branch information
babslgam authored and koeaw committed Mar 19, 2024
1 parent 498f3a3 commit 3402d26
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions apis_ontology/management/commands/create_base_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from apis_ontology.scripts.import_helpers import create_triple, create_source

fname = os.path.basename(__file__)
data_source, created = create_source(
name="BaseEntitiesSource", file_name="additional_infos.py", data_type="python"
)


def create_archives(calling_file=fname):
Expand All @@ -15,15 +18,13 @@ def create_archives(calling_file=fname):
:param calling_file: optional argument to pass filename of the calling
script, otherwise uses this file's name
"""
import_name = "Archives_Import"

for a in ARCHIVES:
# for archives, save XML file as pubinfo when creating sources
# for later reference
source, created = create_source(import_name, metadata=a["source_file"])
Archive.objects.get_or_create(
name=a["name"],
defaults={"data_source": source},
data_source=data_source,
)


Expand All @@ -34,15 +35,10 @@ def create_persons(calling_file=fname):
:param calling_file: optional argument to pass filename of the calling
script, otherwise uses this file's name
"""
import_name = "Persons_Import"
source, created = create_source(import_name, metadata=calling_file)

for p in sorted(PERSONS, key=lambda d: d["id"]):
Person.objects.get_or_create(
name=p["name"],
first_name=p["first_name"],
last_name=p["last_name"],
defaults={"data_source": source},
forename=p["first_name"], surname=p["last_name"], data_source=data_source
)


Expand All @@ -53,8 +49,6 @@ def create_types(calling_file=fname):
:param calling_file: optional argument to pass filename of the calling
script, otherwise uses this file's name
"""
import_name = "WorkTypes_Import"
source, created = create_source(import_name, metadata=calling_file)

# types with parents, not top-level types
children = {key: val for (key, val) in WORK_TYPES.items() if val["parent_key"]}
Expand All @@ -64,7 +58,7 @@ def create_types(calling_file=fname):
wtype, created = WorkType.objects.get_or_create(
name=work_type["german_label"],
name_plural=work_type["german_label_plural"],
defaults={"data_source": source},
data_source=data_source,
)

for work_type in children.values():
Expand All @@ -76,7 +70,7 @@ def create_types(calling_file=fname):
create_triple(
entity_subj=wt_object,
entity_obj=parent_object,
prop=Property.objects.get(name="has broader term"),
prop=Property.objects.get(name_forward="has broader term"),
)


Expand Down

0 comments on commit 3402d26

Please sign in to comment.