From 1da1ca939a2f23b299b74fff91e0477aaeb5f961 Mon Sep 17 00:00:00 2001 From: Rohan Shaw Date: Wed, 17 Jul 2024 16:39:44 +0530 Subject: [PATCH 1/8] Implemented pyICU for sorting of ReallyUserFriendlyTypes --- news/3985.chore | 2 ++ plone/app/vocabularies/types.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 news/3985.chore diff --git a/news/3985.chore b/news/3985.chore new file mode 100644 index 0000000..fda49c1 --- /dev/null +++ b/news/3985.chore @@ -0,0 +1,2 @@ +Implemented pyICU for sorting of ReallyUserFriendlyTypes +[rohnsha0] \ No newline at end of file diff --git a/plone/app/vocabularies/types.py b/plone/app/vocabularies/types.py index 73f2d8e..cac9cea 100644 --- a/plone/app/vocabularies/types.py +++ b/plone/app/vocabularies/types.py @@ -8,6 +8,8 @@ from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleTerm from zope.schema.vocabulary import SimpleVocabulary +from icu import Collator, Locale + def getAllowedContentTypes(context): @@ -290,15 +292,25 @@ def __call__(self, context): site = getSite() ttool = getToolByName(site, "portal_types", None) if ttool is None: - return SimpleVocabulary([]) + return PermissiveVocabulary([]) request = aq_get(ttool, "REQUEST", None) + + # Get the current language from the request + language = request.get('LANGUAGE', 'en') + + # Create an ICU Collator for the current language + collator = Collator.createInstance(Locale(language)) + items = [ (translate(ttool[t].Title(), context=request), t) for t in ttool.listContentTypes() if t not in BAD_TYPES ] - items.sort() + + # Sort items using the ICU Collator + items.sort(key=lambda x: collator.getSortKey(x[0])) + items = [SimpleTerm(i[1], i[1], i[0]) for i in items] return PermissiveVocabulary(items) From d3f4fce04e4e9c01c8b371f0d6cb160a87ec536f Mon Sep 17 00:00:00 2001 From: Rohan Shaw Date: Tue, 23 Jul 2024 20:33:38 +0530 Subject: [PATCH 2/8] Sort ReallyUserFriendlyTypesVocabulary by translated title using unidecode --- plone/app/vocabularies/types.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/plone/app/vocabularies/types.py b/plone/app/vocabularies/types.py index cac9cea..81bf1f8 100644 --- a/plone/app/vocabularies/types.py +++ b/plone/app/vocabularies/types.py @@ -8,8 +8,7 @@ from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleTerm from zope.schema.vocabulary import SimpleVocabulary -from icu import Collator, Locale - +from unidecode import unidecode def getAllowedContentTypes(context): @@ -292,27 +291,21 @@ def __call__(self, context): site = getSite() ttool = getToolByName(site, "portal_types", None) if ttool is None: - return PermissiveVocabulary([]) + return SimpleVocabulary([]) request = aq_get(ttool, "REQUEST", None) - - # Get the current language from the request - language = request.get('LANGUAGE', 'en') - - # Create an ICU Collator for the current language - collator = Collator.createInstance(Locale(language)) - items = [ (translate(ttool[t].Title(), context=request), t) for t in ttool.listContentTypes() if t not in BAD_TYPES ] - # Sort items using the ICU Collator - items.sort(key=lambda x: collator.getSortKey(x[0])) + print(items) + # Sort items based on the translated title using unidecode + items.sort(key=lambda x: unidecode(x[0]).lower()) - items = [SimpleTerm(i[1], i[1], i[0]) for i in items] - return PermissiveVocabulary(items) + terms = [SimpleTerm(i[1], i[1], i[0]) for i in items] + return PermissiveVocabulary(terms) -ReallyUserFriendlyTypesVocabularyFactory = ReallyUserFriendlyTypesVocabulary() +ReallyUserFriendlyTypesVocabularyFactory = ReallyUserFriendlyTypesVocabulary() \ No newline at end of file From d65f0f2b10bda3475e1c3aca82be970f1a793798 Mon Sep 17 00:00:00 2001 From: Rohan Shaw Date: Tue, 23 Jul 2024 20:51:39 +0530 Subject: [PATCH 3/8] removed print statement --- plone/app/vocabularies/types.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plone/app/vocabularies/types.py b/plone/app/vocabularies/types.py index 81bf1f8..e294ddf 100644 --- a/plone/app/vocabularies/types.py +++ b/plone/app/vocabularies/types.py @@ -299,8 +299,7 @@ def __call__(self, context): for t in ttool.listContentTypes() if t not in BAD_TYPES ] - - print(items) + # Sort items based on the translated title using unidecode items.sort(key=lambda x: unidecode(x[0]).lower()) From 430dae4506e43f11eaf1e6d9f73a1f7f71e61e6d Mon Sep 17 00:00:00 2001 From: Rohan Shaw Date: Tue, 23 Jul 2024 21:00:52 +0530 Subject: [PATCH 4/8] add "unidecode" dependency to setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 613c086..105c88a 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,7 @@ # by many many other packages in plone.app.* namespace # it is very easy to add transitive circular dependencies "BTrees", + "unidecode", "Products.ZCatalog", "plone.base", "plone.memoize", From 771b2937da3880d6c4dbc5479128c4f246fa6b49 Mon Sep 17 00:00:00 2001 From: Rohan Shaw Date: Tue, 23 Jul 2024 21:06:06 +0530 Subject: [PATCH 5/8] Update setup.py with "unidecode" dependency --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 105c88a..b479aee 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,6 @@ # by many many other packages in plone.app.* namespace # it is very easy to add transitive circular dependencies "BTrees", - "unidecode", "Products.ZCatalog", "plone.base", "plone.memoize", @@ -56,6 +55,7 @@ "plone.uuid", "pytz", "setuptools", + "unidecode", "z3c.formwidget.query", "zope.browser", "zope.globalrequest", From 4087ba8564d2147615264e4427016c7f9221ddb9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 15:42:20 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plone/app/vocabularies/types.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plone/app/vocabularies/types.py b/plone/app/vocabularies/types.py index e294ddf..a921e9c 100644 --- a/plone/app/vocabularies/types.py +++ b/plone/app/vocabularies/types.py @@ -1,6 +1,7 @@ from Acquisition import aq_get from plone.app.vocabularies import PermissiveVocabulary from Products.CMFCore.utils import getToolByName +from unidecode import unidecode from zope.component.hooks import getSite from zope.deprecation import deprecate from zope.i18n import translate @@ -8,7 +9,6 @@ from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleTerm from zope.schema.vocabulary import SimpleVocabulary -from unidecode import unidecode def getAllowedContentTypes(context): @@ -299,12 +299,12 @@ def __call__(self, context): for t in ttool.listContentTypes() if t not in BAD_TYPES ] - + # Sort items based on the translated title using unidecode items.sort(key=lambda x: unidecode(x[0]).lower()) - + terms = [SimpleTerm(i[1], i[1], i[0]) for i in items] return PermissiveVocabulary(terms) -ReallyUserFriendlyTypesVocabularyFactory = ReallyUserFriendlyTypesVocabulary() \ No newline at end of file +ReallyUserFriendlyTypesVocabularyFactory = ReallyUserFriendlyTypesVocabulary() From a82224d18a91a0c3c5ec4a01a5ffac0b2efca505 Mon Sep 17 00:00:00 2001 From: Rohan Shaw Date: Tue, 23 Jul 2024 21:25:38 +0530 Subject: [PATCH 7/8] updates news comment --- news/3985.chore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/3985.chore b/news/3985.chore index fda49c1..f846ca0 100644 --- a/news/3985.chore +++ b/news/3985.chore @@ -1,2 +1,2 @@ -Implemented pyICU for sorting of ReallyUserFriendlyTypes +Implemented sorting of ReallyUserFriendlyTypes using `unidecode` [rohnsha0] \ No newline at end of file From 82bb290e95935de5b1b4434acf539a79bf9f21b4 Mon Sep 17 00:00:00 2001 From: Rohan Shaw Date: Tue, 23 Jul 2024 21:42:54 +0530 Subject: [PATCH 8/8] added period in news --- news/3985.chore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/3985.chore b/news/3985.chore index f846ca0..84968a3 100644 --- a/news/3985.chore +++ b/news/3985.chore @@ -1,2 +1,2 @@ -Implemented sorting of ReallyUserFriendlyTypes using `unidecode` +Implemented sorting of ReallyUserFriendlyTypes using `unidecode`. [rohnsha0] \ No newline at end of file