Skip to content

Commit

Permalink
Update citations for Goitein index cards (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Feb 4, 2025
1 parent 1cc58d8 commit f3f27bb
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 3 deletions.
8 changes: 6 additions & 2 deletions geniza/corpus/templates/corpus/document_scholarship.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ <h1 class="sr-only">{{ page_title }}</h1>
{% translate 'Bibliographic citation' %}
</dt>
<dd>
{{ source.grouper.formatted_display|safe }}
{% if source|is_index_cards %}
{{ source|handle_index_cards }}
{% else %}
{{ source.grouper.formatted_display|safe }}
{% endif %}
</dd>
{% if source.list|has_location_or_url %}
{% if not source|is_index_cards and source.list|has_location_or_url %}
{# Translators: accessibility label for the specific location of a citation in a source record #}
<dt class="sr-only">{% translate "Location in source" %}</dt>
<dd>
Expand Down
41 changes: 41 additions & 0 deletions geniza/corpus/templatetags/corpus_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re

from django import template
from django.template.defaultfilters import pluralize
from django.urls import reverse
from django.urls import translate_url as django_translate_url
from django.utils.safestring import mark_safe
Expand Down Expand Up @@ -188,3 +189,43 @@ def all_doc_relations(footnotes):
for fn in footnotes:
relations.update(set([n.strip() for n in str(fn.doc_relation).split(",")]))
return sorted(relations)


@register.filter
def is_index_cards(source):
"""For scholarship records list: indicate whether or not a source record
relates to Goitein index cards."""
return "unpublished index cards" in source.grouper.formatted_display(
format_index_cards=True
)


@register.filter
def handle_index_cards(source):
"""For scholarship records list: handle Goitein index cards by including
URLs and index card numbers when available, and by adding the attribution
to the PGL."""
citation = source.grouper.formatted_display(format_index_cards=True)
all_cards = []
# add card numbers
for fn in source.list:
# remove "Card" or "card" from the location field first, we just want #NNN
loc = re.sub("[Cc]ard ", "", fn.location)
card_str = ""
# add URL if present
if loc and fn.url:
card_str = f'<a href="{fn.url}">{loc}</a>'
elif loc:
card_str = str(loc)
if card_str:
all_cards.append(card_str)
if all_cards:
# if card #s are present, include them as a list in the citation
joined = " and ".join(
[", ".join(all_cards[:-1]), all_cards[-1]]
if len(all_cards) > 2
else all_cards
)
citation = citation[0:-1] + f", {joined}."
# add PGL attribution
return mark_safe(citation + " Princeton Geniza Lab, Princeton University.")
48 changes: 48 additions & 0 deletions geniza/corpus/tests/test_corpus_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import pytest
from django.http.request import HttpRequest, QueryDict
from django.urls import reverse
from piffle.iiif import IIIFImageClient
from pytest_django.asserts import assertContains

from geniza.common.utils import absolutize_url
from geniza.corpus.templatetags import admin_extras, corpus_extras
Expand Down Expand Up @@ -76,6 +78,52 @@ def test_all_doc_relations(self, document, footnote):
"Edition",
]

def test_handle_index_cards(self, document, footnote, index_cards, client):
# no index card numbers
fn = Footnote.objects.create(
object_id=document.pk,
content_type=footnote.content_type,
source=index_cards,
doc_relation=Footnote.DISCUSSION,
)
response = client.get(
reverse("corpus:document-scholarship", args=[document.pk])
)
assertContains(response, "cards (1950–85). Princeton Geniza Lab")

# one card with numbers
fn.location = "Card #1234"
fn.save()
response = client.get(
reverse("corpus:document-scholarship", args=[document.pk])
)
assertContains(response, "cards (1950–85), #1234. Princeton Geniza Lab")

# multiple cards
Footnote.objects.create(
object_id=document.pk,
content_type=footnote.content_type,
source=index_cards,
doc_relation=Footnote.DISCUSSION,
location="card #5678",
)
response = client.get(
reverse("corpus:document-scholarship", args=[document.pk])
)
assertContains(
response, "cards (1950–85), #1234 and #5678. Princeton Geniza Lab"
)

# card with link
fn.url = "https://fake.goitein.card/"
fn.save()
response = client.get(
reverse("corpus:document-scholarship", args=[document.pk])
)
assertContains(
response, '<a href="https://fake.goitein.card/">#1234</a>', html=True
)


def test_dict_item():
# no error on non-dict first argument
Expand Down
12 changes: 12 additions & 0 deletions geniza/footnotes/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ def unpublished_editions(db):
return source


@pytest.fixture
def index_cards(db):
# fixture for unpublished index cards
unpub = SourceType.objects.get(type="Unpublished")
source = Source.objects.create(
source_type=unpub, title_en="index cards", volume="CUL"
)
author = Creator.objects.create(last_name_en="Goitein", first_name_en="S. D.")
Authorship.objects.create(creator=author, source=source)
return source


@pytest.fixture
def book_section(db):
# fixture to create and return a book section source
Expand Down
8 changes: 7 additions & 1 deletion geniza/footnotes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def all_languages(self):
)
return ""

def formatted_display(self, extra_fields=True):
def formatted_display(self, extra_fields=True, format_index_cards=False):
"""Format source for display; used on document scholarship page.
To omit publisher, place_published, and page_range fields,
specify `extra_fields=False`."""
Expand Down Expand Up @@ -248,6 +248,12 @@ def formatted_display(self, extra_fields=True):
# if this is a machine learning model, format appropriately
elif "model" in self.source_type.type:
work_title = "Machine-generated transcription (%s)" % self.title
elif (
format_index_cards
and "Goitein" in author
and "index card" in self.title.lower()
):
work_title = "unpublished index cards (1950–85)"
# otherwise, just leave unformatted
else:
work_title = self.title + ltr_mark
Expand Down
3 changes: 3 additions & 0 deletions geniza/footnotes/tests/test_footnote_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ def test_formatted_mlmodel(self):
== "Machine-generated transcription (%s)." % source.title_en
)

def test_formatted_indexcard(self, index_cards):
assert "unpublished index cards (1950–85)" in index_cards.formatted_display()

def test_get_volume_from_shelfmark(self):
assert Source.get_volume_from_shelfmark("T-S 3564.5J") == "T-S 35"
assert Source.get_volume_from_shelfmark("Bodl. 3563") == "Bodl."
Expand Down

0 comments on commit f3f27bb

Please sign in to comment.