plone / Products.CMFPlone

The core of the Plone content management system
https://plone.org
GNU General Public License v2.0
246 stars 186 forks source link

addon sorting in prefs_install_products_form #1400

Closed thet closed 2 years ago

thet commented 8 years ago

I cannot identify a pattern how the plugins in prefs_install_products_form are sorted. Should be sorted by title, probably.

hvelarde commented 8 years ago

they are probably not respecting i18n.

thomasmassmann commented 7 years ago

What is the preferred sort key? title or id? If we use title, should it be case sensitive?

Sorting based on id (my favorite, because then its language/i18n independent):

    def get_addons_in_order(self, addons):
        return sorted(addons, key=lambda x: x['id'])

Sorting based on title:

    def get_addons_in_order(self, addons):
        return sorted(addons, key=lambda x: x['title'])

Sorting based on title, case insensitive:

    def get_addons_in_order(self, addons):
        return sorted(addons, key=lambda x: x['title'].lower())

To use it, the method should be called by the view methods:

    def get_upgrades(self):
        """
        Return a list of products that have upgrades on tap
        """
        return self.get_addons_in_order(
            self.get_addons(apply_filter='upgrades').values()
        )

    def get_installed(self):
        return self.get_addons_in_order(
            self.get_addons(apply_filter='installed').values()
        )

    def get_available(self):
        return self.get_addons_in_order(
            self.get_addons(apply_filter='available').values()
        )

    def get_broken(self):
        return self.get_addons_in_order(
            self.get_addons(apply_filter='broken').values()
        )
thet commented 2 years ago

Done in: https://github.com/plone/Products.CMFPlone/pull/3524