def process_create_data_sender_form(dbm, form, org_id): message = None data_sender_id = None if form.is_valid(): try: organization = Organization.objects.get(org_id=org_id) if organization.in_trial_mode: add_data_sender_to_trial_organization(form.cleaned_data["telephone_number"], org_id) web_player = WebPlayer(dbm, LocationBridge(location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy)) reporter_id = form.cleaned_data["short_code"] if form.cleaned_data != "" else None request = Request(message=_get_data(form.cleaned_data, organization.country_name(), reporter_id), transportInfo=TransportInfo(transport='web', source='web', destination='mangrove')) response = web_player.accept(request, logger=websubmission_logger) if response.success: data_sender_id = response.short_code message = get_success_msg_for_registration_using(response, "web") else: form.update_errors(response.errors) except MangroveException as exception: message = exception.message return data_sender_id,message
def build(cls, manager, extension, default_parser=None, form_code=None, is_datasender=False): channels = dict({ ".xls": Channel.XLS, ".xlsx": Channel.XLSX, ".csv": Channel.CSV }) try: channel = channels[extension] except KeyError: raise InvalidFileFormatException() if default_parser is not None: parser = default_parser() elif extension == '.csv': parser = CsvParser() elif extension == '.xls': parser = XlsParser() elif extension == '.xlsx': parser = XlsxParser() else: raise InvalidFileFormatException() location_bridge = LocationBridge( get_location_tree(), get_loc_hierarchy=get_location_hierarchy) player = FilePlayer(manager, parser, channel, location_tree=location_bridge, is_datasender=is_datasender) player.form_code = form_code return player
def player_response(self, created_request): location_bridge = LocationBridge( location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy) return WebPlayer(self.manager, location_bridge).accept(created_request, logger=websubmission_logger)
def _edit_contact(self, form, manager, organization, reporter_id): web_player = WebPlayer(manager, LocationBridge(location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy)) response = web_player.accept( Request(message=_get_data(form.cleaned_data, organization.country_name(), reporter_id), transportInfo=TransportInfo(transport='web', source='web', destination='mangrove'), is_update=True)) return response
def _create_identification_number(self,form_code, values, extra_data): if extra_data: return Response(success=False, errors=_create_error("Wrong number of answers")) service = IdentificationNumberService(self.dbm) location_tree = LocationBridge(get_location_tree(), get_location_hierarchy) response = service.save_identification_number(form_code, values, location_tree) return response
def process_create_data_sender_form(dbm, form, org_id): message = None data_sender_id = None if form.is_valid(): try: organization = Organization.objects.get(org_id=org_id) if organization.in_trial_mode: _add_data_sender_to_trial_organization( form.cleaned_data["telephone_number"], org_id) web_player = WebPlayer( dbm, LocationBridge(location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy)) reporter_id = form.cleaned_data["short_code"].lower( ) if form.cleaned_data != "" else None request = Request(message=_get_data(form.cleaned_data, organization.country_name(), reporter_id), transportInfo=TransportInfo( transport='web', source='web', destination='mangrove')) response = web_player.accept(request, logger=websubmission_logger) if response.success: data_sender_id = response.short_code message = get_success_msg_for_ds_registration_using( response, "web") else: form.update_errors(response.errors) except IntegrityError as e: form.update_errors({ MOBILE_NUMBER_FIELD_CODE: _(u'Sorry, the telephone number %s has already been registered.' ) % form.cleaned_data["telephone_number"] }) except DataObjectAlreadyExists as e: message = _("%s with %s = %s already exists.") % ( e.data[2], e.data[0], e.data[1], ) except MangroveException as exception: message = exception.message return data_sender_id, message
def submit_to_player(incoming_request): try: dbm = incoming_request['dbm'] post_sms_parser_processors = [PostSMSProcessorLanguageActivator(dbm, incoming_request), PostSMSProcessorNumberOfAnswersValidators(dbm, incoming_request)] sms_player = SMSPlayer(dbm, LocationBridge(get_location_tree(),get_loc_hierarchy=get_location_hierarchy), post_sms_parser_processors=post_sms_parser_processors) mangrove_request = Request(message=incoming_request['incoming_message'], transportInfo=incoming_request['transport_info']) response = sms_player.accept(mangrove_request, logger=incoming_request.get("logger")) message = SMSResponse(response).text(dbm) send_message(incoming_request, response) except DataObjectAlreadyExists as e: message = ugettext("%s with %s = %s already exists.") % (ugettext(e.data[2]), ugettext(e.data[0]), e.data[1]) except Exception as exception: message = handle(exception, incoming_request) incoming_request['outgoing_message'] = message return incoming_request
def submit(request): dbm = get_database_manager(request.user) post = json.loads(request.POST['data']) success = True try: web_player = WebPlayer( dbm, LocationBridge(location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy)) message = post['message'] message[LOCATION_TYPE_FIELD_CODE] = get_country_appended_location( message.get(LOCATION_TYPE_FIELD_CODE), get_organization_country(request)) request = Request(message=message, transportInfo=TransportInfo( transport=post.get('transport'), source=post.get('source'), destination=post.get('destination'))) response = web_player.accept(request) if response.success: message = get_success_msg_for_registration_using(response, "web") else: message = get_submission_error_message_for(response.errors) entity_id = response.datarecord_id except DataObjectAlreadyExists as exception: message = _( "Entity with Unique Identification Number (ID) = %s already exists." ) % exception.data[1] success, entity_id = False, None except MangroveException as exception: message = get_exception_message_for(exception=exception, channel="web") message = _("Please add subject type and then add a subject" ) if message == "t should be present" else message success = False entity_id = None return HttpResponse( json.dumps({ 'success': success, 'message': message, 'entity_id': entity_id }))
def setUp(self): self.tree = get_location_tree()
def post(self, request, reporter_id, *args, **kwargs): reporter_id = reporter_id.lower() manager = get_database_manager(request.user) reporter_entity = ReporterEntity( get_by_short_code(manager, reporter_id, [REPORTER])) entity_links = { 'registered_datasenders_link': reverse("all_datasenders") } datasender = {'short_code': reporter_id} get_datasender_user_detail(datasender, request.user) email = datasender.get( 'email') if datasender.get('email') != '--' else False org_id = request.user.get_profile().org_id form = ReporterRegistrationForm(org_id=org_id, data=request.POST) message = None if form.is_valid(): try: org_id = request.user.get_profile().org_id current_telephone_number = reporter_entity.mobile_number current_name = reporter_entity.name organization = Organization.objects.get(org_id=org_id) web_player = WebPlayer( manager, LocationBridge(location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy)) response = web_player.accept( Request(message=_get_data(form.cleaned_data, organization.country_name(), reporter_id), transportInfo=TransportInfo( transport='web', source='web', destination='mangrove'), is_update=True)) if response.success: if organization.in_trial_mode: update_data_sender_from_trial_organization( current_telephone_number, form.cleaned_data["telephone_number"], org_id) if email and current_name != form.cleaned_data["name"]: update_user_name_if_exists(email, form.cleaned_data["name"]) message = _("Your changes have been saved.") detail_dict = {"Unique ID": reporter_id} current_lang = get_language() activate("en") field_mapping = dict(mobile_number="telephone_number") for field in [ "geo_code", "location", "mobile_number", "name" ]: if getattr(reporter_entity, field) != form.cleaned_data.get( field_mapping.get(field, field)): label = u"%s" % form.fields[field_mapping.get( field, field)].label detail_dict.update({ label: form.cleaned_data.get( field_mapping.get(field, field)) }) activate(current_lang) if len(detail_dict) > 1: detail_as_string = json.dumps(detail_dict) UserActivityLog().log(request, action=EDITED_DATA_SENDER, detail=detail_as_string) else: form.update_errors(response.errors) except MangroveException as exception: message = exception.message return render_to_response('edit_datasender_form.html', { 'form': form, 'message': message, 'reporter_id': reporter_id, 'email': email, 'project_links': entity_links }, context_instance=RequestContext(request))
def edit_data_sender(request, project_id, reporter_id): manager = get_database_manager(request.user) reporter_entity = ReporterEntity( get_by_short_code(manager, reporter_id, [REPORTER])) project, links = _get_project_and_project_link(manager, project_id, reporter_id) user_profile = get_user_profile_by_reporter_id(reporter_id, request.user) email = user_profile.user.email if user_profile else None if request.method == 'GET': location = reporter_entity.location geo_code = reporter_entity.geo_code form = ReporterRegistrationForm( initial={ 'project_id': project_id, 'name': reporter_entity.name, 'telephone_number': reporter_entity.mobile_number, 'location': location, 'geo_code': geo_code }) return render_to_response('project/edit_datasender.html', { 'project': project, 'reporter_id': reporter_id, 'form': form, 'project_links': links, 'in_trial_mode': _in_trial_mode(request), 'email': email }, context_instance=RequestContext(request)) if request.method == 'POST': org_id = request.user.get_profile().org_id form = ReporterRegistrationForm(org_id=org_id, data=request.POST) message = None if form.is_valid(): try: organization = Organization.objects.get(org_id=org_id) current_telephone_number = reporter_entity.mobile_number web_player = WebPlayer( manager, LocationBridge(location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy)) response = web_player.accept( Request(message=_get_data(form.cleaned_data, organization.country_name(), reporter_id), transportInfo=TransportInfo( transport='web', source='web', destination='mangrove'), is_update=True)) if response.success: if organization.in_trial_mode: update_data_sender_from_trial_organization( current_telephone_number, form.cleaned_data["telephone_number"], org_id) message = _("Your changes have been saved.") detail_dict = {"Unique ID": reporter_id} current_lang = get_language() activate("en") field_mapping = dict(mobile_number="telephone_number") for field in [ "geo_code", "location", "mobile_number", "name" ]: if getattr(reporter_entity, field) != form.cleaned_data.get( field_mapping.get(field, field)): label = u"%s" % form.fields[field_mapping.get( field, field)].label detail_dict.update({ label: form.cleaned_data.get( field_mapping.get(field, field)) }) activate(current_lang) if len(detail_dict) > 1: detail_as_string = json.dumps(detail_dict) UserActivityLog().log(request, action=EDITED_DATA_SENDER, detail=detail_as_string, project=project.name) else: form.update_errors(response.errors) except MangroveException as exception: message = exception.message return render_to_response('edit_datasender_form.html', { 'project': project, 'form': form, 'reporter_id': reporter_id, 'message': message, 'project_links': links, 'in_trial_mode': _in_trial_mode(request), 'email': email }, context_instance=RequestContext(request))
def __init__(self,location_tree=None,get_loc_hierarchy=None): self.location_tree = location_tree or get_location_tree() self.get_location_hierarchy = get_loc_hierarchy or get_location_hierarchy
def edit_subject(request, entity_type, entity_id, project_id=None): manager = get_database_manager(request.user) form_model = get_form_model_by_entity_type(manager, [entity_type.lower()]) subject = get_by_short_code(manager, entity_id, [entity_type.lower()]) back_link = reverse(all_subjects, args=[entity_type]) web_questionnaire_template = get_template(request.user) disable_link_class, hide_link_class = get_visibility_settings_for( request.user) if request.method == 'GET': initialize_values(form_model, subject) questionnaire_form = SubjectRegistrationForm(form_model) form_context = _make_form_context( questionnaire_form, entity_type, disable_link_class, hide_link_class, form_model.form_code, get_organization_telephone_number(request), form_model.fields, is_update=True, back_link=back_link) form_context.update( {'is_pro_sms': get_organization(request).is_pro_sms}) return render_to_response(web_questionnaire_template, form_context, context_instance=RequestContext(request)) if request.method == 'POST': questionnaire_form = SubjectRegistrationForm( form_model, data=request.POST, country=get_organization_country(request)) if not questionnaire_form.is_valid(): form_context = _make_form_context( questionnaire_form, entity_type, disable_link_class, hide_link_class, form_model.form_code, get_organization_telephone_number(request), form_model.fields, is_update=True, back_link=back_link) return render_to_response(web_questionnaire_template, form_context, context_instance=RequestContext(request)) success_message = None error_message = None try: response = WebPlayer( manager, LocationBridge( location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy)).accept( create_request(questionnaire_form, request.user.username, is_update=True)) if response.success: #assumption q6 - unique_id code and q2 - lastname codes cannot be changed update_submission_search_for_subject_edition( manager, [entity_type], response.processed_data) success_message = _("Your changes have been saved.") questionnaire_form = SubjectRegistrationForm( form_model, data=request.POST, country=get_organization_country(request)) else: from datawinners.project.helper import errors_to_list questionnaire_form._errors = errors_to_list( response.errors, form_model.fields) form_context = _make_form_context( questionnaire_form, entity_type, disable_link_class, hide_link_class, form_model.form_code, get_organization_telephone_number(request), form_model.fields, is_update=True, back_link=back_link) return render_to_response( web_questionnaire_template, form_context, context_instance=RequestContext(request)) except DataObjectNotFound: message = exception_messages.get(DataObjectNotFound).get(WEB) error_message = _(message) % (form_model.entity_type[0], form_model.entity_type[0]) except Exception as exception: error_message = _( get_exception_message_for(exception=exception, channel=Channel.WEB)) subject_context = _make_form_context( questionnaire_form, entity_type, disable_link_class, hide_link_class, form_model.form_code, get_organization_telephone_number(request), form_model.fields, is_update=True, back_link=back_link) subject_context.update({ 'success_message': success_message, 'error_message': error_message }) return render_to_response(web_questionnaire_template, subject_context, context_instance=RequestContext(request))
def submit_to_player(incoming_request): sent_via_sms_test_questionnaire = incoming_request.get( 'test_sms_questionnaire', False) organization = incoming_request.get('organization') organization = organization try: dbm = incoming_request['dbm'] mangrove_request = Request( message=incoming_request['incoming_message'], transportInfo=incoming_request['transport_info']) response = _is_datasender_registered(dbm, incoming_request) if not response: post_sms_parser_processors = [ PostSMSProcessorLanguageActivator(dbm, incoming_request) ] if organization.in_trial_mode: post_sms_parser_processors.append( PostSMSProcessorCheckLimits(dbm, incoming_request)) post_sms_parser_processors.extend([ PostSMSProcessorNumberOfAnswersValidators( dbm, incoming_request), PostSMSProcessorCheckDSIsLinkedToProject( dbm, incoming_request) ]) sms_player = SMSPlayer( dbm, LocationBridge(get_location_tree(), get_loc_hierarchy=get_location_hierarchy), post_sms_parser_processors=post_sms_parser_processors, feeds_dbm=incoming_request['feeds_dbm']) response = sms_player.accept( mangrove_request, logger=incoming_request.get("logger"), translation_processor=TranslationProcessor) if response.is_registration: incoming_request['is_registration'] = True if not sent_via_sms_test_questionnaire: organization.increment_message_count_for( sms_registration_count=1) if not response.is_registration: if sent_via_sms_test_questionnaire: organization.increment_message_count_for( incoming_web_count=1) check_quotas_and_update_users(organization, sms_channel=True) mail_feed_errors(response, dbm.database_name) message = SMSResponse(response, incoming_request).text(dbm) send_message(incoming_request, response) except DataObjectAlreadyExists as e: message = identification_number_already_exists_handler( dbm, e.data[1], e.data[2]) if not sent_via_sms_test_questionnaire: organization.increment_message_count_for(sms_registration_count=1) except DataObjectNotFound as exception: if sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) message = handle(exception, incoming_request) except FormModelDoesNotExistsException as exception: if sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) message = incorrect_questionnaire_code_handler(dbm, exception.data[0]) except SMSParserWrongNumberOfAnswersException as exception: form_model = sms_player.get_form_model(mangrove_request) if not form_model.is_entity_registration_form(): organization.increment_message_count_for( incoming_web_count=1 ) if sent_via_sms_test_questionnaire else organization.increment_message_count_for( incoming_sms_count=1) message = incorrect_number_of_answers_for_submission_handler( dbm, form_model.form_code, incoming_request) elif form_model.is_entity_registration_form(): message = incorrect_number_of_answers_for_uid_registration_handler( dbm, form_model.form_code, incoming_request) elif not sent_via_sms_test_questionnaire: organization.increment_message_count_for(sms_registration_count=1) except Exception as exception: if sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) message = handle(exception, incoming_request) message = incoming_request.get('error_message', message) incoming_request['outgoing_message'] = message if incoming_request.get( 'is_outgoing_reply_sms_enabled', True) else "" if not sent_via_sms_test_questionnaire: if incoming_request.get('is_outgoing_reply_sms_enabled', True): organization.increment_message_count_for(outgoing_sms_count=1) SMS(message=message, message_id=incoming_request['message_id'], organization=incoming_request['organization'], msg_from=mangrove_request.transport.source, msg_to=mangrove_request.transport.destination, msg_type=MSG_TYPE_SUBMISSION_REPLY, status="Submitted").save() return incoming_request
def load_sms_data_for_cli001(manager): FEB = datetime(2011, 02, 28, hour=12, minute=00, second=00, tzinfo=UTC) MARCH = datetime(2011, 03, 01, tzinfo=UTC) DEC_2010 = datetime(2010, 12, 28, hour=00, minute=00, second=59, tzinfo=UTC) NOV_2010 = datetime(2010, 11, 26, hour=23, minute=59, second=59, tzinfo=UTC) today = datetime.today() THIS_MONTH = datetime(today.year, today.month, 5, 12, 45, 58) PREV_MONTH = THIS_MONTH - timedelta(days=8) tree = get_location_tree() sms_player = SMSPlayer(manager, SubmissionHandler(manager), location_tree=tree) FROM_NUMBER = '1234567890' TO_NUMBER = '261333782943' transport = TransportInfo(SMS, FROM_NUMBER, TO_NUMBER) message1 = "reg +t clinic +n Clinic in Analalava +l Analalava +g -14.6333 47.7667 +d This is a Clinic in Analalava +m 987654321" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Andapa +l Andapa +g -14.65 49.6167 +d This is a Clinic in Andapa +m 87654322" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Antalaha +l Antalaha +g -14.8833 50.25 +d This is a Clinic in Antalaha +m 87654323" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in ANALAMANGA +l ANALAMANGA +g -18.8 47.4833 +d This is a Clinic in Antananarivo +m 87654324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in TSIMANARIRAZANA +l TSIMANARIRAZANA +g -12.35 49.3 +d This is a Clinic in Diégo–Suarez +m 87654325" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Antsirabe +l Antsirabe +g -19.8167 47.0667 +d This is a Clinic in Antsirabe +m 87654326" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Besalampy +l Besalampy +g -16.75 44.5 +d This is a Clinic in Besalampy +m 87654327" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n clinique à Farafangana +l Farafangana +g -22.8 47.8333 +d This is a Clinic in Farafangana +m 87654328" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Fianarantsoa I +l Fianarantsoa I +g -21.45 47.1 +d C'est une clinique à Fianarantsoa +m 87654329" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Sainte Marie +l Sainte Marie +g -17.0833 49.8167 +d This is a Clinic in Île Sainte–Marie +m 87654330" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Mahajanga +l Mahajanga +g -15.6667 46.35 +d This is a Clinic in Mahajanga +m 87654331" response = sms_player.accept( Request(transportInfo=transport, message=message1)) datetime_mocker = DateTimeMocker() datetime_mocker.set_date_time_now(FEB) # Total number of identical records = 3 message1 = "cli001 +EID cid001 +NA Mr. Tessy +FA 58 +RD 28.02.2011 +BG c +SY ade +GPS 79.2 20.34567" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid002 +NA Mr. Adam +FA 62 +RD 15.02.2011 +BG a +SY ab +GPS 74.2678 23.3567" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid003 +NA Ms. Beth +FA 75 +RD 09.02.2011 +BG b +SY bc +GPS 18.245 29.3123" response = sms_player.accept( Request(transportInfo=transport, message=message1)) datetime_mocker.set_date_time_now(MARCH) # Total number of identical records = 4 message1 = "cli001 +EID cid004 +NA Jannita +FA 90 +RD 07.03.2011 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid005 +NA Aanda +RD 12.03.2011 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cid001 +NA Ianda (",) +FA 34 +RD 27.03.2011 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid001 +NA ànita +FA 45 +RD 07.03.2011 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid004 +NA Amanda +RD 12.03.2011 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cid005 +NA Vanda (",) +FA 34 +RD 27.03.2011 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid003 +NA ànnita +FA 80 +RD 07.03.2011 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid002 +NA Amanda +RD 12.03.2011 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cid004 +NA Panda (",) +FA 34 +RD 27.03.2011 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid005 +NA ànnita +FA 50 +RD 07.03.2011 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid003 +NA Jimanda +RD 12.03.2011 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cli10 +NA Kanda (",) +FA 64 +RD 27.03.2011 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid004 +NA ànnita +FA 30 +RD 07.03.2011 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid005 +NA Qamanda +RD 12.03.2011 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cid001 +NA Huanda (*_*) +FA 74 +RD 27.03.2011 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept( Request(transportInfo=transport, message=message1)) datetime_mocker.set_date_time_now(DEC_2010) # Total number of identical records = 4 message1 = "cli001 +EID cli12 +FA 47 +RD 15.12.2010 +BG d +SY ace +GPS -58.3452 19.3345" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli11 +NA De'melo +FA 38 +RD 27.12.2010 +BG c +SY ba +GPS 81.672 92.33456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli13 +NA Dono`mova +FA 24 +RD 06.12.2010 +BG b +SY cd +GPS 65.23452 -28.3456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli15 +NA Aàntra +FA 89 +RD 11.12.2010 +BG a +SY bd +GPS 45.234 89.32345" response = sms_player.accept( Request(transportInfo=transport, message=message1)) datetime_mocker.set_date_time_now(NOV_2010) # Total number of identical records = 3 message1 = "cli001 +EID cli12 +NA ànnita +FA 90 +RD 07.11.2010 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli14 +NA Amanda +RD 12.11.2010 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cli8 +NA Kanda (",) +FA 34 +RD 27.11.2010 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli9 +NA ànnita +FA 90 +RD 17.11.2010 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid007 +NA Amanda +RD 12.11.2010 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cli8 +NA Kanda (",) +FA 34 +RD 27.11.2010 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept( Request(transportInfo=transport, message=message1)) datetime_mocker.set_date_time_now(PREV_MONTH) # Total number of identical records = 4 message1 = "cli001 +EID cli9 +NA Demelo +FA 38 +RD 17.05.2011 +BG c +SY ba +GPS 19.672 92.33456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli10 +NA Zorro +FA 48 +RD 05.05.2011 +BG b +SY cd +GPS 23.23452 -28.3456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli11 +NA Aàntra +FA 98 +RD 12.05.2011 +BG a +GPS -45.234 89.32345" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli12 +NA ànnita +FA 37 +RD 05.05.2011 +BG d +SY cbe +GPS -78.233 -28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli9 +NA Demelo +FA 38 +RD 17.05.2011 +BG c +SY ba +GPS 19.672 92.33456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli10 +NA Zorro +FA 48 +RD 02.05.2011 +BG b +SY cd +GPS 23.23452 -28.3456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli11 +NA Aàntra +FA 95 +RD 12.05.2011 +BG a +GPS -45.234 89.32345" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli12 +NA ànnita +FA 35 +RD 09.05.2010 +BG d +SY cbe +GPS -78.233 -28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli9 +NA Demelo +FA 32 +RD 27.05.2011 +BG c +SY ba +GPS 19.672 92.33456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli10 +NA Zorro +FA 43 +RD 05.05.2011 +BG b +SY cd +GPS 23.23452 -28.3456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli11 +NA Aàntra +FA 91 +RD 12.05.2011 +BG a +GPS -45.234 89.32345" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli12 +NA ànnita +FA 45 +RD 15.05.2010 +BG d +SY cbe +GPS -78.233 -28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) datetime_mocker.set_date_time_now(THIS_MONTH) # Total number of identical records = 4 message1 = "cli001 +EID cli13 +NA Dmanda +FA 69 +RD 05.06.2011 +BG c +SY ce +GPS 40.2 69.3123" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli14 +NA Vamand +FA 36 +RD 03.06.2011 +BG a +SY ace +GPS 58.3452 115.3345" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli15 +NA M!lo +FA 88 +RD 02.06.2011 +SY ba +GPS 19.672 92.33456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli16 +NA K!llo +FA 88 +GPS 19.672 92.33456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli13 +NA Dmanda +FA 89 +RD 04.06.2011 +BG c +SY ce +GPS 40.2 69.3123" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli14 +NA Vamand +FA 56 +RD 01.06.2011 +BG a +SY ace +GPS 58.3452 115.3345" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli15 +NA M!lo +FA 45 +RD 07.06.2011 +SY ba +GPS 19.672 92.33456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli16 +NA K!llo +FA 28 +GPS 19.672 92.33456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) datetime_mocker.end_mock() # Total number of identical records = 3 message1 = "cli001 +EID cli17 +NA Catty +FA 78 +RD 15.06.2011 +BG b +SY dce +GPS 33.23452 -68.3456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli18 +NA àntra +FA 28 +RD 12.06.2011 +BG a +SY adb +GPS -45.234 169.32345" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli9 +NA Tinnita +FA 37 +BG d +SY ace +GPS -78.233 -28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli17 +NA Catty +FA 98 +RD 25.06.2011 +BG b +SY dce +GPS 33.23452 -68.3456" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli18 +NA àntra +FA 58 +RD 22.06.2011 +BG a +SY adb +GPS -45.234 169.32345" response = sms_player.accept( Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli9 +NA Tinnita +FA 27 +BG d +SY ace +GPS -78.233 -28.3324" response = sms_player.accept( Request(transportInfo=transport, message=message1))
def load_sms_data_for_cli001(manager): FEB = datetime(2011, 02, 28, hour=12, minute=00, second=00, tzinfo=UTC) MARCH = datetime(2011, 03, 01, tzinfo=UTC) DEC_2010 = datetime(2010, 12, 28, hour=00, minute=00, second=59, tzinfo=UTC) NOV_2010 = datetime(2010, 11, 26, hour=23, minute=59, second=59, tzinfo=UTC) today = datetime.today() THIS_MONTH = datetime(today.year,today.month,5,12,45,58) PREV_MONTH = THIS_MONTH - timedelta(days=8) tree = get_location_tree() sms_player = SMSPlayer(manager, SubmissionHandler(manager), location_tree=tree) FROM_NUMBER = '1234567890' TO_NUMBER = '261333782943' transport = TransportInfo(SMS, FROM_NUMBER, TO_NUMBER) message1 = "reg +t clinic +n Clinic in Analalava +l Analalava +g -14.6333 47.7667 +d This is a Clinic in Analalava +m 987654321" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Andapa +l Andapa +g -14.65 49.6167 +d This is a Clinic in Andapa +m 87654322" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Antalaha +l Antalaha +g -14.8833 50.25 +d This is a Clinic in Antalaha +m 87654323" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in ANALAMANGA +l ANALAMANGA +g -18.8 47.4833 +d This is a Clinic in Antananarivo +m 87654324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in TSIMANARIRAZANA +l TSIMANARIRAZANA +g -12.35 49.3 +d This is a Clinic in Diégo–Suarez +m 87654325" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Antsirabe +l Antsirabe +g -19.8167 47.0667 +d This is a Clinic in Antsirabe +m 87654326" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Besalampy +l Besalampy +g -16.75 44.5 +d This is a Clinic in Besalampy +m 87654327" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n clinique à Farafangana +l Farafangana +g -22.8 47.8333 +d This is a Clinic in Farafangana +m 87654328" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Fianarantsoa I +l Fianarantsoa I +g -21.45 47.1 +d C'est une clinique à Fianarantsoa +m 87654329" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Sainte Marie +l Sainte Marie +g -17.0833 49.8167 +d This is a Clinic in Île Sainte–Marie +m 87654330" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "reg +t clinic +n Clinic in Mahajanga +l Mahajanga +g -15.6667 46.35 +d This is a Clinic in Mahajanga +m 87654331" response = sms_player.accept(Request(transportInfo=transport, message=message1)) datetime_mocker = DateTimeMocker() datetime_mocker.set_date_time_now(FEB) # Total number of identical records = 3 message1 = "cli001 +EID cid001 +NA Mr. Tessy +FA 58 +RD 28.02.2011 +BG c +SY ade +GPS 79.2 20.34567" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid002 +NA Mr. Adam +FA 62 +RD 15.02.2011 +BG a +SY ab +GPS 74.2678 23.3567" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid003 +NA Ms. Beth +FA 75 +RD 09.02.2011 +BG b +SY bc +GPS 18.245 29.3123" response = sms_player.accept(Request(transportInfo=transport, message=message1)) datetime_mocker.set_date_time_now(MARCH) # Total number of identical records = 4 message1 = "cli001 +EID cid004 +NA Jannita +FA 90 +RD 07.03.2011 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid005 +NA Aanda +RD 12.03.2011 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cid001 +NA Ianda (",) +FA 34 +RD 27.03.2011 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid001 +NA ànita +FA 45 +RD 07.03.2011 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid004 +NA Amanda +RD 12.03.2011 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cid005 +NA Vanda (",) +FA 34 +RD 27.03.2011 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid003 +NA ànnita +FA 80 +RD 07.03.2011 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid002 +NA Amanda +RD 12.03.2011 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cid004 +NA Panda (",) +FA 34 +RD 27.03.2011 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid005 +NA ànnita +FA 50 +RD 07.03.2011 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid003 +NA Jimanda +RD 12.03.2011 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cli10 +NA Kanda (",) +FA 64 +RD 27.03.2011 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid004 +NA ànnita +FA 30 +RD 07.03.2011 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid005 +NA Qamanda +RD 12.03.2011 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cid001 +NA Huanda (*_*) +FA 74 +RD 27.03.2011 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept(Request(transportInfo=transport, message=message1)) datetime_mocker.set_date_time_now(DEC_2010) # Total number of identical records = 4 message1 = "cli001 +EID cli12 +FA 47 +RD 15.12.2010 +BG d +SY ace +GPS -58.3452 19.3345" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli11 +NA De'melo +FA 38 +RD 27.12.2010 +BG c +SY ba +GPS 81.672 92.33456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli13 +NA Dono`mova +FA 24 +RD 06.12.2010 +BG b +SY cd +GPS 65.23452 -28.3456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli15 +NA Aàntra +FA 89 +RD 11.12.2010 +BG a +SY bd +GPS 45.234 89.32345" response = sms_player.accept(Request(transportInfo=transport, message=message1)) datetime_mocker.set_date_time_now(NOV_2010) # Total number of identical records = 3 message1 = "cli001 +EID cli12 +NA ànnita +FA 90 +RD 07.11.2010 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli14 +NA Amanda +RD 12.11.2010 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cli8 +NA Kanda (",) +FA 34 +RD 27.11.2010 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli9 +NA ànnita +FA 90 +RD 17.11.2010 +BG b +SY bbe +GPS 45.233 28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cid007 +NA Amanda +RD 12.11.2010 +BG c +SY bd +GPS 40.2 69.3123" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = 'cli001 +EID cli8 +NA Kanda (",) +FA 34 +RD 27.11.2010 +BG d +SY be +GPS 38.3452 15.3345' response = sms_player.accept(Request(transportInfo=transport, message=message1)) datetime_mocker.set_date_time_now(PREV_MONTH) # Total number of identical records = 4 message1 = "cli001 +EID cli9 +NA Demelo +FA 38 +RD 17.05.2011 +BG c +SY ba +GPS 19.672 92.33456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli10 +NA Zorro +FA 48 +RD 05.05.2011 +BG b +SY cd +GPS 23.23452 -28.3456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli11 +NA Aàntra +FA 98 +RD 12.05.2011 +BG a +GPS -45.234 89.32345" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli12 +NA ànnita +FA 37 +RD 05.05.2011 +BG d +SY cbe +GPS -78.233 -28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli9 +NA Demelo +FA 38 +RD 17.05.2011 +BG c +SY ba +GPS 19.672 92.33456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli10 +NA Zorro +FA 48 +RD 02.05.2011 +BG b +SY cd +GPS 23.23452 -28.3456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli11 +NA Aàntra +FA 95 +RD 12.05.2011 +BG a +GPS -45.234 89.32345" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli12 +NA ànnita +FA 35 +RD 09.05.2010 +BG d +SY cbe +GPS -78.233 -28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli9 +NA Demelo +FA 32 +RD 27.05.2011 +BG c +SY ba +GPS 19.672 92.33456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli10 +NA Zorro +FA 43 +RD 05.05.2011 +BG b +SY cd +GPS 23.23452 -28.3456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli11 +NA Aàntra +FA 91 +RD 12.05.2011 +BG a +GPS -45.234 89.32345" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli12 +NA ànnita +FA 45 +RD 15.05.2010 +BG d +SY cbe +GPS -78.233 -28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) datetime_mocker.set_date_time_now(THIS_MONTH) # Total number of identical records = 4 message1 = "cli001 +EID cli13 +NA Dmanda +FA 69 +RD 05.06.2011 +BG c +SY ce +GPS 40.2 69.3123" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli14 +NA Vamand +FA 36 +RD 03.06.2011 +BG a +SY ace +GPS 58.3452 115.3345" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli15 +NA M!lo +FA 88 +RD 02.06.2011 +SY ba +GPS 19.672 92.33456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli16 +NA K!llo +FA 88 +GPS 19.672 92.33456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli13 +NA Dmanda +FA 89 +RD 04.06.2011 +BG c +SY ce +GPS 40.2 69.3123" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli14 +NA Vamand +FA 56 +RD 01.06.2011 +BG a +SY ace +GPS 58.3452 115.3345" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli15 +NA M!lo +FA 45 +RD 07.06.2011 +SY ba +GPS 19.672 92.33456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli16 +NA K!llo +FA 28 +GPS 19.672 92.33456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) datetime_mocker.end_mock() # Total number of identical records = 3 message1 = "cli001 +EID cli17 +NA Catty +FA 78 +RD 15.06.2011 +BG b +SY dce +GPS 33.23452 -68.3456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli18 +NA àntra +FA 28 +RD 12.06.2011 +BG a +SY adb +GPS -45.234 169.32345" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli9 +NA Tinnita +FA 37 +BG d +SY ace +GPS -78.233 -28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli17 +NA Catty +FA 98 +RD 25.06.2011 +BG b +SY dce +GPS 33.23452 -68.3456" response = sms_player.accept(Request(transportInfo=transport, message=message1)) message1 = "cli001 +EID cli18 +NA àntra +FA 58 +RD 22.06.2011 +BG a +SY adb +GPS -45.234 169.32345" response = sms_player.accept(Request(transportInfo= transport, message=message1)) message1 = "cli001 +EID cli9 +NA Tinnita +FA 27 +BG d +SY ace +GPS -78.233 -28.3324" response = sms_player.accept(Request(transportInfo=transport, message=message1))
def __init__(self, dbm, submission_handler, location_tree): self.dbm = dbm self.submission_handler = submission_handler self.location_tree = location_tree if self.location_tree is None: self.location_tree=get_location_tree()
def submit_to_player(incoming_request): sent_via_sms_test_questionnaire = incoming_request.get( 'test_sms_questionnaire', False) organization = incoming_request.get('organization') organization = organization try: dbm = incoming_request['dbm'] post_sms_parser_processors = [ PostSMSProcessorLanguageActivator(dbm, incoming_request), PostSMSProcessorNumberOfAnswersValidators(dbm, incoming_request) ] sms_player = SMSPlayer( dbm, LocationBridge(get_location_tree(), get_loc_hierarchy=get_location_hierarchy), post_sms_parser_processors=post_sms_parser_processors, feeds_dbm=incoming_request['feeds_dbm']) mangrove_request = Request( message=incoming_request['incoming_message'], transportInfo=incoming_request['transport_info']) response = sms_player.accept(mangrove_request, logger=incoming_request.get("logger")) if response.is_registration and not sent_via_sms_test_questionnaire: organization.increment_message_count_for(sms_registration_count=1) if not response.is_registration and sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) mail_feed_errors(response, dbm.database_name) message = SMSResponse(response).text(dbm) send_message(incoming_request, response) except DataObjectAlreadyExists as e: message = ugettext("The Unique ID Number %s is already used for the %s %s. Register your %s with a different ID.") % \ (e.data[1], e.data[2], e.data[3], e.data[2]) if not sent_via_sms_test_questionnaire: organization.increment_message_count_for(sms_registration_count=1) except DataObjectNotFound as exception: if sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) message = handle(exception, incoming_request) except FormModelDoesNotExistsException as exception: if sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) message = handle(exception, incoming_request) except Exception as exception: message = handle(exception, incoming_request) incoming_request['outgoing_message'] = message if not sent_via_sms_test_questionnaire: SMS(message=message, message_id=incoming_request['message_id'], organization=incoming_request['organization'], msg_from=mangrove_request.transport.source, msg_to=mangrove_request.transport.destination, msg_type=MSG_TYPE_SUBMISSION_REPLY, status="Submitted").save() return incoming_request
def submission(request): if request.method != 'POST': response = HttpResponse(status=204) response['Location'] = request.build_absolute_uri() return response send_to_carbon(create_path('submissions.smartphone'), 1) request_user = request.user submission_file = request.FILES.get("xml_submission_file").read() manager = get_database_manager(request_user) if not __authorized_to_make_submission_on_requested_form(request_user, submission_file, manager) \ or is_quota_reached(request): response = HttpResponse(status=403) return response player = XFormPlayerV2(manager, get_feeds_database(request_user)) try: user_profile = NGOUserProfile.objects.get(user=request_user) mangrove_request = Request( message=submission_file, transportInfo=TransportInfo(transport=SMART_PHONE, source=request_user.email, destination=''), media=request.FILES if len(request.FILES) > 1 else []) form_code, values = XFormParser(manager).parse( mangrove_request.message) form_model = get_form_model_by_code(manager, form_code) if isinstance( form_model, EntityFormModel) and form_model.is_entity_registration_form: location_tree = LocationBridge( get_location_tree(), get_loc_hierarchy=get_location_hierarchy) response = player.add_subject(form_model, values, location_tree) else: response = player.add_survey_response(mangrove_request, user_profile.reporter_id, logger=sp_submission_logger) mail_feed_errors(response, manager.database_name) if response.errors: logger.error("Error in submission : \n%s" % get_errors(response.errors)) return HttpResponseBadRequest() except MediaAttachmentNotFoundException as me: _send_media_error_mail(request, request_user, user_profile, me.message) return HttpResponseBadRequest() except DataObjectAlreadyExists as doe: send_email_for_duplicate_unique_id_registration( request, doe.data[2], doe.data[1]) return HttpResponseBadRequest() except Exception as e: logger.exception("Exception in submission : \n%s" % e) return HttpResponseBadRequest() organization = Organization.objects.get(org_id=user_profile.org_id) organization.increment_message_count_for(incoming_sp_count=1) check_quotas_and_update_users(organization) response = HttpResponse(status=201) response['Location'] = request.build_absolute_uri(request.path) return response
def create_subject(request, entity_type=None): manager = get_database_manager(request.user) form_model = get_form_model_by_entity_type(manager, [entity_type.lower()]) web_questionnaire_template = get_template(request.user) disable_link_class, hide_link_class = get_visibility_settings_for( request.user) if request.method == 'GET': questionnaire_form = SubjectRegistrationForm(form_model) form_context = _make_form_context( questionnaire_form, entity_type, disable_link_class, hide_link_class, form_model.form_code, get_organization_telephone_number(request), form_model.fields, web_view=request.GET.get("web_view", False)) form_context.update( {'is_pro_sms': get_organization(request).is_pro_sms}) return render_to_response(web_questionnaire_template, form_context, context_instance=RequestContext(request)) if request.method == 'POST': questionnaire_form = SubjectRegistrationForm( form_model, data=request.POST, country=get_organization_country(request)) if not questionnaire_form.is_valid(): form_context = _make_form_context( questionnaire_form, entity_type, disable_link_class, hide_link_class, form_model.form_code, get_organization_telephone_number(request), form_model.fields, web_view=True) return render_to_response(web_questionnaire_template, form_context, context_instance=RequestContext(request)) success_message = None error_message = None try: from datawinners.project.helper import create_request response = WebPlayer( manager, LocationBridge( location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy)).accept( create_request(questionnaire_form, request.user.username), logger=websubmission_logger) if response.success: ReportRouter().route( get_organization(request).org_id, response) success_message = _( "%s with Identification Number %s successfully registered." ) % (entity_type.capitalize(), response.short_code) detail_dict = dict({ "Subject Type": entity_type.capitalize(), "Unique ID": response.short_code }) UserActivityLog().log(request, action=REGISTERED_IDENTIFICATION_NUMBER, detail=json.dumps(detail_dict)) questionnaire_form = SubjectRegistrationForm(form_model) else: from datawinners.project.helper import errors_to_list questionnaire_form._errors = errors_to_list( response.errors, form_model.fields) form_context = _make_form_context( questionnaire_form, entity_type, disable_link_class, hide_link_class, form_model.form_code, get_organization_telephone_number(request), form_model.fields, web_view=True) return render_to_response( web_questionnaire_template, form_context, context_instance=RequestContext(request)) except DataObjectNotFound: message = exception_messages.get(DataObjectNotFound).get(WEB) error_message = _(message) % (form_model.entity_type[0], form_model.entity_type[0]) except DataObjectAlreadyExists as exception: error_message = _( "%s with ID Number '%s' already exists or has previously collected data." ) % (exception.data[2], exception.data[1]) except Exception as exception: error_message = _( get_exception_message_for(exception=exception, channel=Channel.WEB)) subject_context = _make_form_context( questionnaire_form, entity_type, disable_link_class, hide_link_class, form_model.form_code, get_organization_telephone_number(request), form_model.fields, web_view=True) subject_context.update({ 'success_message': success_message, 'error_message': error_message }) return render_to_response(web_questionnaire_template, subject_context, context_instance=RequestContext(request))
def create_subject(request, entity_type=None): manager = get_database_manager(request.user) form_model = get_form_model_by_entity_type(manager, [entity_type.lower()]) QuestionnaireForm = WebQuestionnaireFormCreator( None, form_model=form_model).create() web_questionnaire_template = get_template(request.user) disable_link_class, hide_link_class = get_visibility_settings_for( request.user) if request.method == 'GET': questionnaire_form = QuestionnaireForm() form_context = _make_form_context(questionnaire_form, entity_type, disable_link_class, hide_link_class) return render_to_response(web_questionnaire_template, form_context, context_instance=RequestContext(request)) if request.method == 'POST': questionnaire_form = QuestionnaireForm( country=get_organization_country(request), data=request.POST) if not questionnaire_form.is_valid(): form_context = _make_form_context(questionnaire_form, entity_type, disable_link_class, hide_link_class) return render_to_response(web_questionnaire_template, form_context, context_instance=RequestContext(request)) success_message = None error_message = None try: from datawinners.project.helper import create_request response = WebPlayer( manager, LocationBridge( location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy)).accept( create_request(questionnaire_form, request.user.username), logger=websubmission_logger) if response.success: ReportRouter().route( get_organization(request).org_id, response) success_message = (_( "Successfully submitted. Unique identification number(ID) is:" ) + " %s") % (response.short_code, ) detail_dict = dict({ "Subject Type": entity_type.capitalize(), "Unique ID": response.short_code }) UserActivityLog().log(request, action=REGISTERED_SUBJECT, detail=json.dumps(detail_dict)) questionnaire_form = QuestionnaireForm() else: from datawinners.project.helper import errors_to_list questionnaire_form._errors = errors_to_list( response.errors, form_model.fields) form_context = _make_form_context(questionnaire_form, entity_type, disable_link_class, hide_link_class) return render_to_response( web_questionnaire_template, form_context, context_instance=RequestContext(request)) except DataObjectNotFound: message = exception_messages.get(DataObjectNotFound).get(WEB) error_message = _(message) % (form_model.entity_type[0], form_model.entity_type[0]) except DataObjectAlreadyExists as exception: error_message = _( "Entity with Unique Identification Number (ID) = %s already exists." ) % exception.data[1] except Exception as exception: error_message = _( get_exception_message_for(exception=exception, channel=Channel.WEB)) subject_context = _make_form_context(questionnaire_form, entity_type, disable_link_class, hide_link_class) subject_context.update({ 'success_message': success_message, 'error_message': error_message }) return render_to_response(web_questionnaire_template, subject_context, context_instance=RequestContext(request))
def submit_to_player(incoming_request): sent_via_sms_test_questionnaire = incoming_request.get('test_sms_questionnaire', False) organization = incoming_request.get('organization') organization = organization should_increment_incoming_sms_count = True if not sent_via_sms_test_questionnaire else False response =None try: dbm = incoming_request['dbm'] mangrove_request = Request(message=incoming_request['incoming_message'], transportInfo=incoming_request['transport_info']) post_sms_parser_processors = [PostSMSProcessorLanguageActivator(dbm, incoming_request), PostSMSProcessorCheckDSIsRegistered(dbm, incoming_request)] if organization.in_trial_mode: post_sms_parser_processors.append(PostSMSProcessorCheckLimits(dbm, incoming_request)) post_sms_parser_processors.extend([PostSMSProcessorNumberOfAnswersValidators(dbm, incoming_request), PostSMSProcessorCheckDSIsLinkedToProject(dbm, incoming_request)]) sms_player = SMSPlayer(dbm, LocationBridge(get_location_tree(), get_loc_hierarchy=get_location_hierarchy), post_sms_parser_processors=post_sms_parser_processors, feeds_dbm=incoming_request['feeds_dbm']) response = sms_player.accept(mangrove_request, logger=incoming_request.get("logger"), translation_processor=TranslationProcessor) if response.is_registration: incoming_request['is_registration'] = True if not sent_via_sms_test_questionnaire: organization.increment_message_count_for(sms_registration_count=1) else: if sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) check_quotas_and_update_users(organization, sms_channel=True) mail_feed_errors(response, dbm.database_name) message = SMSResponse(response, incoming_request).text(dbm) send_message(incoming_request, response) except DataObjectAlreadyExists as e: message = identification_number_already_exists_handler(dbm, e.data[1], e.data[2]) if not sent_via_sms_test_questionnaire: organization.increment_message_count_for(sms_registration_count=1) except DataObjectNotFound as exception: if sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) message = handle(exception, incoming_request) except FormModelDoesNotExistsException as exception: if sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) message = incorrect_questionnaire_code_handler(dbm, exception.data[0], incoming_request) except SMSParserWrongNumberOfAnswersException: form_model = sms_player.get_form_model(mangrove_request) if not form_model.is_entity_registration_form(): if sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) message = incorrect_number_of_answers_for_submission_handler(dbm, form_model.form_code, incoming_request) elif form_model.is_entity_registration_form(): message = incorrect_number_of_answers_for_uid_registration_handler(dbm, form_model.form_code, incoming_request) except (ExceedSubmissionLimitException, ExceedSMSLimitException) as exception: should_increment_incoming_sms_count = False message = handle(exception, incoming_request) except Exception as exception: if sent_via_sms_test_questionnaire: organization.increment_message_count_for(incoming_web_count=1) message = handle(exception, incoming_request) if should_increment_incoming_sms_count: organization.increment_incoming_message_count() if response and not response.is_registration: check_quotas_and_update_users(organization, ) return post_player_handler(incoming_request, message)
def setUp(self): MangroveTestCase.setUp(self) self._create_entities() self.player = SMSPlayer(self.manager, location_tree=LocationBridge(get_location_tree(), get_loc_hierarchy=get_location_hierarchy)) self.transport = TransportInfo(transport="sms", source="1234", destination="5678") initializer.run(self.manager)
def __init__(self, dbm, submission_handler, location_tree): self.dbm = dbm self.submission_handler = submission_handler self.location_tree = location_tree if self.location_tree is None: self.location_tree = get_location_tree()
def edit_subject(request, entity_type, entity_id, project_id=None): manager = get_database_manager(request.user) form_model = get_form_model_by_entity_type(manager, [entity_type.lower()]) subject = get_by_short_code(manager, entity_id, [entity_type.lower()]) if project_id is not None: back_link = '/project/registered_subjects/%s/' % project_id else: back_link = reverse(all_subjects) for field in form_model.fields: if field.name == LOCATION_TYPE_FIELD_NAME: field.value = ','.join(subject.location_path) elif field.name == GEO_CODE_FIELD_NAME: field.value = ','.join(map(str, subject.geometry['coordinates'])) elif field.name == SHORT_CODE_FIELD: field.value = subject.short_code else: field.value = subject.data[ field.name]['value'] if field.name in subject.data.keys( ) else None field.value = field._to_str() QuestionnaireForm = WebQuestionnaireFormCreator( None, form_model=form_model).create() web_questionnaire_template = get_template(request.user) disable_link_class, hide_link_class = get_visibility_settings_for( request.user) if request.method == 'GET': questionnaire_form = QuestionnaireForm() form_context = _make_form_context(questionnaire_form, entity_type, disable_link_class, hide_link_class, True, back_link) return render_to_response(web_questionnaire_template, form_context, context_instance=RequestContext(request)) if request.method == 'POST': post_data = QueryDict(request.raw_post_data, mutable=True) post_data[ QuestionnaireForm.short_code_question_code] = subject.short_code questionnaire_form = QuestionnaireForm( country=get_organization_country(request), data=post_data) if not questionnaire_form.is_valid(): form_context = _make_form_context(questionnaire_form, entity_type, disable_link_class, hide_link_class, True, back_link) return render_to_response(web_questionnaire_template, form_context, context_instance=RequestContext(request)) success_message = None error_message = None try: from datawinners.project.helper import create_request response = WebPlayer( manager, LocationBridge( location_tree=get_location_tree(), get_loc_hierarchy=get_location_hierarchy)).accept( create_request(questionnaire_form, request.user.username, is_update=True)) if response.success: success_message = _("Your changes have been saved.") questionnaire_form = QuestionnaireForm( country=get_organization_country(request), data=post_data) else: from datawinners.project.helper import errors_to_list questionnaire_form._errors = errors_to_list( response.errors, form_model.fields) form_context = _make_form_context(questionnaire_form, entity_type, disable_link_class, hide_link_class, True, back_link) return render_to_response( web_questionnaire_template, form_context, context_instance=RequestContext(request)) except DataObjectNotFound: message = exception_messages.get(DataObjectNotFound).get(WEB) error_message = _(message) % (form_model.entity_type[0], form_model.entity_type[0]) except Exception as exception: error_message = _( get_exception_message_for(exception=exception, channel=Channel.WEB)) subject_context = _make_form_context(questionnaire_form, entity_type, disable_link_class, hide_link_class, True, back_link) subject_context.update({ 'success_message': success_message, 'error_message': error_message }) return render_to_response(web_questionnaire_template, subject_context, context_instance=RequestContext(request))