2012-02-04 159 views
-1

經過很多小時的拔毛之後,我期待着使用stackoverflow來幫助我解決這個問題。Django信號之謎...開發服務器與遠程服務器

我已經創建了兩個信號來運行自動電子郵件功能。這些信號通過在我的admin.py文件中修改save_model來觸發。

唯一的問題是......通過Django開發服務器(發送自動電子郵件)運行時,兩個信號都會工作,但在遠程服務器上測試時只有一個信號有效。我不明白這是如何可能的,我一直無法找到錯誤。

我知道這裏沒有太多的信息可以使用。有什麼可能在這裏發生的建議?

至於文件/目錄結構,這些信號保存在位於該特定應用程序目錄下的signals.py文件中。該信號通過修改我的admin.py文件中的save_model定義觸發,位於同一目錄中。

這裏有信號的定義:

notify_status_change_signal = Signal(providing_args=['status', 'restaurant', 'delivery_date', 'contact_email', 'contact_phone']) 
notify_on_change_signal = Signal(providing_args=['organization', 'identifier', 'id', 'restaurant', 'delivery_date']) 

@receiver(notify_on_change_signal) 
def notify_on_change(sender, organization, identifier, id, restaurant, delivery_date, signal, *args, **kwargs): 
    "This is the signal that only functions when run through the local development server" 
    order_id = identifier + str(id) 
    subject = r'A change has been made to order %s' % order_id 
    body = """ 
    System Message: The details for order %s (%s) have been updated by the client.""" % (order_id, organization) 

    send_mail(subject, body, 'System Notification <[email protected]>', [admin_email], fail_silently=False)  


@receiver(notify_status_change_signal) 
def notify_status_change(sender, status, restaurant, delivery_date, contact_email, contact_phone, signal, *args, **kwargs): 
    """This is the signal that works on both servers""" 
    stat_body = { 
    'Confirmed':""" 

Message 1 """, 

    'Placed': """ 

Message 2 """, 

    'En Route': """ 

Message 3 """, 

    'Completed':""" 

Message 4 """, 
    } 

    #Auto email 
    from_addr = 'Order Status <[email protected]>' 
    to_addrs = [contact_email] 
    subject = u'Order %s %s status changed to %s.' % (restaurant, delivery_date, status) 
    body = '' 
    for stat_label, description in stat_body.iteritems(): 
     if status == stat_label: body = description 

    if status == "Confirmed" or status == "En Route" or status == "Completed":  
     send_mail(subject, body, from_addr, to_addrs, fail_silently=False) 

    #Auto text message 
    if status == 'En Route': 
     client = TwilioRestClient(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN) 
     message = client.sms.messages.create(to=contact_phone, 
            from_="5555555555", 
            body="Your order, %s %s, is now en route." % (restaurant, delivery_date)) 
+0

有一點點代碼,也許? – Jingo 2012-02-04 01:23:17

+4

你可以發佈你的信號定義,以及你的文件/目錄結構嗎?這可能與測試服務器設置Python路徑的方式有所不同。 – 2012-02-04 02:42:43

+0

你在哪裏連接信號? – 2012-02-04 19:35:43

回答

0

雖然我絕對重新啓動服務器時我更新了這些信號的代碼,重新啓動服務器再次奏效了。