python3: always sort using key

This commit is contained in:
Frédéric Péters 2018-03-25 16:14:52 +02:00
parent ef474d3ade
commit 594206130e
4 changed files with 5 additions and 5 deletions

View File

@ -84,7 +84,7 @@ class MomoIconCell(CellBase):
def get_default_form_class(self):
sorted_icons = self._meta.get_field('icon').choices
sorted_icons.sort(lambda x, y: cmp(x[1], y[1]))
sorted_icons.sort(key=lambda x: x[1])
return model_forms.modelform_factory(self.__class__,
fields=['icon', 'style', 'description', 'embed_page'],
widgets={'icon': Select(choices=sorted_icons)})

View File

@ -51,5 +51,5 @@ def get_wcs_options(url, include_category_slug=False):
else:
reference = '%s:%s' % (wcs_key, slug)
references.append((reference, label))
references.sort(lambda x, y: cmp(x[1], y[1]))
references.sort(key=lambda x: x[1])
return references

View File

@ -561,7 +561,7 @@ class CellBase(models.Model):
if cell_filter and not cell_filter(klass):
continue
cells.extend(klass.objects.filter(**kwargs))
cells.sort(lambda x, y: cmp(x.order, y.order))
cells.sort(key=lambda x: x.order)
return cells
def get_reference(self):
@ -1243,7 +1243,7 @@ class ConfigJsonCell(JsonCellBase):
'group': _('Extra'),
'cell_type_str': cls.get_cell_type_str(),
})
l.sort(lambda x, y: cmp(x.get('name'), y.get('name')))
l.sort(key=lambda x: x.get('name'))
return l
def get_label(self):

View File

@ -69,7 +69,7 @@ class PageSelectTemplateForm(forms.ModelForm):
super(PageSelectTemplateForm, self).__init__(*args, **kwargs)
templates = [(x[0], x[1]['name']) for x in settings.COMBO_PUBLIC_TEMPLATES.items()]
templates = [x for x in templates if self.template_exists(x[0])]
templates.sort(lambda x, y: cmp(x[1], y[1]))
templates.sort(key=lambda x: x[1])
if 'template_name' in self.fields:
self.fields['template_name'].widget = forms.Select(choices=templates)