Skip to content

Commit

Permalink
Add basic citations in scholarship records page for unpublished recor…
Browse files Browse the repository at this point in the history
…ds (#1502)
  • Loading branch information
blms committed Feb 4, 2025
1 parent dec7831 commit b48c97b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 32 deletions.
6 changes: 1 addition & 5 deletions geniza/corpus/templates/corpus/document_scholarship.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ <h1 class="sr-only">{{ page_title }}</h1>
{% translate 'Bibliographic citation' %}
</dt>
<dd>
{% if source|is_index_cards %}
{{ source|handle_index_cards }}
{% else %}
{{ source.grouper.formatted_display|safe }}
{% endif %}
{{ source|process_citation }}
</dd>
{% 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 #}
Expand Down
73 changes: 49 additions & 24 deletions geniza/corpus/templatetags/corpus_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from piffle.iiif import IIIFImageClientException

from geniza.common.utils import absolutize_url
from geniza.footnotes.models import Footnote

register = template.Library()

Expand Down Expand Up @@ -200,32 +201,56 @@ def is_index_cards(source):
)


def list_to_string(lst):
"""Helper function to join a list with commas, and 'and' before the final
entry."""
return " and ".join([", ".join(lst[:-1]), lst[-1]] if len(lst) > 2 else lst)


@register.filter
def handle_index_cards(source):
def process_citation(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.")
if "unpublished index cards" in citation:
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 = list_to_string(all_cards)
citation = citation[0:-1] + f", {joined}."
# add PGL attribution
citation += " Princeton Geniza Lab, Princeton University."
elif source.grouper.source_type.type == "Unpublished":
relations = [r for rs in [fn.doc_relation for fn in source.list] for r in rs]
if (
Footnote.DIGITAL_EDITION in relations
or Footnote.DIGITAL_TRANSLATION in relations
):
authors = [
c.creator.firstname_lastname()
for c in source.grouper.authorship_set.order_by("creator__last_name")
]
citation = list_to_string(authors)
relation_display = list_to_string(
[fn.get_doc_relation_display() for fn in source.list]
)
citation += f"'s {relation_display.lower()}"
if source.grouper.year:
citation += f" ({source.grouper.year})"
citation += ", available online through the Princeton Geniza Project at "
permalink = source.list[0].content_object.permalink
citation += f'<a href="{permalink}">{permalink}</a>.'
return mark_safe(citation)
10 changes: 7 additions & 3 deletions geniza/footnotes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,13 @@ def all_authors(self):
def all_languages(self):
"""comma-delimited list of languages, in parentheses, used for the translation selector"""
if self.languages.exists():
return "(in %s)" % ", ".join(
[str(lang) for lang in self.languages.all().order_by("name")]
)
langs = [
str(lang)
for lang in self.languages.all().order_by("name")
if "Unspecified" not in str(lang)
]
if langs:
return "(in %s)" % ", ".join(langs)
return ""

def formatted_display(self, extra_fields=True, format_index_cards=False):
Expand Down

0 comments on commit b48c97b

Please sign in to comment.