Esempio n. 1
0
 def _append_country_for_location_field(self, form_model, values, organization):
     location_field_code = get_location_field_code(form_model)
     if location_field_code is None:
         return values
     if location_field_code in values and values[location_field_code]:
         values[location_field_code] = get_country_appended_location(values[location_field_code],
                                                                     organization.country_name())
     return values
    def clean(self):
        location_field_code = get_location_field_code(self.form_model)

        if location_field_code is None:
            return self.cleaned_data

        for question_code, values in self.cleaned_data.items():
            if question_code == location_field_code:
                self.cleaned_data[question_code] = get_country_appended_location(values, self.country)

        return self.cleaned_data
Esempio n. 3
0
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 test_should_not_append_country_if_location_hierarchy_is_empty(self):
     country_appended_location = get_country_appended_location(u'', 'India')
     self.assertEqual('', country_appended_location)
 def test_should_not_append_country_in_case_location_hierarchy_already_has_it(
         self):
     country_appended_location = get_country_appended_location(
         'Pune , India', 'India')
     self.assertEqual('Pune,India', country_appended_location)