Created
March 29, 2012 16:40
-
-
Save amackera/2239640 to your computer and use it in GitHub Desktop.
get_outgoing_number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_outgoing_number(provider, incoming_number): | |
''' | |
Returns the outgoing number associated with this incoming number. | |
''' | |
def get_sms_settings(): | |
# Memcached closure returns outgoing number for this student | |
try: | |
settings = SmsSettings.objects.get(phone_number = incoming_number) | |
except SmsSettings.DoesNotExist: | |
# Create settings record for this number | |
outgoing_number = get_provider_outgoing_number(provider) | |
safe_call_task(tq_save_sms_settings, | |
[incoming_number, outgoing_number]) | |
return outgoing_number | |
if settings.sms_reply_number == None: | |
# Settings exist but no sms_reply_number has been set. Set it | |
outgoing_number = get_provider_outgoing_number(provider) | |
safe_call_task(tq_save_sms_settings, | |
[incoming_number, outgoing_number]) | |
return outgoing_number | |
else: | |
return settings.sms_reply_number | |
number = get_object_through_memcache("sms_reply_number_%s" %incoming_number, | |
get_sms_settings, | |
timeout = 120) | |
if number: | |
# settings exist, and outgoing number exists for setting | |
return number | |
else: | |
# Something bad happened... | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A good improvement, thanks!