Ticket #2740: django-bug2740-patchfor-r7534.patch

File django-bug2740-patchfor-r7534.patch, 4.2 KB (added by kcarnold, 7 years ago)

update of patch for current trunk

  • models/base.py

     
    147147        opts = cls._meta
    148148        opts._prepare(cls)
    149149
    150         if opts.order_with_respect_to:
    151             cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
    152             cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
    153             setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls))
    154             setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls))
    155 
    156150        # Give the class a docstring -- its definition.
    157151        if cls.__doc__ is None:
    158152            cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join([f.attname for f in opts.fields]))
     
    502496            setattr(self, cachename, get_image_dimensions(filename))
    503497        return getattr(self, cachename)
    504498
    505 ############################################
    506 # HELPER FUNCTIONS (CURRIED MODEL METHODS) #
    507 ############################################
    508 
    509 # ORDERING METHODS #########################
    510 
    511 def method_set_order(ordered_obj, self, id_list):
    512     rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name)
    513     order_name = ordered_obj._meta.order_with_respect_to.name
    514     # FIXME: It would be nice if there was an "update many" version of update
    515     # for situations like this.
    516     for i, j in enumerate(id_list):
    517         ordered_obj.objects.filter(**{'pk': j, order_name: rel_val}).update(_order=i)
    518     transaction.commit_unless_managed()
    519 
    520 def method_get_order(ordered_obj, self):
    521     rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name)
    522     order_name = ordered_obj._meta.order_with_respect_to.name
    523     pk_name = ordered_obj._meta.pk.name
    524     return [r[pk_name] for r in
    525             ordered_obj.objects.filter(**{order_name: rel_val}).values(pk_name)]
    526 
    527499##############################################
    528500# HELPER FUNCTIONS (CURRIED MODEL FUNCTIONS) #
    529501##############################################
  • models/fields/related.py

     
    121121        related = RelatedObject(other, cls, self)
    122122        self.contribute_to_related_class(other, related)
    123123
     124        opts = other._meta
     125        if opts.order_with_respect_to:
     126            cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
     127            cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
     128            setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls))
     129            setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls))
     130
     131
    124132    def get_db_prep_lookup(self, lookup_type, value):
    125133        # If we are doing a lookup on a Related Field, we must be
    126134        # comparing object instances. The value should be the PK of value,
     
    833841        # so return None.
    834842        return None
    835843
     844
     845############################################
     846# HELPER FUNCTIONS (CURRIED MODEL METHODS) #
     847############################################
     848
     849# ORDERING METHODS #########################
     850
     851def method_set_order(ordered_obj, self, id_list):
     852    rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name)
     853    order_name = ordered_obj._meta.order_with_respect_to.name
     854    # FIXME: It would be nice if there was an "update many" version of update
     855    # for situations like this.
     856    for i, j in enumerate(id_list):
     857        ordered_obj.objects.filter(**{'pk': j, order_name: rel_val}).update(_order=i)
     858    transaction.commit_unless_managed()
     859
     860def method_get_order(ordered_obj, self):
     861    rel_val = getattr(self, ordered_obj._meta.order_with_respect_to.rel.field_name)
     862    order_name = ordered_obj._meta.order_with_respect_to.name
     863    pk_name = ordered_obj._meta.pk.name
     864    return [r[pk_name] for r in
     865            ordered_obj.objects.filter(**{order_name: rel_val}).values(pk_name)]
     866
Back to Top