add json api to sms app to expose message log for phone numbers

This commit is contained in:
Sanj 2012-10-11 00:29:34 +05:30
parent 99af8ad9ba
commit 84511cb22d
3 changed files with 20 additions and 0 deletions

View File

@ -1 +1,18 @@
# Create your views here.
from rapidsms.contrib.messagelog.models import Message
from ox.django.shortcuts import render_to_json_response
def messages_json(request):
phone_no = request.GET.get("phone_no", None)
#TODO: validate phone no
if not phone_no:
return render_to_json_response({'error': 'no phone number provided'})
messages = Message.objects.filter(connection__identity__endswith=phone_no)
ret = []
for m in messages:
ret.append({
'text': m.text,
'direction': m.direction,
'datetime': m.date.isoformat()
})
return render_to_json_response(ret)

View File

@ -21,6 +21,8 @@ DATABASES = {
MEDIA_ROOT = join(PROJECT_PATH, 'static')
LOCAL_DEVELOPMENT = True
JSON_DEBUG = False
# the rapidsms backend configuration is designed to resemble django's
# database configuration, as a nested dict of (name, configuration).
#

View File

@ -28,6 +28,7 @@ urlpatterns = patterns('',
(r'^messaging/', include('rapidsms.contrib.messaging.urls')),
(r'^registration/', include('rapidsms.contrib.registration.urls')),
(r'^scheduler/', include('rapidsms.contrib.scheduler.urls')),
(r'^messages_json/', 'mumbai.views.messages_json'),
)
if settings.LOCAL_DEVELOPMENT: