ModAction: Read from ModActionBySRActionMod.

This commit is contained in:
Brian Simpson
2013-09-10 15:04:24 -04:00
parent 544e4994a5
commit 8a7e8d224d
2 changed files with 9 additions and 18 deletions

View File

@@ -437,18 +437,9 @@ class FrontController(RedditController, OAuth2ResourceController):
return self.abort404()
def _make_moderationlog(self, srs, num, after, reverse, count, mod=None, action=None):
if mod and action:
query = Subreddit.get_modactions(srs, mod=mod, action=None)
def keep_fn(ma):
return ma.action == action
else:
query = Subreddit.get_modactions(srs, mod=mod, action=action)
def keep_fn(ma):
return True
builder = QueryBuilder(query, skip=True, num=num, after=after,
keep_fn=keep_fn, count=count,
query = Subreddit.get_modactions(srs, mod=mod, action=action)
builder = QueryBuilder(query, num=num, after=after,
count=count,
reverse=reverse,
wrap=default_thing_wrapper())
listing = ModActionListing(builder)

View File

@@ -257,17 +257,17 @@ class ModAction(tdb_cassandra.UuidThing, Printable):
if not mod and not action:
rowkeys = [sr._id36 for sr in srs]
q = ModActionBySR.query(rowkeys, after=after, reverse=reverse, count=count)
elif mod and not action:
elif mod:
mods = tup(mod)
key = '%s_%s' if not action else '%%s_%%s_%s' % action
rowkeys = itertools.product([sr._id36 for sr in srs],
[mod._id36 for mod in mods])
rowkeys = ['%s_%s' % (sr, mod) for sr, mod in rowkeys]
q = ModActionBySRMod.query(rowkeys, after=after, reverse=reverse, count=count)
elif not mod and action:
rowkeys = [key % (sr, mod) for sr, mod in rowkeys]
view = ModActionBySRActionMod if action else ModActionBySRMod
q = view.query(rowkeys, after=after, reverse=reverse, count=count)
else:
rowkeys = ['%s_%s' % (sr._id36, action) for sr in srs]
q = ModActionBySRAction.query(rowkeys, after=after, reverse=reverse, count=count)
else:
raise NotImplementedError("Can't query by both mod and action")
return q