def after_show(self, context, pkg_dict): if not self.is_supported_package_type(pkg_dict): return pkg_dict pkg_dict = self._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] = sh.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, }) return pkg_dict
def after_show(self, context, pkg_dict): if not self.is_supported_package_type(pkg_dict): return pkg_dict pkg_dict = self._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] = 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, } ) return pkg_dict
def _extract_lang_value(self, value, lang_code): new_value = sh.parse_json(value) if isinstance(new_value, dict): return sh.get_localized_value(new_value, lang_code, default_value='') return value
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 after_show(self, context, pkg_dict): if not self.is_supported_package_type(pkg_dict): return # 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] = parse_json(group[field]) # organization if pkg_dict['organization'] is not None: for field in pkg_dict['organization']: pkg_dict['organization'][field] = parse_json( pkg_dict['organization'][field] )
def _package_parse_json_strings(self, pkg_dict): # try to parse all values as JSON for key, value in pkg_dict.iteritems(): pkg_dict[key] = sh.parse_json(value) # groups if 'groups' in pkg_dict and 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] = sh.parse_json(group[field]) # organization if 'organization' in pkg_dict and pkg_dict['organization'] is not None: for field in pkg_dict['organization']: pkg_dict['organization'][field] = sh.parse_json( pkg_dict['organization'][field]) return pkg_dict
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_datetime(temporal[key]) else: temporal[key] = None return value
def _package_parse_json_strings(self, pkg_dict): # try to parse all values as JSON for key, value in pkg_dict.iteritems(): pkg_dict[key] = parse_json(value) # groups if 'groups' in pkg_dict and 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] = parse_json(group[field]) # organization if 'organization' in pkg_dict and pkg_dict['organization'] is not None: for field in pkg_dict['organization']: pkg_dict['organization'][field] = parse_json( pkg_dict['organization'][field] ) return pkg_dict
def before_view(self, pkg_dict): # try to parse all values as JSON for key, value in pkg_dict.iteritems(): pkg_dict[key] = parse_json(value) # read pylons values if available try: path = pylons.request.path desired_lang_code = pylons.request.environ['CKAN_LANG'] except TypeError: return pkg_dict # Do not change the resulting dict for API requests if path.startswith('/api'): return pkg_dict pkg_dict['display_name'] = pkg_dict['title'] for key, value in pkg_dict.iteritems(): if not self._ignore_field(key): pkg_dict[key] = self._extract_lang_value( value, desired_lang_code ) return pkg_dict
def _extract_lang_value(self, value, lang_code): new_value = parse_json(value) if isinstance(new_value, dict): return get_localized_value(new_value, lang_code, default_value='') return value
def multiple_text_output(value): """ Return stored json representation as a list """ return parse_json(value, default_value=[value])