Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • arkindex/backend
1 result
Show changes
Commits on Source (2)
......@@ -891,10 +891,12 @@ class ListProcessElements(CustomPaginationViewMixin, ListAPIView):
elif dataimport.elements.exists():
# Handle a selection of elements
# The list() is necessary to make a unique SQL request to check length & content
# It's more performant, as we usually have only 1 corpus in here
elements = dataimport.elements.all()
corpus = elements.values_list('corpus_id', flat=True).distinct()
corpus = list(elements.values_list('corpus_id', flat=True).distinct())
# Check all elements are in the same corpus as the process
if corpus.count() != 1 or corpus[0] != dataimport.corpus_id:
if len(corpus) != 1 or corpus[0] != dataimport.corpus_id:
raise ValidationError({
'elements': [
'Some elements on this process are not part of corpus {}'.format(
......@@ -905,12 +907,13 @@ class ListProcessElements(CustomPaginationViewMixin, ListAPIView):
# Apply base filters as early as possible to trim results
base_filters = self.get_filters(dataimport)
if elements and dataimport.load_children:
if elements is not None and dataimport.load_children:
# Load all the children elements whose path contains the pre-selected elements
# Those children are appended to the pre-selection
elements |= Element.objects.filter(paths__path__overlap=map(str, elements.values_list('id', flat=True))).filter(**base_filters)
if not elements:
# Load the full corpus, only when elements has not been populated before
if elements is None:
# Handle all elements of the process corpus
elements = Element.objects.filter(corpus=dataimport.corpus_id)
......
......@@ -262,7 +262,7 @@ class TestProcessElements(FixtureAPITestCase):
elements = [self.folder_1, self.page_1]
self.client.force_login(self.superuser)
with self.assertNumQueries(9):
with self.assertNumQueries(7):
response = self.client.get(reverse('api:process-elements-list', kwargs={'pk': self.dataimport.id}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
......@@ -306,7 +306,7 @@ class TestProcessElements(FixtureAPITestCase):
elements = [self.line_1, self.line_2, self.line_3]
self.client.force_login(self.superuser)
with self.assertNumQueries(10):
with self.assertNumQueries(8):
response = self.client.get(reverse('api:process-elements-list', kwargs={'pk': self.dataimport.id}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
......@@ -389,7 +389,7 @@ class TestProcessElements(FixtureAPITestCase):
self.dataimport.save()
self.client.force_login(self.superuser)
with self.assertNumQueries(7):
with self.assertNumQueries(6):
response = self.client.get(reverse('api:process-elements-list', kwargs={'pk': self.dataimport.id}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
......@@ -407,7 +407,7 @@ class TestProcessElements(FixtureAPITestCase):
self.dataimport.elements.add(self.page_1.id, self.folder_2.id)
self.client.force_login(self.superuser)
with self.assertNumQueries(9):
with self.assertNumQueries(7):
response = self.client.get(reverse('api:process-elements-list', kwargs={'pk': self.dataimport.id}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
......@@ -544,7 +544,7 @@ class TestProcessElements(FixtureAPITestCase):
elements = [self.folder_1, self.page_1, self.page_3, self.line_1, self.line_2, self.line_3, self.page_2]
self.client.force_login(self.superuser)
with self.assertNumQueries(9):
with self.assertNumQueries(7):
response = self.client.get(reverse('api:process-elements-list', kwargs={'pk': self.dataimport.id}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
......@@ -566,7 +566,7 @@ class TestProcessElements(FixtureAPITestCase):
elements = [self.page_1, self.page_5, self.page_3, self.line_1, self.line_3, self.line_4, self.line_5, self.folder_2, self.page_4]
self.client.force_login(self.superuser)
with self.assertNumQueries(11):
with self.assertNumQueries(8):
response = self.client.get(reverse('api:process-elements-list', kwargs={'pk': self.dataimport.id}))
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
......@@ -654,12 +654,12 @@ class TestProcessElements(FixtureAPITestCase):
self.dataimport.save()
self.client.force_login(self.superuser)
with self.assertNumQueries(9):
with self.assertNumQueries(7):
page_1 = self.client.get(reverse('api:process-elements-list', kwargs={'pk': self.dataimport.id}))
self.assertEqual(len(page_1.json()['results']), 20)
next_page = page_1.json().get('next')
self.assertIsNotNone(next_page)
with self.assertNumQueries(9):
with self.assertNumQueries(7):
page_2 = self.client.get(next_page)
self.assertIsNone(page_2.json()['next'])
qs_1 = Element.objects.filter(id__in=[elt['id'] for elt in page_1.json()['results']])
......