Skip to content
Snippets Groups Projects
Commit 245984bf authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Merge branch 'remove-transcription-sources-count' into 'master'

Remove transcriptions sources count filter from element list views

Closes #389

See merge request !904
parents 32946e3d 1728db53
No related branches found
No related tags found
1 merge request!904Remove transcriptions sources count filter from element list views
......@@ -148,20 +148,6 @@ class ElementsListMixin(object):
'type': 'boolean',
'default': False
}
},
{
'name': 'with_transcription_sources_count',
'in': 'query',
'description': (
'Include the `transcription_sources_count` '
'integer to count available transcriptions sources for each element. '
'Otherwise, `transcription_sources_count` will always be null.'
),
'required': False,
'schema': {
'type': 'boolean',
'default': False
}
}
]
}
......@@ -245,10 +231,6 @@ class ElementsListMixin(object):
# Use queryset.distinct() whenever best_class is defined
queryset = queryset.filter(class_filters).distinct()
transcription_sources_count = self.request.query_params.get('with_transcription_sources_count')
if transcription_sources_count and transcription_sources_count.lower() not in ('false', '0'):
queryset = queryset.annotate(transcription_sources_count=Count('transcriptions__source_id', distinct=True))
with_children_count = self.request.query_params.get('with_children_count')
if with_children_count and with_children_count.lower() not in ('false', '0'):
queryset = BulkMap(_fetch_children_count, queryset)
......
......@@ -144,11 +144,10 @@ class ElementListSerializer(ElementSlimSerializer):
"""
best_classes = ClassificationSerializer(many=True, default=None, read_only=True)
children_count = serializers.IntegerField(default=None, read_only=True)
transcription_sources_count = serializers.IntegerField(default=None, read_only=True)
class Meta(ElementSlimSerializer.Meta):
model = Element
fields = ElementSlimSerializer.Meta.fields + ('best_classes', 'children_count', 'transcription_sources_count')
fields = ElementSlimSerializer.Meta.fields + ('best_classes', 'children_count')
class ElementParentSerializer(serializers.Serializer):
......
......@@ -91,7 +91,6 @@ class TestChildrenElements(FixtureAPITestCase):
},
"best_classes": None,
"children_count": None,
"transcription_sources_count": None,
"thumbnail_url": nested_volume.thumbnail.s3_url,
"thumbnail_put_url": None,
}
......@@ -138,24 +137,3 @@ class TestChildrenElements(FixtureAPITestCase):
'Volume 1, page 2r': 0,
}
)
def test_children_with_transcription_sources_count(self):
with self.assertNumQueries(7):
response = self.client.get(
reverse('api:elements-children', kwargs={'pk': str(self.vol.id)}),
data={'with_transcription_sources_count': True}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertDictEqual(
{element['name']: element['transcription_sources_count'] for element in response.json()['results']},
{
'Act 1': 0,
'Act 2': 0,
'Act 3': 0,
'Act 4': 0,
'Act 5': 0,
'Volume 1, page 1r': 1,
'Volume 1, page 1v': 1,
'Volume 1, page 2r': 1,
}
)
......@@ -2,7 +2,7 @@ from django.urls import reverse
from rest_framework import status
from arkindex_common.ml_tool import MLToolType
from arkindex.documents.models import \
Element, DataSource, Transcription, Corpus
Element, DataSource, Corpus
from arkindex.project.tests import FixtureAPITestCase
......@@ -109,25 +109,3 @@ class TestParentsElements(FixtureAPITestCase):
{element['name']: element['children_count'] for element in response.json()['results']},
{'Act 1': 1},
)
def test_parent_transcription_sources_count_multiple(self):
surface = Element.objects.get(name='Surface A')
parent = Element.objects.get(name='Act 1')
# Add transcriptions from two different sources on the parent
sources = [DataSource.objects.get(slug='test'), self.manual_source]
parent.transcriptions.bulk_create([
Transcription(element=parent, zone=surface.zone, source=s)
for s in sources
])
with self.assertNumQueries(5):
response = self.client.get(
reverse('api:elements-parents', kwargs={'pk': str(surface.id)}),
data={'with_transcription_sources_count': True},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertDictEqual(
{element['name']: element['transcription_sources_count'] for element in response.json()['results']},
{
'Act 1': 2,
}
)
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