Fix plugin version sorting
Default sorting is not good enough, since it alphabetically sorts
numbers, as in 11 < 2 instead of 11 > 10.
Change-Id: Iaa575cf4ba0fe76524ba2823ce50de30a5b931d9
Closes-Bug: #1707204
(cherry picked from commit ffe4371710
)
This commit is contained in:
parent
7394ec6183
commit
26b0483435
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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('.')]
|
||||
|
|
Loading…
Reference in New Issue