From 5cfffd0d362c4e20a99daf4bc0645afa9de3753b Mon Sep 17 00:00:00 2001 From: Chad Birch Date: Mon, 13 Jul 2015 11:41:31 -0600 Subject: [PATCH] Add a mod log entry for replaced stickies Previously, when stickying a post, the mod log would only include an entry for the stickying of the new post, even if it replaced an existing sticky. In the case of a replacement, this adds a second log entry indicating which post was unstickied to make room for the new one. In the case of accidentally stickying something, this can make it much easier to locate the previously-stickied post. --- r2/r2/models/subreddit.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index af35c939a..92ad0477f 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -1186,7 +1186,9 @@ class Subreddit(Thing, Printable, BaseSite): return self.sticky_fullnames def set_sticky(self, link, user, num=None): - from r2.models import ModAction + from r2.models import Link, ModAction + unstickied_fullnames = [] + if not self.sticky_fullnames: self.sticky_fullnames = [link._fullname] else: @@ -1197,6 +1199,7 @@ class Subreddit(Thing, Printable, BaseSite): # if a particular slot was specified and is in use, replace it if num and num <= len(sticky_fullnames): + unstickied_fullnames.append(sticky_fullnames[num-1]) sticky_fullnames[num-1] = link._fullname else: # either didn't specify a slot or it's empty, just append @@ -1204,6 +1207,8 @@ class Subreddit(Thing, Printable, BaseSite): # if we're already at the max number of stickies, remove # the bottom-most to make room for this new one if len(sticky_fullnames) >= self.MAX_STICKIES: + unstickied_fullnames.extend( + sticky_fullnames[self.MAX_STICKIES-1:]) sticky_fullnames = sticky_fullnames[:self.MAX_STICKIES-1] sticky_fullnames.append(link._fullname) @@ -1211,6 +1216,11 @@ class Subreddit(Thing, Printable, BaseSite): self.sticky_fullnames = sticky_fullnames self._commit() + + for fullname in unstickied_fullnames: + unstickied = Link._by_fullname(fullname) + ModAction.create( + self, user, "unsticky", target=unstickied, details="replaced") ModAction.create(self, user, "sticky", target=link) def remove_sticky(self, link, user):