2012-02-04 2 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

+4

신호 정의 및 파일/디렉토리 구조를 게시 할 수 있습니까? 테스트 서버가 파이썬 경로를 설정하는 방법과 차이가있을 수 있습니다. –

+0

어디에서 신호를 연결하고 있습니까? –

답변

0

I 서버가 다시 속임수를 썼는지 다시 시작,이 신호와 코드를 업데이트 할 때 나는 확실히 서버를 다시 시작했지만.