diff --git a/sahara_dashboard/content/data_processing/clusters/image_registry/views.py b/sahara_dashboard/content/data_processing/clusters/image_registry/views.py index 6431eb77..8e604668 100644 --- a/sahara_dashboard/content/data_processing/clusters/image_registry/views.py +++ b/sahara_dashboard/content/data_processing/clusters/image_registry/views.py @@ -26,6 +26,7 @@ from sahara_dashboard.content. \ data_processing.clusters.image_registry.forms import EditTagsForm from sahara_dashboard.content. \ data_processing.clusters.image_registry.forms import RegisterImageForm +from sahara_dashboard import utils def update_context_with_plugin_tags(request, context): @@ -39,7 +40,8 @@ def update_context_with_plugin_tags(request, context): plugins_object = dict() for plugin in plugins: plugins_object[plugin.name] = OrderedDict() - for version in sorted(plugin.versions, reverse=True): + for version in sorted(plugin.versions, reverse=True, + key=utils.smart_sort_helper): try: details = saharaclient. \ plugin_get_version_details(request, diff --git a/sahara_dashboard/content/data_processing/clusters/wizard/forms.py b/sahara_dashboard/content/data_processing/clusters/wizard/forms.py index dc91a498..0bf32297 100644 --- a/sahara_dashboard/content/data_processing/clusters/wizard/forms.py +++ b/sahara_dashboard/content/data_processing/clusters/wizard/forms.py @@ -23,6 +23,7 @@ from horizon import messages from sahara_dashboard.api import sahara as saharaclient from sahara_dashboard.content.data_processing.utils \ import helpers +from sahara_dashboard import utils class ChoosePluginForm(forms.SelfHandlingForm): @@ -60,8 +61,10 @@ class ChoosePluginForm(forms.SelfHandlingForm): for plugin in plugins: field_name = plugin.name + "_version" - version_choices = (sorted([(version, version) - for version in plugin.versions], reverse=True)) + version_choices = (sorted( + [(version, version) for version in plugin.versions], + reverse=True, key=lambda v: utils.smart_sort_helper(v[0])) + ) choice_field = forms.ChoiceField( label=_("Version"), required=False, diff --git a/sahara_dashboard/content/data_processing/utils/workflow_helpers.py b/sahara_dashboard/content/data_processing/utils/workflow_helpers.py index 81e464ed..cfcf2e2a 100644 --- a/sahara_dashboard/content/data_processing/utils/workflow_helpers.py +++ b/sahara_dashboard/content/data_processing/utils/workflow_helpers.py @@ -24,7 +24,7 @@ from horizon import workflows from openstack_dashboard.api import neutron from sahara_dashboard.api import sahara as saharaclient - +from sahara_dashboard import utils LOG = logging.getLogger(__name__) @@ -261,9 +261,12 @@ class PluginAndVersionMixin(object): 'data-slug': 'pluginname'})) for plugin in plugins: - version_choices = (sorted( - [(version, version) - for version in get_enabled_versions(plugin)], reverse=True)) + versions = [(version, version) + for version in get_enabled_versions(plugin)] + version_choices = sorted( + versions, + reverse=True, + key=lambda v: utils.smart_sort_helper(v[0])) field_name = plugin.name + "_version" choice_field = forms.ChoiceField( label=_("Version"), diff --git a/sahara_dashboard/utils.py b/sahara_dashboard/utils.py index c0fc1a16..6eb180f8 100644 --- a/sahara_dashboard/utils.py +++ b/sahara_dashboard/utils.py @@ -69,3 +69,16 @@ def delete_pagination_params_from_request(request, save_limit=None): query_string = parse.urlencode(query_dict, doseq=True) request.META['QUERY_STRING'] = query_string return request + + +def smart_sort_helper(version): + """Allows intelligent sorting of plugin versions, for example when + minor version of a plugin is 11, sort numerically so that 11 > 10, + instead of alphabetically so that 2 > 11 + """ + def _safe_cast_to_int(obj): + try: + return int(obj) + except ValueError: + return obj + return [_safe_cast_to_int(part) for part in version.split('.')]