From a76fa88e943abc85ce84d157babf2c2bbe2dc2d7 Mon Sep 17 00:00:00 2001 From: Manuel Reinhardt Date: Tue, 14 Jan 2025 10:34:43 +0100 Subject: [PATCH 1/2] Mailing lists: Sort language-specific entries Stable sorting is necessary to make batching work reliably. Ref https://github.com/syslabcom/scrum/issues/2316 --- src/osha/oira/client/browser/client.py | 2 +- src/osha/oira/client/tests/test_mailing_lists.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/osha/oira/client/browser/client.py b/src/osha/oira/client/browser/client.py index 5872c631..0387fefd 100644 --- a/src/osha/oira/client/browser/client.py +++ b/src/osha/oira/client/browser/client.py @@ -139,7 +139,7 @@ def _get_mailing_lists_for(self, brain): self._get_entry( "-".join((brain.getId, language)), f"{brain.Title} ({language})" ) - for language in languages + for language in sorted(languages) ] def filter_permission(self, brains, query, user): diff --git a/src/osha/oira/client/tests/test_mailing_lists.py b/src/osha/oira/client/tests/test_mailing_lists.py index c5658cba..b1f567e5 100644 --- a/src/osha/oira/client/tests/test_mailing_lists.py +++ b/src/osha/oira/client/tests/test_mailing_lists.py @@ -111,15 +111,15 @@ def test_mailing_lists_batching(self): self.assertEqual( results[0], { - "id": "nl-nl|VGhlIE5ldGhlcmxhbmRzIChubCk=", - "text": "The Netherlands (nl) [0 subscribers]", + "id": "nl-fr|VGhlIE5ldGhlcmxhbmRzIChmcik=", + "text": "The Netherlands (fr) [0 subscribers]", }, ) self.assertEqual( results[1], { - "id": "nl-fr|VGhlIE5ldGhlcmxhbmRzIChmcik=", - "text": "The Netherlands (fr) [0 subscribers]", + "id": "nl-nl|VGhlIE5ldGhlcmxhbmRzIChubCk=", + "text": "The Netherlands (nl) [0 subscribers]", }, ) From 63f495cc9585f3612b75bbddd2842c91ee8a5031 Mon Sep 17 00:00:00 2001 From: Manuel Reinhardt Date: Tue, 14 Jan 2025 10:54:25 +0100 Subject: [PATCH 2/2] Mailing lists: Sort on path in addition to title There are multiple tools with the same title in different countries, e.g. "Agriculture". For batching we need to make sure they are always sorted in the same way. Ref https://github.com/syslabcom/scrum/issues/2316 --- src/osha/oira/client/browser/client.py | 2 +- src/osha/oira/client/tests/test_mailing_lists.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/osha/oira/client/browser/client.py b/src/osha/oira/client/browser/client.py index 0387fefd..d99cb4e7 100644 --- a/src/osha/oira/client/browser/client.py +++ b/src/osha/oira/client/browser/client.py @@ -197,7 +197,7 @@ def results(self): query = { "portal_type": ["euphorie.clientcountry", "euphorie.survey"], "path": "/".join(self.context.getPhysicalPath()), - "sort_on": "sortable_title", + "sort_on": ("sortable_title", "path"), } # Filter for query string if given. Else return all results. diff --git a/src/osha/oira/client/tests/test_mailing_lists.py b/src/osha/oira/client/tests/test_mailing_lists.py index b1f567e5..2ef2419c 100644 --- a/src/osha/oira/client/tests/test_mailing_lists.py +++ b/src/osha/oira/client/tests/test_mailing_lists.py @@ -19,7 +19,7 @@ def setUp(self): survey = """ Test - Second Survey + Software development fr """ @@ -86,15 +86,15 @@ def test_mailing_lists_batching(self): self.assertEqual( results[1], { - "id": "nl/test/second-survey|U2Vjb25kIFN1cnZleQ==", - "text": "Second Survey (nl/test/second-survey) [0 subscribers]", + "id": "nl/ict/software-development|U29mdHdhcmUgZGV2ZWxvcG1lbnQ=", + "text": "Software development (nl/ict/software-development) [0 subscribers]", # noqa: E501 }, ) self.assertEqual( results[2], { - "id": "nl/ict/software-development|U29mdHdhcmUgZGV2ZWxvcG1lbnQ=", - "text": "Software development (nl/ict/software-development) [0 subscribers]", # noqa: E501 + "id": "nl/test/software-development|U29mdHdhcmUgZGV2ZWxvcG1lbnQ=", + "text": "Software development (nl/test/software-development) [0 subscribers]", # noqa: E501 }, )