misc: sort categories using key function (#36515)
This commit is contained in:
parent
a0b301d755
commit
e0736bb329
|
@ -66,21 +66,8 @@ class Category(XmlStorableObject):
|
|||
|
||||
@classmethod
|
||||
def sort_by_position(cls, categories):
|
||||
def cmp_position(x, y):
|
||||
if x is None and y is None:
|
||||
return 0
|
||||
if y is None:
|
||||
return -1
|
||||
if x is None:
|
||||
return 1
|
||||
if x.position == y.position:
|
||||
return 0
|
||||
if x.position is None:
|
||||
return 1
|
||||
if y.position is None:
|
||||
return -1
|
||||
return cmp(x.position, y.position)
|
||||
categories.sort(cmp_position)
|
||||
# move categories with no defined position to the end
|
||||
categories.sort(key=lambda x: x.position if x and x.position is not None else 10000)
|
||||
|
||||
def remove_self(self):
|
||||
from .formdef import FormDef
|
||||
|
|
Loading…
Reference in New Issue