def _get_recent_changes(): site = web.ctx.get('site') or delegate.create_site() web.ctx.setdefault("ip", "127.0.0.1") # The recentchanges can have multiple revisions for a document if it has been modified more than once. # Take only the most recent revision in that case. visited = set() def is_visited(key): if key in visited: return True else: visited.add(key) return False # ignore reverts re_revert = web.re_compile(r"reverted to revision \d+") def is_revert(r): return re_revert.match(r.comment or "") # take the 100 recent changes, filter them and take the first 50 q = {"bot": False, "limit": 100} result = site.versions(q) result = [r for r in result if not is_visited(r.key) and not is_revert(r)] result = result[:50] def process_thing(thing): t = web.storage() for k in ["key", "title", "name", "displayname"]: t[k] = thing[k] t['type'] = web.storage(key=thing.type.key) return t for r in result: r.author = r.author and process_thing(r.author) r.thing = process_thing(site.get(r.key, r.revision)) return result
def _get_recent_changes(): site = web.ctx.get('site') or delegate.create_site() web.ctx.setdefault("ip", "127.0.0.1") # The recentchanges can have multiple revisions for a document if it has been modified more than once. # Take only the most recent revision in that case. visited = set() def is_visited(key): if key in visited: return True else: visited.add(key) return False # ignore reverts re_revert = web.re_compile("reverted to revision \d+") def is_revert(r): return re_revert.match(r.comment or "") # take the 100 recent changes, filter them and take the first 50 q = {"bot": False, "limit": 100} result = site.versions(q) result = [r for r in result if not is_visited(r.key) and not is_revert(r)] result = result[:50] def process_thing(thing): t = web.storage() for k in ["key", "title", "name", "displayname"]: t[k] = thing[k] t['type'] = web.storage(key=thing.type.key) return t for r in result: r.author = r.author and process_thing(r.author) r.thing = process_thing(site.get(r.key, r.revision)) return result