Ticket #8077: signals_patch3.diff
File signals_patch3.diff, 2.7 KB (added by , 16 years ago) |
---|
-
django/db/models/base.py
192 192 __metaclass__ = ModelBase 193 193 194 194 def __init__(self, *args, **kwargs): 195 signals.pre_init.send(sender=self.__class__, args=args, kwargs=kwargs) 195 if send_signals: 196 signals.pre_init.send(sender=self.__class__, args=args, kwargs=kwargs) 196 197 197 198 # There is a rather weird disparity here; if kwargs, it's set, then args 198 199 # overrides it. It should be one or the other; don't duplicate the work … … 263 264 pass 264 265 if kwargs: 265 266 raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0] 266 signals.post_init.send(sender=self.__class__, instance=self) 267 if send_signals: 268 signals.post_init.send(sender=self.__class__, instance=self) 267 269 268 270 def __repr__(self): 269 271 return smart_str(u'<%s: %s>' % (self.__class__.__name__, unicode(self))) … … 292 294 293 295 pk = property(_get_pk_val, _set_pk_val) 294 296 295 def save(self, force_insert=False, force_update=False):297 def save(self, send_signals=True, force_insert=False, force_update=False): 296 298 """ 297 299 Saves the current instance. Override this in a subclass if you want to 298 300 control the saving process. … … 304 306 if force_insert and force_update: 305 307 raise ValueError("Cannot force both insert and updating in " 306 308 "model saving.") 307 self.save_base( force_insert=force_insert, force_update=force_update)309 self.save_base(send_signals=send_signals, force_insert=force_insert, force_update=force_update) 308 310 309 311 save.alters_data = True 310 312 311 def save_base(self, raw=False, cls=None, force_insert=False,313 def save_base(self, send_signals=True, raw=False, cls=None, force_insert=False, 312 314 force_update=False): 313 315 """ 314 316 Does the heavy-lifting involved in saving. Subclasses shouldn't need to … … 321 323 cls = self.__class__ 322 324 meta = self._meta 323 325 signal = True 324 signals.pre_save.send(sender=self.__class__, instance=self, raw=raw) 326 if send_signals: 327 signals.pre_save.send(sender=self.__class__, instance=self, raw=raw) 325 328 else: 326 329 meta = cls._meta 327 330 signal = False … … 385 388 setattr(self, meta.pk.attname, result) 386 389 transaction.commit_unless_managed() 387 390 388 if signal :391 if signal and send_signals: 389 392 signals.post_save.send(sender=self.__class__, instance=self, 390 393 created=(not record_exists), raw=raw) 391 394