Skip to content
Snippets Groups Projects
Commit 6033ddc3 authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Frontend layout updates

parent 94fd57ba
No related branches found
No related tags found
No related merge requests found
from arkindex.documents.models import Transcription, Act, Element, ElementType
from arkindex.documents.models import Transcription, Act, Element
from itertools import chain
import uuid
......@@ -45,29 +45,23 @@ def search_acts_post(data):
transcriptions = {
t.id: t
for t in Transcription.objects.filter(id__in=tr_ids)
for t in Transcription.objects.filter(id__in=tr_ids).prefetch_related('zone__image__server')
}
acts = Act.objects.filter(id__in=act_ids)
acts = Act.objects.filter(id__in=act_ids).prefetch_related('corpus')
acts_tr_ids = {
uuid.UUID(result['_id']): [
uuid.UUID(hit['_source']['id'])
for hit in result['inner_hits']['transcriptions']['hits']['hits']
] for result in results
}
all_surfaces = Element.objects.get_descendings(
type=ElementType.Surface,
parents_ids=act_ids,
prefetch=('zone__image__server',)
)
all_parents = Element.objects.get_ascendings_paths(*act_ids)
all_paths = Element.objects.get_ascendings_paths(*act_ids)
for act in acts:
act.transcriptions_results = [transcriptions[tid] for tid in acts_tr_ids[act.id]]
act.total_transcriptions = tr_totals[act.id]
act.surfaces = [surf.zone for surf in all_surfaces.get(act.id, [])]
act.parents = all_parents.get(act.id, [])
act.parent_paths = all_paths.get(act.id, [])
return sorted(acts, key=lambda a: act_scores[a.id], reverse=True)
......
from rest_framework import serializers
from arkindex.documents.models import Transcription, TranscriptionType, Act
from arkindex.documents.serializers.light import CorpusLightSerializer
from arkindex.documents.serializers.elements import ElementLightSerializer
from arkindex.documents.serializers.transcriptions import TranscriptionSerializer
from arkindex.images.serializers import ZoneSerializer
......@@ -37,13 +38,12 @@ class ActSearchResultSerializer(serializers.ModelSerializer):
"""
transcriptions = TranscriptionSerializer(many=True, source='transcriptions_results')
total_transcriptions = serializers.IntegerField()
surfaces = ZoneSerializer(many=True)
parents = serializers.ListField(
parent_paths = serializers.ListField(
child=serializers.ListField(
child=ElementLightSerializer()
),
read_only=True,
)
corpus = CorpusLightSerializer()
viewer_url = ViewerURLField('api:act-manifest')
class Meta:
......@@ -54,7 +54,7 @@ class ActSearchResultSerializer(serializers.ModelSerializer):
'number',
'transcriptions',
'total_transcriptions',
'surfaces',
'parents',
'parent_paths',
'corpus',
'viewer_url',
)
from rest_framework import serializers
from arkindex.documents.models import Element, Transcription, TranscriptionType, Corpus
from arkindex.images.models import Image
from arkindex.images.serializers import ZoneSerializer
from arkindex.project.serializer_fields import EnumField
......@@ -11,6 +12,7 @@ class TranscriptionSerializer(serializers.ModelSerializer):
"""
type = EnumField(TranscriptionType)
zone = ZoneSerializer()
class Meta:
model = Transcription
......@@ -19,6 +21,7 @@ class TranscriptionSerializer(serializers.ModelSerializer):
'type',
'text',
'score',
'zone',
)
......
......@@ -96,7 +96,6 @@ class TestSearchAPI(FixtureAPITestCase):
def test_act_search(self):
act = Act.objects.get(number="1")
ts = Transcription.objects.filter(text__in=["PARIS", "ROY"], zone__image__path='img1')
surf = Element.objects.get(name="Surface A").zone
self.es_mock().count.return_value = {'count': len(ts)}
self.es_mock().search.return_value = self.build_es_response(
......@@ -116,8 +115,7 @@ class TestSearchAPI(FixtureAPITestCase):
map(str, ts.values_list('id', flat=True)),
)
self.assertEqual(len(result['surfaces']), 1)
self.assertEqual(result['surfaces'][0]['id'], str(surf.id))
self.assertEqual(result['total_transcriptions'], len(ts))
def test_iiif_transcription_search(self):
# Filter to only get transcriptions from volume 1
......
......@@ -18,24 +18,38 @@
<div class="navbar-start">
<a class="navbar-item" href="{% url 'volumes' %}">
Volumes
</a>
<a class="navbar-item" href="{% url 'transcriptions' %}">
Transcriptions
</a>
<a class="navbar-item" href="{% url 'acts' %}">
Acts
Browse
</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
Search
</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="{% url 'transcriptions' %}">
Pages
</a>
<a class="navbar-item" href="{% url 'acts' %}">
Acts
</a>
</div>
</div>
{% if user.is_authenticated %}
<a class="navbar-item" href="{% url 'imports' %}">
Imports
</a>
<a class="navbar-item" href="{% url 'files' %}">
Files
</a>
<a class="navbar-item" href="{% url 'repositories' %}">
Repositories
</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
Import
</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="{% url 'imports' %}">
Workflows
</a>
<a class="navbar-item" href="{% url 'files' %}">
Files
</a>
<a class="navbar-item" href="{% url 'repositories' %}">
Repositories
</a>
</div>
</div>
{% endif %}
</div>
......
......@@ -2,7 +2,7 @@
{% block content %}
<h1 class="title">Acts in volume {{ volume.name }}</h1>
<h2 class="subtitle">View all the acts inside a volume</h2>
<h2 class="subtitle">View all acts inside a volume</h2>
<div id="app">
<Volume-Acts id="{{ volume.id }}" />
......
{% extends 'base.html' %}
{% block content %}
<h1 class="title">Volume {{ volume.name }}</h1>
<h2 class="subtitle">View all the pages inside a volume</h2>
<div id="app">
<Volume-Pages id="{{ volume.id }}" />
</div>
{% endblock %}
{% extends 'base.html' %}
{% block content %}
<h1 class="title">Volumes</h1>
<h2 class="subtitle">List all available volumes</h2>
<div id="app">
<Volumes />
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment