<s> from django . http import HttpResponse <EOL> __author__ = '<STR_LIT>' <EOL> from twilio import twiml <EOL> from django . contrib . auth . models import User <EOL> from openduty . models import Incident <EOL> from notification . models import ScheduledNotification <EOL> from openduty . incidents import _update_type <EOL> from django_twilio . decorators import twilio_view <EOL> @ twilio_view <EOL> def read_notification ( request , id , user_id ) : <EOL> resp = twiml . Response ( ) <EOL> try : <EOL> notification = ScheduledNotification . objects . get ( id = id ) <EOL> user = User . objects . get ( id = user_id ) <EOL> resp . say ( "<STR_LIT>" % user . username ) <EOL> resp . say ( notification . message ) <EOL> with resp . gather ( numDigits = <NUM_LIT:1> , action = "<STR_LIT>" % ( id , user_id ) , method = "<STR_LIT:GET>" ) as g : <EOL> g . say ( "<STR_LIT>" ) <EOL> g . say ( "<STR_LIT>" ) <EOL> g . say ( "<STR_LIT>" ) <EOL> except ScheduledNotification . DoesNotExist : <EOL> resp . say ( "<STR_LIT>" ) <EOL> except User . DoesNotExist : <EOL> resp . say ( "<STR_LIT>" ) <EOL> return resp <EOL> @ twilio_view <EOL> def handle_key ( request , id , user_id ) : <EOL> """<STR_LIT>""" <EOL> digit_pressed = request . GET . get ( '<STR_LIT>' , None ) <EOL> resp = twiml . Response ( ) <EOL> try : <EOL> notification = ScheduledNotification . objects . get ( id = id ) <EOL> user = User . objects . get ( id = user_id ) <EOL> if digit_pressed == "<STR_LIT:1>" : <EOL> resp . say ( "<STR_LIT>" ) <EOL> _update_type ( user , [ notification . incident . id ] , Incident . ACKNOWLEDGE ) <EOL> if digit_pressed == "<STR_LIT:2>" : <EOL> resp . say ( "<STR_LIT>" ) <EOL> _update_type ( user , [ notification . incident . id ] , Incident . RESOLVE ) <EOL> if digit_pressed == "<STR_LIT:3>" : <EOL> notification . delete ( ) <EOL> resp . say ( "<STR_LIT>" ) <EOL> except ScheduledNotification . DoesNotExist : <EOL> resp . say ( "<STR_LIT>" ) <EOL> except User . DoesNotExist : <EOL> resp . say ( "<STR_LIT>" ) <EOL> return resp </s>
