コード例 #1
0
    def submit(self, submission, reporter_id):
        try:
            form_code, values, extra_data = SMSParserFactory().getSMSParser(submission, self.dbm).parse(submission)

            form_model = get_form_model_by_code(self.dbm, form_code)

            if self.organization.has_exceeded_quota_and_notify_users():
                return False, "Exceeded Submission Limit"

            if isinstance(form_model, EntityFormModel):
                response = self._create_identification_number(form_code, values, extra_data)
            else:
                response = self._create_survey_response(form_model, reporter_id, values, extra_data)

        except FormModelDoesNotExistsException as e:
            request = {"form_code": e.data[0],
                       "incoming_message": submission,
                       "organization": self.organization,
                       "transport_info": TransportInfo("api", "", "")}
            create_failure_log("Form Code is not valid.", request)
            return False, "Form Code is not valid."

        except DataObjectAlreadyExists:
            return False, "Duplicate unique id"

        except SMSParserInvalidFormatException:
            return False, "Wrong number of answers"

        except MangroveException as e:
            return False, e.message

        if response.success:
            return True, 'submitted successfully'
        else:
            return False, response.errors.values()[0]
コード例 #2
0
 def test_should_create_failure_log_when_form_code_is_not_present(self):
     error_message = "error message"
     create_failure_log(error_message,self.request)
     log = DatawinnerLog.objects.all().order_by('-created_at')[0]
     self.assertEqual(error_message,log.error)
     self.assertEqual('',log.form_code)
     self.assertEqual(self.request['transport_info'].source,log.from_number)
     self.assertEqual(self.request['transport_info'].destination,log.to_number)
     self.assertEqual(None,log.organization)
     log.delete()
コード例 #3
0
 def test_should_create_failure_log(self):
     self.request[FORM_CODE]='code'
     error_message = "error message"
     self.request['organization']=Organization.objects.get(org_id=DEFAULT_TEST_ORG_ID)
     create_failure_log(error_message,self.request)
     log = DatawinnerLog.objects.all().order_by('-created_at')[0]
     self.assertEqual(error_message,log.error)
     self.assertEqual(self.request[FORM_CODE],log.form_code)
     self.assertEqual(self.request['transport_info'].source,log.from_number)
     self.assertEqual(self.request['transport_info'].destination,log.to_number)
     self.assertEqual(self.request['organization'],log.organization)
     log.delete()
コード例 #4
0
def find_dbm(request):
    incoming_request = {}
    #This is the http post request. After this state, the request being sent is a python dictionary
    SMSMessageRequestProcessor().process(http_request=request, mangrove_request=incoming_request)
    SMSTransportInfoRequestProcessor().process(http_request=request, mangrove_request=incoming_request)
    organization, error = _get_organization(request)

    if error is not None:
        incoming_request['outgoing_message'] = error
        create_failure_log(error, incoming_request)
        return incoming_request

    incoming_request['dbm'] = get_database_manager_for_org(organization)
    incoming_request['organization'] = organization

    incoming_request['next_state'] = process_sms_counter
    return incoming_request
コード例 #5
0
def find_dbm(request):
    send_to_carbon(create_path('submissions.sms'), 1)
    incoming_request = {}
    # This is the http post request. After this state, the request being sent is a python dictionary
    SMSMessageRequestProcessor().process(http_request=request, mangrove_request=incoming_request)
    SMSTransportInfoRequestProcessor().process(http_request=request, mangrove_request=incoming_request)
    organization, error = _get_organization(request)

    if error is not None:
        incoming_request['outgoing_message'] = error
        create_failure_log(error, incoming_request)
        return incoming_request

    incoming_request['dbm'] = get_database_manager_for_org(organization)
    incoming_request['feeds_dbm'] = get_feeds_db_for_org(organization)
    incoming_request['organization'] = organization
    incoming_request['message_id'] = request.POST.get('message_id')
    translation.activate(organization.language)

    incoming_request['next_state'] = check_account_and_datasender
    return incoming_request