python3: sort version using key function
This commit is contained in:
parent
930f110872
commit
0e92ea921d
|
@ -183,9 +183,9 @@ def try_int(x):
|
|||
|
||||
version_re = re.compile(r'[\.\+-]d?e?v?')
|
||||
|
||||
def cmp_version(v1, v2):
|
||||
return cmp([try_int(x) for x in version_re.split(v1.version.version)],
|
||||
[try_int(x) for x in version_re.split(v2.version.version)])
|
||||
|
||||
def key_version(v1):
|
||||
return [try_int(x) for x in version_re.split(v1.version.version)]
|
||||
|
||||
|
||||
class ModuleDeploymentsView(TemplateView):
|
||||
|
@ -202,7 +202,7 @@ class ModuleDeploymentsView(TemplateView):
|
|||
if version.version.version:
|
||||
context['versions'].append(version)
|
||||
|
||||
context['versions'].sort(lambda x, y: cmp_version(x, y))
|
||||
context['versions'].sort(key=key_version)
|
||||
return context
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue