Ticket #8077: send_signals_false_patch_correct.diff
File send_signals_false_patch_correct.diff, 3.3 KB (added by , 16 years ago) |
---|
-
django/db/models/base.py
167 167 class Model(object): 168 168 __metaclass__ = ModelBase 169 169 170 def __init__(self, *args, **kwargs): 171 dispatcher.send(signal=signals.pre_init, sender=self.__class__, args=args, kwargs=kwargs) 170 def __init__(self, send_signals=True, *args, **kwargs): 171 172 #Test to see if signals are disabled for this action (send_signals=False). If not, go about as usual. 173 if send_signals: 174 dispatcher.send(signal=signals.pre_init, sender=self.__class__, args=args, kwargs=kwargs) 172 175 173 176 # There is a rather weird disparity here; if kwargs, it's set, then args 174 177 # overrides it. It should be one or the other; don't duplicate the work … … 239 242 pass 240 243 if kwargs: 241 244 raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0] 242 dispatcher.send(signal=signals.post_init, sender=self.__class__, instance=self) 245 #Test to see if signals are disabled for this action (send_signals=False). If not, go about as usual. 246 if send_signals: 247 dispatcher.send(signal=signals.post_init, sender=self.__class__, instance=self) 243 248 244 249 def __repr__(self): 245 250 return smart_str(u'<%s: %s>' % (self.__class__.__name__, unicode(self))) … … 268 273 269 274 pk = property(_get_pk_val, _set_pk_val) 270 275 271 def save(self ):276 def save(self, send_signals=True): 272 277 """ 273 278 Saves the current instance. Override this in a subclass if you want to 274 279 control the saving process. 275 280 """ 276 self.save_base() 281 #Test to see if signals are disabled for this action (send_signals=False). If not, go about as usual. 282 if send_signals: 283 self.save_base() 284 else: 285 self.save_base(send_signals=False) 277 286 278 287 save.alters_data = True 279 288 280 def save_base(self, raw=False, cls=None ):289 def save_base(self, raw=False, cls=None, send_signals=True): 281 290 """ 282 291 Does the heavy-lifting involved in saving. Subclasses shouldn't need to 283 292 override this method. It's separate from save() in order to hide the … … 288 297 cls = self.__class__ 289 298 meta = self._meta 290 299 signal = True 291 dispatcher.send(signal=signals.pre_save, sender=self.__class__, 292 instance=self, raw=raw) 300 #Test to see if signals are disabled for this action (send_signals=False). If not, go about as usual. 301 if send_signals: 302 dispatcher.send(signal=signals.pre_save, sender=self.__class__, 303 instance=self, raw=raw) 293 304 else: 294 305 meta = cls._meta 295 306 signal = False … … 351 362 transaction.commit_unless_managed() 352 363 353 364 if signal: 354 dispatcher.send(signal=signals.post_save, sender=self.__class__, 365 #Test to see if signals are disabled for this action (send_signals=False). If not, go about as usual. 366 if send_signals: 367 dispatcher.send(signal=signals.post_save, sender=self.__class__, 355 368 instance=self, created=(not record_exists), raw=raw) 356 369 357 370 save_base.alters_data = True