-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathviews.py
48 lines (34 loc) · 1.26 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# encoding=utf-8
# maintainer: rgaudin
import urllib
import thread
import logging
from django.http import HttpResponse, Http404
from django.shortcuts import redirect
from nosms.models import Message
from nosms.utils import process_incoming_message
logger = logging.getLogger(__name__)
def handler_get(request):
if request.method == 'GET':
if 'from' in request.GET and 'text' in request.GET:
return redirect('handler', request.GET.get('from'), \
request.GET.get('text'))
raise Http404(u"Oh nooozzee")
def handler(request, identity, text):
def _str(uni):
try:
return str(uni)
except:
return uni.encode('utf-8')
def _plus(str):
return str.replace('%2B', '+')
text = urllib.unquote(_str(_plus(text.replace('+', ' '))))
message = Message(identity=identity, text=text, \
status=Message.STATUS_CREATED, \
direction=Message.DIRECTION_INCOMING)
message.save()
process_incoming_message(message)
return HttpResponse(u"Thanks %s, the following message " \
"have been processed:\n%s" % (identity, text), \
mimetype='text/plain', status=202)