예제 #1
0
    def create(self, request):
        sms = parse_post_event_xml(request.raw_post_data)
        # update the POST to have the `_from` key copied from `from`.
        # The model has `_from` defined because `from` is a protected python
        # statement
        form = forms.ReceivedSMSForm({
            'user': request.user.pk,
            'to_msisdn': sms['Local'],
            'from_msisdn': sms['Remote'],
            'message': sms['Text'],
            'transport_name': 'Opera',
            'received_at': iso8601.parse_date(sms['ReceiveDate'])
        })
        if not form.is_valid():
            raise FormValidationError(form)

        receive_sms = form.save()
        logging.debug('Receiving an SMS from: %s' % receive_sms.from_msisdn)
        signals.sms_received.send(sender=ReceivedSMS, instance=receive_sms,
                                  pk=receive_sms.pk)

        # return the response we got back to Opera, it could be re-routed
        # to other services in a callback chain.
        response = rc.ALL_OK
        response.content = request.raw_post_data
        response['Content-Type'] = 'text/xml; charset=utf8'
        return response
예제 #2
0
파일: opera.py 프로젝트: mangroveorg/vumi
 def render_POST(self, request):
     content = request.content.read()
     sms = utils.parse_post_event_xml(content)
     self.callback(
         to_addr=normalize_msisdn(sms['Local'], country_code='27'),
         from_addr=normalize_msisdn(sms['Remote'], country_code='27'),
         content=sms['Text'], transport_type='sms',
         message_id=sms['MessageID'], transport_metadata={
             'provider': sms['MobileNetwork']
         })
     request.setResponseCode(http.OK)
     request.setHeader('Content-Type', 'text/xml; charset=utf8')
     return content
예제 #3
0
파일: opera.py 프로젝트: snopoke/vumi
 def render_POST(self, request):
     content = get_receipts_xml(request.content.read())
     sms = utils.parse_post_event_xml(content)
     self.callback(to_addr=normalize_msisdn(sms['Local'],
                                            country_code='27'),
                   from_addr=normalize_msisdn(sms['Remote'],
                                              country_code='27'),
                   content=sms['Text'],
                   transport_type='sms',
                   message_id=sms['MessageID'],
                   transport_metadata={'provider': sms['MobileNetwork']})
     request.setResponseCode(http.OK)
     request.setHeader('Content-Type', 'text/xml; charset=utf8')
     return content
예제 #4
0
파일: opera.py 프로젝트: AndrewCvekl/vumi
 def render_POST(self, request):
     try:
         content = get_receipts_xml(request.content.read())
         sms = utils.parse_post_event_xml(content)
         for field in [
                 'Local', 'Remote', 'Text', 'MessageID', 'MobileNetwork']:
             if field not in sms:
                 raise BadRequestError("Missing field: %s" % (field,))
     except BadRequestError as err:
         request.setResponseCode(http.BAD_REQUEST)
         request.setHeader('Content-Type', 'text/plain; charset=utf8')
         return err.args[0]
     self.callback(
         to_addr=normalize_msisdn(sms['Local'], country_code='27'),
         from_addr=normalize_msisdn(sms['Remote'], country_code='27'),
         content=sms['Text'], transport_type='sms',
         message_id=sms['MessageID'], transport_metadata={
             'provider': sms['MobileNetwork']
         })
     request.setResponseCode(http.OK)
     request.setHeader('Content-Type', 'text/xml; charset=utf8')
     return content
예제 #5
0
 def render_POST(self, request):
     try:
         content = get_receipts_xml(request.content.read())
         sms = utils.parse_post_event_xml(content)
         for field in [
                 'Local', 'Remote', 'Text', 'MessageID', 'MobileNetwork'
         ]:
             if field not in sms:
                 raise BadRequestError("Missing field: %s" % (field, ))
     except BadRequestError as err:
         request.setResponseCode(http.BAD_REQUEST)
         request.setHeader('Content-Type', 'text/plain; charset=utf8')
         return err.args[0]
     self.callback(to_addr=normalize_msisdn(sms['Local'],
                                            country_code='27'),
                   from_addr=normalize_msisdn(sms['Remote'],
                                              country_code='27'),
                   content=sms['Text'],
                   transport_type='sms',
                   message_id=sms['MessageID'],
                   transport_metadata={'provider': sms['MobileNetwork']})
     request.setResponseCode(http.OK)
     request.setHeader('Content-Type', 'text/xml; charset=utf8')
     return content