Exemple #1
0
def ogdch_prepare_pkg_dict_for_api(pkg_dict):
    if not _is_dataset_package_type(pkg_dict):
        return pkg_dict

    pkg_dict = package_map_ckan_default_fields(pkg_dict)

    # groups
    if pkg_dict['groups'] is not None:
        for group in pkg_dict['groups']:
            """
            TODO: somehow the title is messed up here,
            but the display_name is okay
            """
            group['title'] = group['display_name']
            for field in group:
                group[field] = ogdch_loc_utils.parse_json(group[field])

    # load organization from API to get all fields defined in schema
    # by default, CKAN loads organizations only from the database
    if pkg_dict['owner_org'] is not None:
        pkg_dict['organization'] = logic.get_action('organization_show')(
            {}, {
                'id': pkg_dict['owner_org'],
                'include_users': False,
                'include_followers': False,
            })

    if ogdch_request_utils.request_is_api_request():
        _transform_package_dates(pkg_dict)
        _transform_publisher(pkg_dict)
    return pkg_dict
Exemple #2
0
def multilingual_text_output(value):
    """
    Return stored json representation as a multilingual dict, if
    value is already a dict just pass it through.
    """
    if isinstance(value, dict):
        return value
    return parse_json(value)
 def test_parse_json_error_and_default_value(self):
     """if an error occurs the value should be returned as is"""
     value = u"{Hallo"
     default_value = "Hello world"
     self.assertEqual(
         ogdch_localize_utils.parse_json(value,
                                         default_value=default_value),
         default_value)
def temporals_display(value):
    """
    Converts a temporal with start and end date
    as timestamps to temporal as datetimes
    """
    value = parse_json(value)
    if not isinstance(value, list):
        return ''
    for temporal in value:
        for key in temporal:
            if temporal[key] is not None:
                temporal[key] = ogdch_date_output(temporal[key])
    return value
Exemple #5
0
def temporals_to_datetime_output(value):
    """
    Converts a temporal with start and end date
    as timestamps to temporal as datetimes
    """
    value = parse_json(value)

    for temporal in value:
        for key in temporal:
            if temporal[key]:
                temporal[key] = timestamp_to_date_string(temporal[key])
            else:
                temporal[key] = None
    return value
Exemple #6
0
def multiple_text_output(value):
    """
    Return stored json representation as a list
    """
    return parse_json(value, default_value=[value])
 def test_parse_json_without_error(self):
     """if an error occurs the default value should be returned"""
     value = '{"de": "Hallo", "it": "okay"}'
     value_as_dict = {"de": "Hallo", "it": "okay"}
     self.assertEqual(ogdch_localize_utils.parse_json(value), value_as_dict)
 def test_parse_json_with_error(self):
     """if an error occurs the default value should be returned"""
     value = u"{Hallo"
     self.assertEqual(ogdch_localize_utils.parse_json(value), value)