Skip to content

Commit

Permalink
Merge branch 'develop' into feature/1614-docsearch-redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Jul 31, 2024
2 parents bf401ef + fbd984c commit a8d96f1
Show file tree
Hide file tree
Showing 28 changed files with 774 additions and 282 deletions.
13 changes: 13 additions & 0 deletions geniza/corpus/solr_queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class DocumentSolrQuerySet(AliasedSolrQuerySet):
"has_digital_translation": "has_digital_translation_b",
"has_discussion": "has_discussion_b",
"old_shelfmark": "old_shelfmark_bigram",
"old_shelfmark_t": "old_shelfmark_t",
"transcription_nostem": "transcription_nostem",
"description_nostem": "description_nostem",
"related_people": "people_count_i",
Expand Down Expand Up @@ -293,4 +294,16 @@ def get_highlighting(self):
highlights[doc]["translation"] = [
clean_html(s) for s in highlights[doc]["translation"]
]

# handle old shelfmark highlighting; sometimes it's on one or the other
# field, and sometimes one of the highlight results is empty
if "old_shelfmark" in highlights[doc]:
highlights[doc]["old_shelfmark"] = ", ".join(
[h for h in highlights[doc]["old_shelfmark"] if h]
)
elif "old_shelfmark_t" in highlights[doc]:
highlights[doc]["old_shelfmark"] = ", ".join(
[h for h in highlights[doc]["old_shelfmark_t"] if h]
)

return highlights
136 changes: 103 additions & 33 deletions geniza/corpus/templates/corpus/document_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,83 @@ <h2 class="sr-only">
</dl>
</section>

{% if document.has_image or document.digital_editions.count or document.digital_translations.count %}
{% with n_transcriptions=document.digital_editions.count n_translations=document.digital_translations.count %}
<section class="content-stats">
{# Translators: label for document content stats (number of translations, transcriptions, images) #}
<h2>{% translate "What's in the PGP" %}</h2>
<ul>
{# translators: indicator that a document has an image #}
{% if document.has_image %}<li class="has-image">{% translate 'Image' %}</li>{% endif %}
{% if n_transcriptions > 0 %}
{# translators: n_transcriptions is the number of a document's digitized transcriptions #}
<li class="transcription-count">
{% blocktranslate count counter=n_transcriptions trimmed %}
{{ n_transcriptions }} Transcription
{% plural %}
{{ n_transcriptions }} Transcriptions
{% endblocktranslate %}
</li>
{% endif %}
{% if n_translations > 0 %}
{# translators: n_translations is the number of a document's digitized translations #}
<li class="translation-count">
{% blocktranslate count counter=n_translations trimmed %}
{{ n_translations }} Translation
{% plural %}
{{ n_translations }} Translations
{% endblocktranslate %}
</li>
{% endif %}
</ul>
</section>
{% endwith %}
{% endif %}

<section class="description">
{# Translators: label for document description #}
<h2>{% translate 'Description' %}</h2>
<p>{{ document.description|pgp_urlize }}</p>
</section>

{# related people #}
{% if related_people.exists %}
<section class="related">
{# Translators: heading label for document related people #}
<h2>{% translate "Related People" %}</h2>
<dl>
{% regroup related_people by type as person_relations %}
{% for relation_type in person_relations %}
<dt>{{ relation_type.grouper }}</dt>
<dd>
{% for relation in relation_type.list %}
{% if relation.person.get_absolute_url %}<a data-turbo="false" href="{{ relation.person.get_absolute_url }}">{{ relation.person }}</a>{% else %}{{ relation.person }}{% endif %}{% if not forloop.last %}, {% endif %}
{% endfor %}
</dd>
{% endfor %}
</dl>
</section>
{% endif %}

{# related places #}
{% if related_places.exists %}
<section class="related">
{# Translators: heading label for document related places #}
<h2>{% translate "Related Places" %}</h2>
<dl>
{% regroup related_places.all by type as place_relations %}
{% for relation_type in place_relations %}
<dt>{{ relation_type.grouper }}</dt>
<dd>
{% for relation in relation_type.list %}
<a data-turbo="false" href="{{ relation.place.get_absolute_url }}">{{ relation.place }}</a>{% if not forloop.last %}, {% endif %}
{% endfor %}
</dd>
{% endfor %}
</dl>
</section>
{% endif %}

{% if document.tags.exists %}
<section>
{# Translators: label for tags on a document #}
Expand All @@ -136,51 +213,44 @@ <h2 class="sr-only">{% translate 'Tags' %}</h2>
</ul>
</section>
{% endif %}

<section class="extra-metadata">
<h2 class="sr-only">
{# Translators: label for secondary/historiographical metadata #}
{% translate 'Additional metadata' %}
</h2>
<dl>
{% if document.fragment_historical_shelfmarks %}
{# Translators: label for historical/old shelfmarks on document fragments #}
<dt>{% translate 'Historical shelfmarks' %}</dt>
<dd>{{ document.fragment_historical_shelfmarks }}</dd>
{% endif %}
{# Translators: Label for date document was first added to the PGP #}
<dt>{% translate 'Input date' %}</dt>
<dd>
{# Translators: Date document was first added to the PGP #}
{% blocktranslate with date=document.log_entries.last.action_time.year %}
In PGP since {{ date }}
{% endblocktranslate %}
</dd>
</dl>
</section>

<section class="description">
<h2>
{# Translators: label for document description #}
{% translate 'Description' %}
</h2>
<p>{{ document.description|pgp_urlize }}</p>
</section>
</div>

<section class="extra-metadata">
<h2 class="sr-only">
{# Translators: label for secondary/historiographical metadata #}
{% translate 'Additional metadata' %}
</h2>
<dl>
{% if document.fragment_historical_shelfmarks %}
{# Translators: label for historical/old shelfmarks on document fragments #}
<dt>{% translate 'Historical shelfmarks' %}</dt>
<dd>{{ document.fragment_historical_shelfmarks }}</dd>
{% endif %}
{# Translators: Label for date document was first added to the PGP #}
<dt>{% translate 'Input date' %}</dt>
<dd>
{# Translators: Date document was first added to the PGP #}
{% blocktranslate with date=document.log_entries.last.action_time.year %}
In PGP since {{ date }}
{% endblocktranslate %}
</dd>
</dl>
</section>

{# viewer #}
{% include "corpus/snippets/document_transcription.html" %}

{# tertiary metadata #}
<dl class="metadata-list tertiary">
{# Translators: label for permanent link to a document #}
{% translate 'Permalink' as permalink %}
{% translate 'Link to this document:' as permalink %}
<dt id="permalink" aria-hidden="true"> {# aria hidden because redundant for screen readers #}
<svg role="presentation"><use xlink:href="{% static 'img/ui/all/all/permalink-icon.svg' %}#permalink-icon" /></svg>
<i class="ph-link"></i>
{{ permalink }}
</dt>
<dd>
<a href="{{ document.permalink }}" rel="bookmark" aria-label="{{ permalink }}">
{# Translators: accessibility label for permanent link to a document #}
<a href="{{ document.permalink }}" rel="bookmark" aria-label="{% translate 'Permalink' %}">
{{ document.permalink }}
</a>
</dd>
Expand Down
36 changes: 18 additions & 18 deletions geniza/corpus/templates/corpus/document_scholarship.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,36 @@ <h1 class="sr-only">{{ page_title }}</h1>
<dd>
{{ source.grouper.formatted_display|safe }}
</dd>
<dt class="relation">
{# Translators: label for included document relations for a single footnote #}
{% translate "includes" as includes_text %}
{% if source.list|has_location_or_url %}
{# Translators: label for document relations in list of footnotes #}
{% blocktranslate with relation=source.list|all_doc_relations|lower trimmed %}
for {{ relation }} see
{% endblocktranslate%}
{% else %}
{# Translators: label for document relations for one footnote with no location or URL #}
{% blocktranslate with relation=source.list|all_doc_relations|lower trimmed %}
includes {{ relation }}
{% endblocktranslate%}
{% endif %}
</dt>
{% if source.list|has_location_or_url %}
<dd class="relation">
<ul>
{# Translators: accessibility label for the specific location of a citation in a source record #}
<dt class="sr-only">{% translate "Location in source" %}</dt>
<dd>
<ul class="locations">
{% for fn in source.list %}
{% ifchanged %}{# omit duplicate footnote locations #}
<li class="location">{% include "corpus/snippets/footnote_location.html" %}</li>
<li>{% include "corpus/snippets/footnote_location.html" %}</li>
{% endifchanged %}
{% endfor %}
</ul>
</dd>
{% endif %}

{# Translators: accessibility label for the relationship(s) of a source to a document #}
<dt class="sr-only">{% translate "Relation to document" %}</dt>
<dd>
<ul class="relations">
{% for relation in source.list|all_doc_relations %}
<li>{{ relation }}</li>
{% endfor %}
</ul>
</dd>
</dl>
</li>
{% endspaceless %}
{% endfor %}
</ol>
</div>

{# viewer #}
{% include "corpus/snippets/document_transcription.html" %}
{% endblock main %}
33 changes: 22 additions & 11 deletions geniza/corpus/templates/corpus/snippets/document_tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@
<!-- document detail page navigation -->
{# Translators: accessibility text label for document detail view tabs navigation #}
<nav aria-label="{% translate "tabs" %}" id="tabs">
<ul class="tabs">
{% url 'corpus:document' pk=document.pk as document_url %}
<li><a href="{{ document_url }}"{% if request.path == document_url %} aria-current="page"{% endif %}>{% translate "Document Details" %}</a></li>
{% with n_records=document.sources|length %}
{% with n_records=document.sources|length n_reldocs=document.related_documents.count %}
<ul class="tabs">
{% url 'corpus:document' pk=document.pk as document_url %}
{% translate "Document Details" as details_text %}
<li><a href="{{ document_url }}"{% if request.path == document_url %} aria-current="page"{% endif %}>{{ details_text }}</a></li>
{# Translators: n_records is number of scholarship records #}
{% blocktranslate asvar srec_text %}Scholarship Records ({{ n_records }}){% endblocktranslate %}
{% blocktranslate asvar srec_text %}Select Bibliography ({{ n_records }}){% endblocktranslate %}
{% url 'corpus:document-scholarship' pk=document.pk as scholarship_url %}
<li>{% if n_records > 0 %}<a href="{{ scholarship_url }}"{% if request.path == scholarship_url %} aria-current="page"{% endif %}>{{ srec_text }}</a>{% else %}<span disabled aria-disabled="true">{{ srec_text }}</span>{% endif %}</li>
{% endwith %}

{# Translators: n_reldocs is number of related documents #}
{% with n_reldocs=document.related_documents.count %}
{# Translators: n_reldocs is number of related documents #}
{% blocktranslate asvar reldoc_text %}Related Documents ({{ n_reldocs }}){% endblocktranslate %}
{% url 'corpus:related-documents' pk=document.pk as reldoc_url %}
<li>{% if n_reldocs > 0 %}<a href="{{ reldoc_url }}"{% if request.path == reldoc_url %} aria-current="page"{% endif %}>{{ reldoc_text }}</a>{% else %}<span disabled aria-disabled="true">{{ reldoc_text }}</span>{% endif %}</li>
{% endwith %}
</ul>
</ul>
{# select dropdown for mobile only #}
{# Translators: accessibility text label for document navigation on mobile devices #}
<select aria-label="{% translate "page select" %}" class="mobile-select" data-controller="menu" data-action="change->menu#changePage">
<option value="{{ document_url }}"{% if request.path == document_url %} selected{% endif %}>
{{ details_text }}
</option>
<option value="{{ scholarship_url }}"{% if n_records == 0 %} disabled{% elif request.path == scholarship_url %} selected{% endif %}>
{{ srec_text }}
</option>
<option value="{{ reldoc_url }}"{% if n_reldocs == 0 %} disabled{% elif request.path == reldoc_url %} selected{% endif %}>
{{ reldoc_text }}
</option>
</select>
{% endwith %}
</nav>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% elif perms.corpus.change_document %}
{% for ed in document.digital_editions.all %}
{# TODO: Make machine learning model editions editable once line-level editing implemented #}
<a class="editor-navigation" href="{% url 'corpus:document-transcribe' document.id ed.source.pk %}" data-turbo="false">
<a class="editor-add" href="{% url 'corpus:document-transcribe' document.id ed.source.pk %}" data-turbo="false">
<i class="ph-pencil"></i>
{% if not 'model' in ed.source.source_type.type %}
<span>Edit {% for auth in ed.source.authorship_set.all %}{% include "snippets/comma.html" %}{{ auth.creator.last_name }}{% empty %}[unknown]{% endfor %}'s edition</span>
Expand All @@ -14,17 +14,17 @@
</a>
{% endfor %}
{% for tr in document.digital_translations.all %}
<a class="editor-navigation" href="{% url 'corpus:document-translate' document.id tr.source.pk %}" data-turbo="false">
<a class="editor-add" href="{% url 'corpus:document-translate' document.id tr.source.pk %}" data-turbo="false">
<i class="ph-pencil"></i>
<span>Edit {% for auth in tr.source.authorship_set.all %}{% include "snippets/comma.html" %}{{ auth.creator.last_name }}{% empty %}[unknown]{% endfor %}'s translation</span>
</a>
{% endfor %}
{% if document.id %}
<a class="editor-navigation" href="{% url 'corpus:document-add-transcription' document.id %}" data-turbo="false">
<a class="editor-add" href="{% url 'corpus:document-add-transcription' document.id %}" data-turbo="false">
<i class="ph-plus-circle"></i>
<span>Add a new transcription</span>
</a>
<a class="editor-navigation" href="{% url 'corpus:document-add-translation' document.id %}" data-turbo="false">
<a class="editor-add" href="{% url 'corpus:document-add-translation' document.id %}" data-turbo="false">
<i class="ph-plus-circle"></i>
<span>Add a new translation</span>
</a>
Expand Down
8 changes: 5 additions & 3 deletions geniza/corpus/templatetags/corpus_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def has_location_or_url(footnotes):

@register.filter
def all_doc_relations(footnotes):
"""For scholarship records list: join doc relations for all footnotes
by a comma."""
return ", ".join(sorted(set([str(fn.doc_relation) for fn in footnotes])))
"""For scholarship records list: list doc relations for all footnotes."""
relations = set()
for fn in footnotes:
relations.update(set([n.strip() for n in str(fn.doc_relation).split(",")]))
return sorted(relations)
26 changes: 26 additions & 0 deletions geniza/corpus/tests/test_corpus_solrqueryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,29 @@ def test_get_highlighting__exact_search(self):
assert dqs.get_highlighting()["doc.1"]["transcription"][0] == clean_html(
"exact match"
)

def test_get_highlighting__old_shelfmark(self):
dqs = DocumentSolrQuerySet()
with patch("geniza.corpus.solr_queryset.super") as mock_super:
mock_get_highlighting = mock_super.return_value.get_highlighting
test_highlight = {
"doc.1": {
# typical formatting for an old_shelfmark highlight
"old_shelfmark": ["", "matched", "secondmatch"],
}
}
mock_get_highlighting.return_value = test_highlight
# should flatten list with comma separation
assert (
dqs.get_highlighting()["doc.1"]["old_shelfmark"]
== "matched, secondmatch"
)

test_highlight = {
"doc.1": {
"old_shelfmark_t": ["", "matched"],
}
}
mock_get_highlighting.return_value = test_highlight
# should use old_shelfmark_t highlight
assert dqs.get_highlighting()["doc.1"]["old_shelfmark"] == "matched"
Loading

0 comments on commit a8d96f1

Please sign in to comment.