# Path: safecity/apps/tropo/views.py
# def process_message(message):
#     """
#     The root message processing handler--parses the message and hands it off
#     to other processors as appropriate.
#     """
#     # TODO - strip whitespace
#     # TODO - handle blank messages
# 
#     keyword = message.text.split()[0].lower()
#     
#     if keyword in KEYWORDS['QUIT']:
#         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)


import json
import logging
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template.loader import render_to_string
from safecity.apps.tropo.views import process_message
from safecity.lib.messages import *
        
        self.mock_output = []

    def respond(self, text):
        self.mock_output.append((self.sender, text))

    def forward(self, recipients):
        for r in recipients:
            self.mock_output.append((r, self.text))

@staff_member_required
def mock(request):
    """
    Create a form for mocking up SMS messages.
    """
    context = {
        'settings': settings,
    }
    
    return render_to_response(
        'mock/mock.html',
        context)
        
@staff_member_required
def mock_sms_ajax(request):
    message = MockIncomingMessage(
        sender=request.REQUEST.get('sender'),
        text=str(request.REQUEST.get('text')),
        received=datetime.now())
        

# Path: safecity/apps/tropo/views.py
# def process_message(message):
#     """
#     The root message processing handler--parses the message and hands it off
#     to other processors as appropriate.
#     """
#     # TODO - strip whitespace
#     # TODO - handle blank messages
# 
#     keyword = message.text.split()[0].lower()
#     
#     if keyword in KEYWORDS['QUIT']:
#         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)


# Path: safecity/apps/mock/views.py
import json
import logging
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template.loader import render_to_string
from safecity.apps.tropo.views import process_message
from safecity.lib.messages import *

        
        self.mock_output = []

    def respond(self, text):
        self.mock_output.append((self.sender, text))

    def forward(self, recipients):
        for r in recipients:
            self.mock_output.append((r, self.text))

@staff_member_required
def mock(request):
    """
    Create a form for mocking up SMS messages.
    """
    context = {
        'settings': settings,
    }
    
    return render_to_response(
        'mock/mock.html',
        context)
        
@staff_member_required
def mock_sms_ajax(request):
    message = MockIncomingMessage(
        sender=request.REQUEST.get('sender'),
        text=str(request.REQUEST.get('text')),
        received=datetime.now())
        

    response = process_message(message)