def site_cloned(site, event): """If a `INySite` was pasted check the `__before_traverse__` for old object's values and delete them. For example:: >>> portal.__before_traverse__ { (99, 'Localizer'): <ZPublisher.BeforeTraverse.NameCaller>, (99, 'Naaya Site/copy_of_portal'): <ZPublisher.BeforeTraverse.NameCaller>, (99, 'Naaya Site/portal'): <ZPublisher.BeforeTraverse.NameCaller> } From the above example the last value (original object) in the dict should be removed because the before_traverse hooks will use that instead of new object's value. """ btr = {} for name, ob in site.__before_traverse__.items(): # Check if it is of the same content type if site.meta_type in name[1]: # Leave the current object and remove the old one if ("%s/%s" % (site.meta_type, site.id) == name[1]): btr[name] = ob else: btr[name] = ob #Override __before_traverse__ rewriteBeforeTraverse(site, btr)
def _cvt_btr(app): stack = [app] while stack: o = stack.pop() ov = getattr(o, 'objectValues', None) if ov is not None: stack.extend(list(ov())) btr = getattr(o, '__before_traverse__', None) if btr and type(btr) == type({}): touched = 0 for k, v in btr.items(): if type(v) is type(''): touched = 1 if k[1] == 'AccessRule': btr[k] = AccessRule(v) else: btr[k] = NameCaller(v) if touched: rewriteBeforeTraverse(o, btr)