2012-04-07 60 views
0

我有發送模型信號:django的信號

class WMTransaction(models.Model): 
    def save(self, *args, **kwargs): 
     if self.status == 'completed': 
      self.completed = datetime.datetime.now() 
      try: 
       old = WMTransaction.objects.get(pk=self.pk) 
       if old.status == 'processing': 
        print 'sending signal' 
        payment_done.send(self) 
      except: 
       pass 
     super(WMTransaction, self).save(*args, **kwargs) 

另外我有在2個模塊的接收器:

@receiver(payment_done, dispatch_uid="make_this_signal_unique", weak=False) 
def subscribe(sender, **kwargs): 
    print 'subscribing' 
    # processing 

和:

@receiver(payment_done, dispatch_uid="this_signal_is_also_unique", weak=False) 
def buy(sender, **kwargs): 
    print 'buying' 
    # processing 

的問題是訂閱函數被調用,而購買 - 不是...兩個模塊都在安裝的應用程序中,這些模塊的其他功能正常工作。信號有什麼問題?

+0

這兩個信號處理程序在'models.py'或導入到'models.py'? – 2012-04-07 18:29:00

+0

**訂閱**是在module_A.models和** buy **是在module_B.models – 2012-04-07 18:40:39

+0

非常不可能,但嘗試添加一些日誌信息到except塊,如果沒有拋出一些異常 – yedpodtrzitko 2012-04-07 19:09:28

回答

1

是否已安裝module_B並且buy的定義實際得到執行?在payment_done.send行之前檢查payment_done.receivers

+0

是的,看起來這個定義沒有執行:payment_done.receivers打印'[( ('make_this_signal_unique',139659700131376),)]。但爲什麼?在該文件中定義的類正常工作。 – 2012-04-08 12:49:06

+0

@ ookami.kb好吧,'buy'定義後payment_done的狀態如何?之後有沒有斷開連接? – okm 2012-04-08 13:53:09

+0

順便說一句,你用什麼Python和env? – okm 2012-04-08 14:04:37