Skip to content

Commit

Permalink
SYS-1574 and SYS-1575: Updated TEI and image OAI feed to match public…
Browse files Browse the repository at this point in the history
… site display assumptions (#117)

* Fixes for PR, function naming and additional test
* Added release notes and tag
* Remove unused import and wrap long comments
  • Loading branch information
kjallen committed Apr 27, 2024
1 parent 44ba3e9 commit 4541ed2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
2 changes: 1 addition & 1 deletion charts/prod-ohstaff-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replicaCount: 1

image:
repository: uclalibrary/oral-history-staff-ui
tag: v1.0.11
tag: v1.0.12
pullPolicy: Always

nameOverride: ""
Expand Down
16 changes: 8 additions & 8 deletions oh_staff_ui/classes/OralHistoryMods.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def populate_fields(self):
self._populate_rights()
self._populate_subjects()
self._populate_constituent_audio()
self._populate_narrator_image()
self._populate_interviewee_image()
self._populate_interview_content()
self._populate_series_content()

Expand Down Expand Up @@ -177,21 +177,21 @@ def _create_relateditem_audio(self, mi: MediaFile) -> MODSv34:
ri.toc = TableOfContents(text=toc.value)

for ts in MediaFile.objects.filter(
item=pi, file_type__file_code="text_master_index"
item=pi, file_type__file_code="text_master_transcript"
):
if ts.file_url != "":
ri.locations.append(
LocationOH(url=ts.file_url, usage="primary display")
)
if ts.file_url != "" and ts.file_url.endswith(".xml"):
# Due to legacy design the text_master_transcript can have 2 file types
# associated with it, we only want to show xml (TEI), and ignore html files
ri.locations.append(LocationOH(url=ts.file_url, usage="timed log"))

return ri

def _populate_narrator_image(self):
def _populate_interviewee_image(self):
for img in MediaFile.objects.filter(
item=self._item, file_type__file_code="image_submaster"
).order_by("sequence"):
self.locations.append(
LocationOH(url=img.file_url, label="Image of Narrator")
LocationOH(url=img.file_url, label="Image of Interviewee")
)

def _populate_interview_content(self):
Expand Down
7 changes: 7 additions & 0 deletions oh_staff_ui/templates/oh_staff_ui/release_notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
<h3>Release Notes</h3>
<hr/>

<h4>1.0.12</h4>
<p><i>April 26, 2024</i></p>
<ul>
<li>Display value associated with images changed from Narrator to Interviewee in OAI feed</li>
<li>TEI documents are now presented as mods:location/mods:url[@="timed_log"] inside mods:relatedItem</li>
</ul>

<h4>1.0.11</h4>
<p><i>April 26, 2024</i></p>
<ul>
Expand Down
40 changes: 38 additions & 2 deletions oh_staff_ui/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,12 @@ def setUpTestData(cls):
file="oh_static/text/submasters/fake-abcdef-2-master-tei.xml",
)

# Utility methods to pretty print xml
def prettify_xml(self, xml: str) -> str:
root = etree.fromstring(xml.serializeDocument())
pretty_xml = etree.tostring(root, pretty_print=True, encoding="unicode")
return pretty_xml

# Utility methods to return MODS specific to item type
def get_mods_from_audio_item(self):
return self.get_mods_from_item_type(type="audio")
Expand Down Expand Up @@ -1322,7 +1328,7 @@ def test_valid_timing_log(self):
def test_valid_mods_image(self):
ohmods = self.get_mods_from_interview_item()
self.assertTrue(
b'<mods:location displayLabel="Image of Narrator">'
b'<mods:location displayLabel="Image of Interviewee">'
in ohmods.serializeDocument()
)

Expand Down Expand Up @@ -1356,7 +1362,8 @@ def test_series_relateditem_on_items(self):
)

def test_timed_log_attribute_is_added(self):
# If an item contains a TEI/XML transcript, it should have a usage attribute with value "timed_log"
# If an item contains a TEI/XML transcript, it should have a usage attribute
# with value "timed_log"
if MediaFile(
item=self.audio_item,
file_type=MediaFileType.objects.get(file_code="text_master_transcript"),
Expand All @@ -1366,6 +1373,35 @@ def test_timed_log_attribute_is_added(self):
b'<mods:url usage="timed log">' in ohmods.serializeDocument()
)

def test_absence_of_timed_log_with_text_master_index(self):
# If an item does not contain a file_code of text_master_transcript,
# mods:url[@usage="timed log"] should not be present.

# Delete MediaFile associated with "text_master_transcript" file_code
media_file = MediaFile.objects.get(
item__id=self.audio_item.id, file_type__file_code="text_master_transcript"
)
media_file.delete()

ohmods = self.get_mods_from_audio_item()

# At this point we should only have "text_master_index" file_code MediaFile
if MediaFile.objects.get(
item__id=self.audio_item.id, file_type__file_code="text_master_index"
):
self.assertFalse(
b'<mods:url usage="timed log">' in ohmods.serializeDocument()
)

# Add "text_master_transcript" back in case future tests rely on it
MediaFile.objects.create(
created_by=self.user,
file_type=MediaFileType.objects.get(file_code="text_master_transcript"),
item=self.audio_item,
original_file_name="FAKE_TEI_TIMED_LOG",
file="oh_static/text/submasters/fake-abcdef-2-master-tei.xml",
)

def test_writing_single_mods(self):
ohmods = self.get_mods_from_interview_item()
ohmods.write_mods_record()
Expand Down

0 comments on commit 4541ed2

Please sign in to comment.