<s> from corehq . util . mixin import UUIDGeneratorMixin <EOL> from corehq . apps . sms . mixin import UnrecognizedBackendException <EOL> from corehq . apps . sms . models import SQLMobileBackend , Log , OUTGOING <EOL> from django . db import models <EOL> class UnrecognizedIVRBackendException ( UnrecognizedBackendException ) : <EOL> pass <EOL> class SQLIVRBackend ( SQLMobileBackend ) : <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> proxy = True <EOL> def initiate_outbound_call ( self , call , logged_subevent , ivr_data = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def get_response ( self , gateway_session_id , ivr_responses , collect_input = False , <EOL> hang_up = True , input_length = None ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def cache_first_ivr_response ( self ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> def set_first_ivr_response ( self , call , gateway_session_id , ivr_data ) : <EOL> call . xforms_session_id = ivr_data . session . session_id <EOL> call . use_precached_first_response = True <EOL> call . first_response = self . get_response ( <EOL> gateway_session_id , <EOL> ivr_data . ivr_responses , <EOL> collect_input = True , <EOL> hang_up = False , <EOL> input_length = ivr_data . input_length <EOL> ) <EOL> class Call ( UUIDGeneratorMixin , Log ) : <EOL> UUIDS_TO_GENERATE = [ '<STR_LIT>' ] <EOL> couch_id = models . CharField ( max_length = <NUM_LIT> , null = True , db_index = True ) <EOL> """<STR_LIT>""" <EOL> answered = models . NullBooleanField ( default = False ) <EOL> duration = models . IntegerField ( null = True ) <EOL> gateway_session_id = models . CharField ( max_length = <NUM_LIT> , null = True , db_index = True ) <EOL> """<STR_LIT>""" <EOL> submit_partial_form = models . NullBooleanField ( default = False ) <EOL> include_case_side_effects = models . NullBooleanField ( default = False ) <EOL> max_question_retries = models . IntegerField ( null = True ) <EOL> current_question_retry_count = models . IntegerField ( default = <NUM_LIT:0> , null = True ) <EOL> """<STR_LIT>""" <EOL> xforms_session_id = models . CharField ( max_length = <NUM_LIT> , null = True ) <EOL> error_message = models . TextField ( null = True ) <EOL> use_precached_first_response = models . NullBooleanField ( default = False ) <EOL> first_response = models . TextField ( null = True ) <EOL> case_id = models . CharField ( max_length = <NUM_LIT> , null = True ) <EOL> case_for_case_submission = models . NullBooleanField ( default = False ) <EOL> form_unique_id = models . CharField ( max_length = <NUM_LIT> , null = True ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> @ classmethod <EOL> def by_gateway_session_id ( cls , gateway_session_id ) : <EOL> result = cls . objects . filter ( <EOL> gateway_session_id = gateway_session_id <EOL> ) . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:1> ] <EOL> if result : <EOL> return result [ <NUM_LIT:0> ] <EOL> return None <EOL> @ classmethod <EOL> def answered_call_exists ( cls , contact_doc_type , contact_id , from_timestamp , to_timestamp = None ) : <EOL> qs = cls . by_recipient ( <EOL> contact_doc_type , <EOL> contact_id <EOL> ) . filter ( <EOL> direction = OUTGOING , <EOL> date__gte = from_timestamp , <EOL> answered = True <EOL> ) <EOL> if to_timestamp : <EOL> qs = qs . filter ( <EOL> date__lte = to_timestamp <EOL> ) <EOL> return qs . count ( ) > <NUM_LIT:0> </s>
