def update_links(self, source, target): base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) site_root = self.get_site_root() languages = site_root.get_property('website_languages') links = [] 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 = _change_link(source, target, old_base, new_base, events) 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 path = str(old_base.resolve2(path)) if path == source: # Hit the old name new_path = str(new_base.get_pathto(target)) 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 path = str(path) path = resources_new2old.get(path, path) if path == source: # Hit the old name self.set_property(key, str(target), language=lang) # Tagaware ? if isinstance(self, TagsAware): TagsAware.update_links(self, source, target) # Change resource get_context().database.change_resource(self)
def update_links(self, source, target): Folder.update_links(self, source, target) TagsAware.update_links(self, source, target) base = self.get_canonical_path() resources_new2old = get_context().database.resources_new2old base = str(base) old_base = resources_new2old.get(base, base) old_base = Path(old_base) new_base = Path(base) # metadata schema = self.class_schema for key, datatype in schema.iteritems(): if issubclass(datatype, PathDataType) is False: continue value = self.get_property(key) if not value: continue ref = get_reference(value) if ref.scheme: continue path, view = get_path_and_view(ref.path) path = str(old_base.resolve2(path)) if path == source: # Hit the old name # Build the new path with the right path new_path = str(new_base.get_pathto(target)) + view self.set_property(key, Path(new_path)) # comments comments = self.metadata.get_property('comment') or [] for comment in comments: # XXX hardcoded, not typed for key in ('attachment',): value = comment.get_parameter(key) if not value: continue ref = get_reference(value) if ref.scheme: continue path, view = get_path_and_view(ref.path) path = str(old_base.resolve2(path)) if path == source: # Hit the old name # Build the new path with the right path new_path = str(new_base.get_pathto(target)) + view comment.set_parameter(key, new_path) self.set_property('comment', comments)