Ticket #12746: key.diff

File key.diff, 5.5 KB (added by Martin v. Löwis, 15 years ago)
  • django/forms/formsets.py

     
    191191            # A sort function to order things numerically ascending, but
    192192            # None should be sorted below anything else. Allowing None as
    193193            # a comparison value makes it so we can leave ordering fields
    194             # blamk.
    195             def compare_ordering_values(x, y):
    196                 if x[1] is None:
    197                     return 1
    198                 if y[1] is None:
    199                     return -1
    200                 return x[1] - y[1]
    201             self._ordering.sort(compare_ordering_values)
     194            # blank.
     195            def compare_ordering_key(k):
     196                if k[1] is None:
     197                    return (1, 0) # +infinity, larger than any number
     198                return (0, k[1])
     199            self._ordering.sort(key=compare_ordering_key)
    202200        # Return a list of form.cleaned_data dicts in the order spcified by
    203201        # the form data.
    204202        return [self.forms[i[0]] for i in self._ordering]
  • django/forms/forms.py

     
    3434    Also integrates any additional media definitions
    3535    """
    3636    fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
    37     fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
     37    fields.sort(key=lambda x: x[1].creation_counter)
    3838
    3939    # If this class is subclassing another Form, add that Form's fields.
    4040    # Note that we loop over the bases in *reverse*. This is necessary in
  • django/contrib/admin/options.py

     
    498498
    499499        # Convert the actions into a SortedDict keyed by name
    500500        # and sorted by description.
    501         actions.sort(lambda a,b: cmp(a[2].lower(), b[2].lower()))
     501        actions.sort(key=lambda k: k[2].lower())
    502502        actions = SortedDict([
    503503            (name, (func, name, desc))
    504504            for func, name, desc in actions
  • django/contrib/admin/sites.py

     
    378378
    379379        # Sort the apps alphabetically.
    380380        app_list = app_dict.values()
    381         app_list.sort(lambda x, y: cmp(x['name'], y['name']))
     381        app_list.sort(key=lambda x: x['name'])
    382382
    383383        # Sort the models alphabetically within each app.
    384384        for app in app_list:
    385             app['models'].sort(lambda x, y: cmp(x['name'], y['name']))
     385            app['models'].sort(key=lambda x: x['name'])
    386386
    387387        context = {
    388388            'title': _('Site administration'),
     
    442442        if not app_dict:
    443443            raise http.Http404('The requested admin page does not exist.')
    444444        # Sort the models alphabetically within each app.
    445         app_dict['models'].sort(lambda x, y: cmp(x['name'], y['name']))
     445        app_dict['models'].sort(key=lambda x: x['name'])
    446446        context = {
    447447            'title': _('%s administration') % capfirst(app_label),
    448448            'app_list': [app_dict],
  • django/contrib/databrowse/plugins/calendars.py

     
    6060    def homepage_view(self, request):
    6161        easy_model = EasyModel(self.site, self.model)
    6262        field_list = self.fields.values()
    63         field_list.sort(lambda x, y: cmp(x.verbose_name, y.verbose_name))
     63        field_list.sort(key=lambda k:k.verbose_name)
    6464        return render_to_response('databrowse/calendar_homepage.html', {'root_url': self.site.root_url, 'model': easy_model, 'field_list': field_list})
    6565
    6666    def calendar_view(self, request, field, year=None, month=None, day=None):
  • django/contrib/databrowse/plugins/fieldchoices.py

     
    6161    def homepage_view(self, request):
    6262        easy_model = EasyModel(self.site, self.model)
    6363        field_list = self.fields.values()
    64         field_list.sort(lambda x, y: cmp(x.verbose_name, y.verbose_name))
     64        field_list.sort(key=lambda k: k.verbose_name)
    6565        return render_to_response('databrowse/fieldchoice_homepage.html', {'root_url': self.site.root_url, 'model': easy_model, 'field_list': field_list})
    6666
    6767    def field_view(self, request, field, value=None):
  • django/utils/translation/trans_real.py

     
    507507            return []
    508508        priority = priority and float(priority) or 1.0
    509509        result.append((lang, priority))
    510     result.sort(lambda x, y: -cmp(x[1], y[1]))
     510    result.sort(key=lambda k: k[1], reverse=True)
    511511    return result
    512512
    513513# get_date_formats and get_partial_date_formats aren't used anymore by Django
Back to Top