Skip to content

Commit

Permalink
Fixes for creator field
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellabitta committed Jan 8, 2025
1 parent dea8a76 commit f2ebcbc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
15 changes: 12 additions & 3 deletions ingest_wikimedia/wikimedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,17 @@ def get_wiki_text(
is_shown_at = escape_wiki_strings(get_str(item_metadata, EDM_IS_SHOWN_AT))
local_id = extract_strings(source_resource, DC_IDENTIFIER_FIELD_NAME)

template_string = """== {{int:filedesc}} ==
{{ Artwork
| Other fields 1 = {{ InFi | Creator | $creator }}
if creator_string:
creator_template = """
| Other fields 1 = {{ InFi | Creator | $creator | id=fileinfotpl_aut}}"""
else:
creator_template = ""

template_string = (
"""== {{int:filedesc}} ==
{{ Artwork"""
+ creator_template
+ """
| title = $title
| description = $description
| date = $date_string
Expand All @@ -157,6 +165,7 @@ def get_wiki_text(
}}
| Institution = {{ Institution | wikidata = $data_provider }}
}}"""
)

return Template(template_string).substitute(
creator=creator_string,
Expand Down
23 changes: 22 additions & 1 deletion tests/test_wikimedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,28 @@ def test_get_wiki_text():
expected_text = (
"== {{int:filedesc}} ==\n"
" {{ Artwork\n"
" | Other fields 1 = {{ InFi | Creator | John Doe }}\n"
" | Other fields 1 = {{ InFi | Creator | John Doe | id=fileinfotpl_aut}}\n"
" | title = Sample Title\n"
" | description = Sample Description\n"
" | date = 2023\n"
" | permission = {{NKC | Q12345}}\n"
" | source = {{ DPLA\n"
" | Q12345\n"
" | hub = Q67890\n"
" | url = http://example.com/item/12345\n"
" | dpla_id = 12345\n"
" | local_id = ID12345\n"
" }}\n"
" | Institution = {{ Institution | wikidata = Q12345 }}\n"
" }}"
)
assert text == expected_text

item_metadata["sourceResource"].pop("creator")
text = get_wiki_text(dpla_id, item_metadata, provider, data_provider)
expected_text = (
"== {{int:filedesc}} ==\n"
" {{ Artwork\n"
" | title = Sample Title\n"
" | description = Sample Description\n"
" | date = 2023\n"
Expand Down

0 comments on commit f2ebcbc

Please sign in to comment.