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 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 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 multiple_text_output(value): """ Return stored json representation as a list """ return parse_json(value, default_value=[value])
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