def undelete(context, request): repo = find_repo(context) docid = int(request.params['docid']) name = request.params['name'] doc = _undelete(repo, context, docid, name) repo.archive_container(IContainerVersion(context), authenticated_userid(request)) index_content(context, None) return HTTPFound(location=model_url(doc, request))
def _restore_subtree(repo, parent, request): try: contents = repo.container_contents(parent.docid) except NoResultFound: pass else: for child_name, child_docid in contents.map.items(): doc = _restore(repo, parent, child_docid, child_name) _restore_subtree(repo, doc, request) repo.archive_container(IContainerVersion(parent), authenticated_userid(request)) index_content(parent, None)
def undelete(context, request): repo = find_repo(context) path = decode_trash_path(request.params['path']) parent = context for name, docid, _ in traverse_trash(context, path): try: doc = parent[name] except KeyError: doc = None if doc is None or doc.docid != docid: # Restore this item. doc = _restore(repo, parent, docid, name) repo.archive_container(IContainerVersion(parent), authenticated_userid(request)) index_content(parent, None) parent = doc # If the user undeleted a container, restore everything it contained. _restore_subtree(repo, parent, request) return HTTPFound(location=resource_url(parent, request))
def undelete(context, request): repo = find_repo(context) docid = int(request.params['docid']) name = request.params['name'] # Find parent folder to restore file into trash = generate_trash_tree(repo, context.docid) parent = context for child_docid in trash.paths[docid][:-1]: for child in parent.values(): if child.docid == child_docid: next_parent = child break else: # Need to restore a folder in order to place file in proper place # in tree. container = repo.container_contents(parent.docid) for deleted_item in container.deleted: if deleted_item.docid == child_docid: next_parent = _undelete(repo, parent, child_docid, deleted_item.name, False) repo.archive_container(IContainerVersion(parent), authenticated_userid(request)) break else: #pragma NO COVERAGE # Will only get here in case of programmer error or db # corruption (due to programmer error) raise RuntimeError("Cannot find container to restore: %d" % child_docid) parent = next_parent doc = _undelete(repo, parent, docid, name, True) repo.archive_container(IContainerVersion(parent), authenticated_userid(request)) index_content(parent, None) return HTTPFound(location=resource_url(parent, request))
def _callFUT(self, object, event): from karl.models.subscribers import index_content return index_content(object, event)
def evolve(context): root = find_root(context) searcher = ICatalogSearch(root) categories_and_layers_query = dict( interfaces={'query':[ICalendarCategory, ICalendarLayer], 'operator':'or'}, ) total, docids, resolver = searcher(**categories_and_layers_query) changed_categories = {} for docid in docids: ob = resolver(docid) if ob is None: # slash in path, likely path = root.catalog.document_map.docid_to_address.get(docid) if path is not None: container_path, ob_name = path.rsplit('/', 1) container = find_model(root, container_path) name = urllib.unquote(ob_name) ob = container.get(name) if ob is not None: ob_name = ob.__name__ if not (ob_name.startswith('_default_') or is_opaque_id(ob_name)): old_path = model_path(ob) container = ob.__parent__ new_name = generate_name(container) del container[ob_name] ob.__name__ = new_name # XXX required? container.add(new_name, ob, send_events=False) new_path = model_path(ob) index_content(ob, None) print 'path fixed: %s -> %s' % (old_path, new_path) if ICalendarCategory.providedBy(ob): changed_categories[old_path] = new_path if changed_categories: # fix layer.paths layers_query = dict(interfaces=[ICalendarLayer]) total, docids, resolver = searcher(**layers_query) for docid in docids: layer = resolver(docid) if layer is not None: new_paths = [] changed = [] for path in layer.paths: if path in changed_categories: new_paths.append(changed_categories[path]) changed.append((path, changed_categories[path])) else: new_paths.append(path) if changed: layer.paths = new_paths reindex_content(layer, None) print 'layer fixed: %s, %s' % ( model_path(layer), [ '%s -> %s' % x for x in changed ]) # fix the category of events events_query = dict( interfaces=[ICalendarEvent], ) total, docids, resolver = searcher(**events_query) for docid in docids: event = resolver(docid) if event is not None: category = event.calendar_category if category in changed_categories: old_category = event.calendar_category new_category = changed_categories[category] event.calendar_category = new_category reindex_content(event, None) print 'event fixed: %s, %s -> %s' % ( model_path(event), old_category, new_category)
def evolve(context): root = find_root(context) searcher = ICatalogSearch(root) categories_and_layers_query = dict(interfaces={ 'query': [ICalendarCategory, ICalendarLayer], 'operator': 'or' }, ) total, docids, resolver = searcher(**categories_and_layers_query) changed_categories = {} for docid in docids: ob = resolver(docid) if ob is None: # slash in path, likely path = root.catalog.document_map.docid_to_address.get(docid) if path is not None: container_path, ob_name = path.rsplit('/', 1) container = find_resource(root, container_path) name = urllib.unquote(ob_name) ob = container.get(name) if ob is not None: ob_name = ob.__name__ if not (ob_name.startswith('_default_') or is_opaque_id(ob_name)): old_path = resource_path(ob) container = ob.__parent__ new_name = generate_name(container) del container[ob_name] ob.__name__ = new_name # XXX required? container.add(new_name, ob, send_events=False) new_path = resource_path(ob) index_content(ob, None) print 'path fixed: %s -> %s' % (old_path, new_path) if ICalendarCategory.providedBy(ob): changed_categories[old_path] = new_path if changed_categories: # fix layer.paths layers_query = dict(interfaces=[ICalendarLayer]) total, docids, resolver = searcher(**layers_query) for docid in docids: layer = resolver(docid) if layer is not None: new_paths = [] changed = [] for path in layer.paths: if path in changed_categories: new_paths.append(changed_categories[path]) changed.append((path, changed_categories[path])) else: new_paths.append(path) if changed: layer.paths = new_paths reindex_content(layer, None) print 'layer fixed: %s, %s' % (resource_path(layer), [ '%s -> %s' % x for x in changed ]) # fix the category of events events_query = dict(interfaces=[ICalendarEvent], ) total, docids, resolver = searcher(**events_query) for docid in docids: event = resolver(docid) if event is not None: category = event.calendar_category if category in changed_categories: old_category = event.calendar_category new_category = changed_categories[category] event.calendar_category = new_category reindex_content(event, None) print 'event fixed: %s, %s -> %s' % ( resource_path(event), old_category, new_category)