Comment 8 for bug 364191

Revision history for this message
Edward Betts (edwardbetts) wrote :

Here is my implementation of this feature. These two lines need to be in /macros/RecentChanges:

$ bot = query_param('bot', None)
$ changes = get_recent_changes(author=author, ip=ip, type=type, bot=bot, limit=limit, offset=page * limit)

To show only bot edits go to: /recentchanges?bot=only
To hide bot edits go to: /recentchanges?bot=hide

Below is a patch to infogami. In this implementation a user is considered to be a bot if the username ends in 'Bot'. This could be changed to check a usergroup or a bot flag in /type/user.

diff --git a/infogami/core/db.py b/infogami/core/db.py
index 7d9bf73..b6d98c2 100644
--- a/infogami/core/db.py
+++ b/infogami/core/db.py
@@ -52,7 +52,7 @@ def get_user_preferences(user):
     return get_version(user.key + '/preferences')

 @public
-def get_recent_changes(key=None, author=None, ip=None, type=None, limit=None, offset=None):
+def get_recent_changes(key=None, author=None, ip=None, type=None, bot=None, limit=None, offset=None):
     q = {'sort': '-created'}
     if key is not None:
         q['key'] = key
@@ -68,6 +68,8 @@ def get_recent_changes(key=None, author=None, ip=None, type=None, limit=None, of

     q['limit'] = limit or 100
     q['offset'] = offset or 0
+ if bot:
+ q['bot'] = bot
     result = web.ctx.site.versions(q)
     for r in result:
         r.thing = web.ctx.site.get(r.key, r.revision, lazy=True)
diff --git a/infogami/infobase/dbstore.py b/infogami/infobase/dbstore.py
index f21a054..86b4543 100644
--- a/infogami/infobase/dbstore.py
+++ b/infogami/infobase/dbstore.py
@@ -568,6 +568,15 @@ class DBSiteStore(common.SiteStore):
                 key = 'transaction.' + key

             where += web.reparam(' AND %s=$value' % key, locals())
+
+ if query.bot:
+ iter = self.db.query("select id from thing where key like '/user/%%Bot'")
+ bots = '(' + ','.join(str(i.id) for i in iter) + ')'
+ if query.bot == 'only':
+ where += ' AND author_id in ' + bots
+ else:
+ assert query.bot == 'hide'
+ where += ' AND author_id not in ' + bots

         sort = query.sort
         if sort and sort.startswith('-'):
diff --git a/infogami/infobase/readquery.py b/infogami/infobase/readquery.py
index 1a9c679..58c0828 100644
--- a/infogami/infobase/readquery.py
+++ b/infogami/infobase/readquery.py
@@ -233,6 +233,7 @@ def make_versions_query(store, query):
     if q.limit > 1000:
         q.limit = 1000
     q.sort = query.pop('sort', '-created')
+ q.bot = query.pop('bot', None)

     columns = ['key', 'type', 'revision', 'author', 'comment', 'machine_comment', 'ip', 'created']