Ticket #5422: save-send-raw-flag_v2.diff

File save-send-raw-flag_v2.diff, 1.8 KB (added by graham.carlyle@…, 17 years ago)

Updated patch against trunk and updated corresponding tests

  • django/db/models/base.py

     
    207207    _prepare = classmethod(_prepare)
    208208
    209209    def save(self, raw=False):
    210         dispatcher.send(signal=signals.pre_save, sender=self.__class__, instance=self)
     210        dispatcher.send(signal=signals.pre_save, sender=self.__class__, instance=self, raw=raw)
    211211
    212212        non_pks = [f for f in self._meta.fields if not f.primary_key]
    213213        cursor = connection.cursor()
     
    268268
    269269        # Run any post-save hooks.
    270270        dispatcher.send(signal=signals.post_save, sender=self.__class__,
    271                 instance=self, created=(not record_exists))
     271                instance=self, created=(not record_exists), raw=raw)
    272272
    273273    save.alters_data = True
    274274
  • tests/modeltests/signals/models.py

     
    1515
    1616def pre_save_test(sender, instance, **kwargs):
    1717    print 'pre_save signal,', instance
     18    if kwargs['raw']:
     19        print 'Is raw'
    1820
    1921def post_save_test(sender, instance, **kwargs):
    2022    print 'post_save signal,', instance
     
    2325            print 'Is created'
    2426        else:
    2527            print 'Is updated'
     28    if kwargs['raw']:
     29        print 'Is raw'
    2630
    2731def pre_delete_test(sender, instance, **kwargs):
    2832    print 'pre_delete signal,', instance
     
    5054post_save signal, Tom Smith
    5155Is updated
    5256
     57>>> p1.save(raw=True)
     58pre_save signal, Tom Smith
     59Is raw
     60post_save signal, Tom Smith
     61Is updated
     62Is raw
     63
    5364>>> p1.delete()
    5465pre_delete signal, Tom Smith
    5566instance.id is not None: True
Back to Top