def get_resource_processed_info(self, base=None, lang=None): info = deepcopy(self.get_resource_info()) if base is None: base = self.base if lang is None: from django.utils import translation lang = translation.get_language() variables = {} if info['type'] in ('widget', 'operator'): for pref in info['preferences']: variables[pref['name']] = pref for prop in info['properties']: variables[prop['name']] = prop for inputendpoint in info['wiring']['inputs']: variables[inputendpoint['name']] = inputendpoint for outputendpoint in info['wiring']['outputs']: variables[outputendpoint['name']] = outputendpoint # process translations if len(info['translations']) > 0: translation = info['translations'][info['default_lang']] if lang in info['translations']: translation.update(info['translations'][lang]) for index in translation: value = translation[index] usages = info['translation_index_usage'][index] for use in usages: if use['type'] == 'resource': info[use['field']] = info[use['field']].replace('__MSG_' + index + '__', value) elif use['type'] == 'vdef': variable = variables[use['variable']] for field in variable: if isinstance(variable[field], basestring): variable[field] = variable[field].replace('__MSG_' + index + '__', value) elif use['type'] == 'upo': variable = variables[use['variable']] for option in variable['options']: for field in option: if isinstance(option[field], basestring): option[field] = option[field].replace('__MSG_' + index + '__', value) del info['translations'] del info['translation_index_usage'] # process url fields for field in BASIC_URL_FIELDS: info[field] = absolutize_url_field(info[field], base) if info['type'] == 'widget': info['code_url'] = absolutize_url_field(info['code_url'], base) elif info['type'] == 'operator': info['js_files'] = [absolutize_url_field(js_file, base) for js_file in info['js_files']] return info
def get_resource_processed_info(self, base=None, lang=None): info = self.get_resource_info() if base is None: base = self.base if lang is None: from django.utils import translation lang = translation.get_language() variables = {} if info['type'] in ('widget', 'operator'): for pref in info['preferences']: variables[pref['name']] = pref for prop in info['properties']: variables[prop['name']] = prop for inputendpoint in info['wiring']['inputs']: variables[inputendpoint['name']] = inputendpoint for outputendpoint in info['wiring']['outputs']: variables[outputendpoint['name']] = outputendpoint # process translations if len(info['translations']) > 0: translation = info['translations'][info['default_lang']] if lang in info['translations']: translation.update(info['translations'][lang]) for index in translation: value = translation[index] usages = info['translation_index_usage'][index] for use in usages: if use['type'] == 'resource': info[use['field']] = info[use['field']].replace('__MSG_' + index + '__', value) elif use['type'] == 'vdef': variable = variables[use['variable']] for field in variable: if isinstance(variable[field], basestring): variable[field] = variable[field].replace('__MSG_' + index + '__', value) elif use['type'] == 'upo': variable = variables[use['variable']] for option in variable['options']: for field in option: if isinstance(option[field], basestring): option[field] = option[field].replace('__MSG_' + index + '__', value) # process url fields for field in self._parser._url_fields: value = info[field] if value.strip() != '': info[field] = urlparse.urljoin(base, value) return info
def get_resource_processed_info(self, base=None, lang=None, process_urls=True, translate=True, process_variables=False): info = deepcopy(self.get_resource_info()) if translate and lang is None: from django.utils import translation lang = translation.get_language() variables = {} if info['type'] in ('widget', 'operator'): for pref in info['preferences']: variables[pref['name']] = pref for prop in info['properties']: variables[prop['name']] = prop for inputendpoint in info['wiring']['inputs']: variables[inputendpoint['name']] = inputendpoint for outputendpoint in info['wiring']['outputs']: variables[outputendpoint['name']] = outputendpoint # process translations if translate and len(info['translations']) > 0: translation = info['translations'][info['default_lang']] if lang in info['translations']: translation.update(info['translations'][lang]) for index in translation: value = translation[index] usages = info['translation_index_usage'][index] for use in usages: if use['type'] == 'resource': info[use['field']] = info[use['field']].replace('__MSG_' + index + '__', value) elif use['type'] in ('vdef', 'inputendpoint', 'outputendpoint'): variable = variables[use['variable']] for field in variable: if isinstance(variable[field], six.string_types): variable[field] = variable[field].replace('__MSG_' + index + '__', value) elif use['type'] == 'upo': variable = variables[use['variable']] for option in variable['options']: for field in option: if isinstance(option[field], six.string_types): option[field] = option[field].replace('__MSG_' + index + '__', value) del info['translations'] del info['translation_index_usage'] # Provide a fallback for the title if info['title'] == '': info['title'] = info['name'] # Process resource variables if process_variables and info['type'] in ('widget', 'operator'): info['variables'] = { 'all': {}, 'preferences': {}, 'properties': {}, } for vardef in info['preferences']: info['variables']['all'][vardef['name']] = vardef info['variables']['preferences'][vardef['name']] = vardef for vardef in info['properties']: info['variables']['all'][vardef['name']] = vardef info['variables']['properties'][vardef['name']] = vardef if process_urls is False: return info if base is None: base = self.base # process url fields for field in BASIC_URL_FIELDS: info[field] = absolutize_url_field(info[field], base) if info['type'] == 'widget': info['contents']['src'] = absolutize_url_field(info['contents']['src'], base) for altcontent in info['altcontents']: altcontent['src'] = absolutize_url_field(altcontent['src'], base) elif info['type'] == 'operator': info['js_files'] = [absolutize_url_field(js_file, base) for js_file in info['js_files']] return info
def get_resource_processed_info(self, base=None, lang=None, process_urls=True, translate=True, process_variables=False): info = deepcopy(self.get_resource_info()) if translate and lang is None: from django.utils import translation lang = translation.get_language() variables = {} if info['type'] in ('widget', 'operator'): for pref in info['preferences']: variables[pref['name']] = pref for prop in info['properties']: variables[prop['name']] = prop for inputendpoint in info['wiring']['inputs']: variables[inputendpoint['name']] = inputendpoint for outputendpoint in info['wiring']['outputs']: variables[outputendpoint['name']] = outputendpoint # process translations if translate and len(info['translations']) > 0: translation = info['translations'][info['default_lang']] if lang in info['translations']: translation.update(info['translations'][lang]) for index in translation: value = translation[index] usages = info['translation_index_usage'][index] for use in usages: if use['type'] == 'resource': info[use['field']] = info[use['field']].replace( '__MSG_' + index + '__', value) elif use['type'] in ('vdef', 'inputendpoint', 'outputendpoint'): variable = variables[use['variable']] for field in variable: if isinstance(variable[field], six.string_types): variable[field] = variable[field].replace( '__MSG_' + index + '__', value) elif use['type'] == 'upo': variable = variables[use['variable']] for option in variable['options']: for field in option: if isinstance(option[field], six.string_types): option[field] = option[field].replace( '__MSG_' + index + '__', value) del info['translations'] del info['translation_index_usage'] # Provide a fallback for the title if info['title'] == '': info['title'] = info['name'] # Process resource variables if process_variables and info['type'] in ('widget', 'operator'): info['variables'] = { 'all': {}, 'preferences': {}, 'properties': {}, } for vardef in info['preferences']: info['variables']['all'][vardef['name']] = vardef info['variables']['preferences'][vardef['name']] = vardef for vardef in info['properties']: info['variables']['all'][vardef['name']] = vardef info['variables']['properties'][vardef['name']] = vardef if process_urls is False: return info if base is None: base = self.base # process url fields for field in BASIC_URL_FIELDS: info[field] = absolutize_url_field(info[field], base) if info['type'] == 'widget': info['contents']['src'] = absolutize_url_field( info['contents']['src'], base) for altcontent in info['altcontents']: altcontent['src'] = absolutize_url_field( altcontent['src'], base) elif info['type'] == 'operator': info['js_files'] = [ absolutize_url_field(js_file, base) for js_file in info['js_files'] ] return info
def get_resource_processed_info( self, base=None, lang=None, process_urls=True, translate=True, process_variables=False ): info = deepcopy(self.get_resource_info()) if translate and lang is None: from django.utils import translation lang = translation.get_language() variables = {} if info["type"] in ("widget", "operator"): for pref in info["preferences"]: variables[pref["name"]] = pref for prop in info["properties"]: variables[prop["name"]] = prop for inputendpoint in info["wiring"]["inputs"]: variables[inputendpoint["name"]] = inputendpoint for outputendpoint in info["wiring"]["outputs"]: variables[outputendpoint["name"]] = outputendpoint # process translations if translate and len(info["translations"]) > 0: translation = info["translations"][info["default_lang"]] if lang in info["translations"]: translation.update(info["translations"][lang]) for index in translation: value = translation[index] usages = info["translation_index_usage"][index] for use in usages: if use["type"] == "resource": info[use["field"]] = info[use["field"]].replace("__MSG_" + index + "__", value) elif use["type"] in ("vdef", "inputendpoint", "outputendpoint"): variable = variables[use["variable"]] for field in variable: if isinstance(variable[field], six.string_types): variable[field] = variable[field].replace("__MSG_" + index + "__", value) elif use["type"] == "upo": variable = variables[use["variable"]] for option in variable["options"]: for field in option: if isinstance(option[field], six.string_types): option[field] = option[field].replace("__MSG_" + index + "__", value) del info["translations"] del info["translation_index_usage"] # Provide a fallback for the title if info["title"] == "": info["title"] = info["name"] # Process resource variables if process_variables and info["type"] in ("widget", "operator"): info["variables"] = {"all": {}, "preferences": {}, "properties": {}} for vardef in info["preferences"]: info["variables"]["all"][vardef["name"]] = vardef info["variables"]["preferences"][vardef["name"]] = vardef for vardef in info["properties"]: info["variables"]["all"][vardef["name"]] = vardef info["variables"]["properties"][vardef["name"]] = vardef if process_urls is False: return info if base is None: base = self.base # process url fields for field in BASIC_URL_FIELDS: info[field] = absolutize_url_field(info[field], base) if info["type"] == "widget": info["contents"]["src"] = absolutize_url_field(info["contents"]["src"], base) for altcontent in info["altcontents"]: altcontent["src"] = absolutize_url_field(altcontent["src"], base) elif info["type"] == "operator": info["js_files"] = [absolutize_url_field(js_file, base) for js_file in info["js_files"]] return info