def update_relative_links(self, source): super(TurningFooterTable, self).update_relative_links(source) target = self.get_canonical_path() # languages site_root = self.get_site_root() available_languages = site_root.get_property('website_languages') resources_old2new = get_context().database.resources_old2new def my_func(value): # Absolute URI or path uri = get_reference(value) if uri.scheme or uri.authority or uri.path.is_absolute(): return value path = uri.path if not path or path.is_absolute() and path[0] == 'ui': return value # Strip the view path, view = get_path_and_view(path) # Resolve Path # Calcul the old absolute path old_abs_path = source.resolve2(path) # Get the 'new' absolute parth new_abs_path = resources_old2new.get(old_abs_path, old_abs_path) path = str(target.get_pathto(new_abs_path)) + view value = Reference('', '', path, uri.query.copy(), uri.fragment) return str(value) handler = self.handler get_value = handler.get_record_value for record in handler.get_records_in_order(): for language in available_languages: data = get_value(record, 'data', language=language) if data is None: continue events = rewrite_uris(data, my_func) events = list(events) p_events = Property(events, language=language) # TODO Update all language in one time self.update_record(record.id, **{'data': p_events})
def update_relative_links(self, source): super(FooterMenu, self).update_relative_links(source) target = self.get_canonical_path() site_root = self.get_site_root() available_languages = site_root.get_property("website_languages") resources_old2new = get_context().database.resources_old2new def my_func(value): # Absolute URI or path uri = get_reference(value) if uri.scheme or uri.authority or uri.path.is_absolute(): return value path = uri.path if not path or path.is_absolute() and path[0] == "ui": return value # Strip the view path, view = get_path_and_view(path) # Resolve Path # Calcul the old absolute path old_abs_path = source.resolve2(path) # Get the 'new' absolute parth new_abs_path = resources_old2new.get(old_abs_path, old_abs_path) path = str(target.get_pathto(new_abs_path)) + view value = Reference("", "", path, uri.query.copy(), uri.fragment) return str(value) handler = self.handler get_value = handler.get_record_value for record in handler.get_records_in_order(): properties = [] for language in available_languages: html_content = get_value(record, "html_content", language=language) if html_content is None: continue events = rewrite_uris(html_content, my_func) events = list(events) properties.append(Property(events, language=language)) self.update_record(record.id, **{"html_content": properties})
def update_incoming_links(self, resource, field_name, source, languages): target = resource.abspath resources_old2new = resource.database.resources_old2new def my_func(value): # Skip empty links, external links and links to '/ui/' uri = get_reference(value) if uri.scheme or uri.authority or uri.path.is_absolute(): return value path = uri.path if not path or path.is_absolute() and path[0] == 'ui': return value # Strip the view name = path.get_name() if name and name[0] == ';': view = '/' + name path = path[:-1] else: view = '' # Resolve Path # Calcul the old absolute path old_abs_path = source.resolve2(path) # Get the 'new' absolute parth new_abs_path = resources_old2new.get(old_abs_path, old_abs_path) path = str(target.get_pathto(new_abs_path)) + view value = Reference('', '', path, uri.query.copy(), uri.fragment) return str(value) for language in languages: handler = self.get_value(resource, field_name, language) if not handler or handler.database.is_phantom(handler): continue events = rewrite_uris(handler.events, my_func) events = list(events) handler.set_changed() handler.events = events
def filter(path, mimetype, body): # HTML if mimetype == 'text/html': source = XHTMLFile(string=body) target = XHTMLFile() elem = get_element(source.events, 'div', **{'class': 'body'}) if not elem: print 'E', path return None elements = elem.get_content_elements() elements = rewrite_uris(elements, rewrite) elements = list(elements) target.set_body(elements) return target.to_str() # Skip elif mimetype in skip: return None # Keep elif mimetype in keep: return body # Unknown else: print 'X', path, mimetype return body
def filter(path, mimetype, body): # HTML if mimetype == "text/html": source = XHTMLFile(string=body) target = XHTMLFile() elem = get_element(source.events, "div", **{"class": "body"}) if not elem: print "E", path return None elements = elem.get_content_elements() elements = rewrite_uris(elements, rewrite) elements = list(elements) target.set_body(elements) return target.to_str() # Skip elif mimetype in skip: return None # Keep elif mimetype in keep: return body # Unknown else: print "X", path, mimetype return body
def update_relative_links(self, source): target = self.get_canonical_path() resources_old2new = get_context().database.resources_old2new resources_new2old = get_context().database.resources_new2old def my_func(value): # Skip empty links, external links and links to '/ui/' uri = get_reference(value) if uri.scheme or uri.authority or uri.path.is_absolute(): return value path = uri.path if not path or path.is_absolute() and path[0] == 'ui': return value # Strip the view name = path.get_name() if name and name[0] == ';': view = '/' + name path = path[:-1] else: view = '' # Resolve Path # Calcul the old absolute path old_abs_path = source.resolve2(path) # Get the 'new' absolute parth new_abs_path = resources_old2new.get(old_abs_path, old_abs_path) path = str(target.get_pathto(new_abs_path)) + view value = Reference('', '', path, uri.query.copy(), uri.fragment) return str(value) languages = self.get_site_root().get_property('website_languages') for key, datatype in self.get_metadata_schema().items(): multilingual = getattr(datatype, 'multilingual', False) langs = languages if multilingual is True else [None] if issubclass(datatype, XHTMLBody): for lang in langs: events = self.get_property(key, language=lang) if not events: continue events = rewrite_uris(events, my_func) events = list(events) self.set_property(key, events, language=lang) elif issubclass(datatype, PathDataType): # Relative path for lang in langs: path = self.get_property(key, language=lang) if path is None: continue # Calcul the old absolute path old_abs_path = source.resolve2(path) # Check if the target path has not been moved new_abs_path = resources_old2new.get(old_abs_path, old_abs_path) # Build the new path # Absolute path allow to call get_pathto with the target new_path = str(target.get_pathto(new_abs_path)) self.set_property(key, new_path, language=lang) elif issubclass(datatype, AbsolutePathDataTypeEnumerate): # Absolute path for lang in langs: path = self.get_property(key, language=lang) if path is None: continue # Calcul the old absolute path path = str(path) old_abs_path = resources_new2old.get(path, path) # Check if the target path has not been moved new_abs_path = resources_old2new.get(old_abs_path, old_abs_path) self.set_property(key, new_abs_path, language=lang)