# Path: safecity/apps/danger/models.py
# class Report(models.Model):
#     """
#     Processed data for messages that are reporting suspicious activity.
#     
#     TODO: support multi-part messages.
#     """
#     location = models.PointField(
#         spatial_index=True,
#         help_text='Location extracted from the report.')
#         
#     text = models.CharField(
#         max_length=160,
#         help_text='Body of the message.')
#         
#     sender = models.CharField(
#         max_length=16,
#         null=True,
#         help_text='Phone number of the reporter in e164 format. None if anonymized.')
#         
#     received = models.DateTimeField(
#         auto_now_add=True,
#         help_text='Date and time this message was received. Approximate if anonymized.')
# 
#     objects = models.GeoManager()
#     
#     class Meta:
#         ordering = ['-received']
#         get_latest_by = 'received'
#         
#     def find_nearby_residents(self):
#         """
#         Get a list of residents near this report.
#         """
#         return Resident.objects.filter(location__distance_lte=(self.location, D(km=1)))
# 
# Path: safecity/apps/signup/models.py
# class Resident(models.Model):
#     """
#     Individuals who want to receive alerts when activity happens near them.
#     
#     Privacy notes:
#     1) The text used to register the resident is intentionally not associated with them.
#     2) Created/updated times are not maintained so that any potentially sensitive information
#         in their messages can never be associated with them.
#     3) Residents are DELETED when a request is made to deregister them.
#     """
#     phone_number = models.CharField(
#         primary_key=True,
#         max_length=16,
#         help_text='Phone number this resident registered with in e164 format.')
#     
#     location = models.PointField(    
#         spatial_index=True,
#         help_text='Location extracted from request message.')
#     
#     objects = models.GeoManager()
#         
#     def __unicode__(self):
#         return self.phone_number


from datetime import datetime
from safecity.apps.danger.models import Report
from safecity.apps.locate.location_parser import *
from safecity.apps.signup.models import Resident
from safecity.apps.tropo.tropolib import *
from safecity.lib.messages import *
import logging
        return process_quit(message)
    
    # Annotate location
    try:
        message.parse_location()
    except NoLocationException:
        message.respond('We were unable to determine your location. Try rephrasing your message using cross-streets.')
        return TropoOkResponse()
    except MultiplePossibleLocationsException:
        message.respond('We were unable to determine your exact location. Try providing more information, such as the block number.')
        return TropoOkResponse()
    except RoadWithoutBlockException:
        message.respond('We were unable to determine your exact location. When stating a street name please include the block number.')
        return TropoOkResponse()
        
    # TODO - handling should be done off process?
    if keyword in KEYWORDS['JOIN']:
        return process_join(message)
    elif keyword in KEYWORDS['UPDATE']:
        return process_update(message)

    return process_report(message)
    
def process_join(message):
    """
    Process setting up a record of a new user and request that they establish
    their location.
    """
    try:
        # If the user is already registered process as an update instead

# Path: safecity/apps/danger/models.py
# class Report(models.Model):
#     """
#     Processed data for messages that are reporting suspicious activity.
#     
#     TODO: support multi-part messages.
#     """
#     location = models.PointField(
#         spatial_index=True,
#         help_text='Location extracted from the report.')
#         
#     text = models.CharField(
#         max_length=160,
#         help_text='Body of the message.')
#         
#     sender = models.CharField(
#         max_length=16,
#         null=True,
#         help_text='Phone number of the reporter in e164 format. None if anonymized.')
#         
#     received = models.DateTimeField(
#         auto_now_add=True,
#         help_text='Date and time this message was received. Approximate if anonymized.')
# 
#     objects = models.GeoManager()
#     
#     class Meta:
#         ordering = ['-received']
#         get_latest_by = 'received'
#         
#     def find_nearby_residents(self):
#         """
#         Get a list of residents near this report.
#         """
#         return Resident.objects.filter(location__distance_lte=(self.location, D(km=1)))
# 
# Path: safecity/apps/signup/models.py
# class Resident(models.Model):
#     """
#     Individuals who want to receive alerts when activity happens near them.
#     
#     Privacy notes:
#     1) The text used to register the resident is intentionally not associated with them.
#     2) Created/updated times are not maintained so that any potentially sensitive information
#         in their messages can never be associated with them.
#     3) Residents are DELETED when a request is made to deregister them.
#     """
#     phone_number = models.CharField(
#         primary_key=True,
#         max_length=16,
#         help_text='Phone number this resident registered with in e164 format.')
#     
#     location = models.PointField(    
#         spatial_index=True,
#         help_text='Location extracted from request message.')
#     
#     objects = models.GeoManager()
#         
#     def __unicode__(self):
#         return self.phone_number


# Path: safecity/apps/tropo/views.py
from datetime import datetime
from safecity.apps.danger.models import Report
from safecity.apps.locate.location_parser import *
from safecity.apps.signup.models import Resident
from safecity.apps.tropo.tropolib import *
from safecity.lib.messages import *
import logging

        return process_quit(message)
    
    # Annotate location
    try:
        message.parse_location()
    except NoLocationException:
        message.respond('We were unable to determine your location. Try rephrasing your message using cross-streets.')
        return TropoOkResponse()
    except MultiplePossibleLocationsException:
        message.respond('We were unable to determine your exact location. Try providing more information, such as the block number.')
        return TropoOkResponse()
    except RoadWithoutBlockException:
        message.respond('We were unable to determine your exact location. When stating a street name please include the block number.')
        return TropoOkResponse()
        
    # TODO - handling should be done off process?
    if keyword in KEYWORDS['JOIN']:
        return process_join(message)
    elif keyword in KEYWORDS['UPDATE']:
        return process_update(message)

    return process_report(message)
    
def process_join(message):
    """
    Process setting up a record of a new user and request that they establish
    their location.
    """
    try:
        # If the user is already registered process as an update instead

        Resident.objects.get(phone_number=message.sender)