diff --git a/r2/r2/lib/template_helpers.py b/r2/r2/lib/template_helpers.py index 12388ea73..bb04dc388 100644 --- a/r2/r2/lib/template_helpers.py +++ b/r2/r2/lib/template_helpers.py @@ -307,3 +307,20 @@ def choose_width(link, width): def panel_size(state): "the frame.cols of the reddit-toolbar's inner frame" return '400px, 100%' if state =='expanded' else '0px, 100%x' + +def find_author_class(thing, attribs, gray): + #assume attribs is sorted + author = thing.author + author_cls = "author" + + extra_class = '' + attribs.sort() + + if gray: + author_cls += " gray" + elif attribs: + #the last element in attribs will be the highest priority + extra_class = attribs[-1][2] + author_cls += " " + extra_class + + return author_cls diff --git a/r2/r2/models/account.py b/r2/r2/models/account.py index 8534eeb3b..24805109e 100644 --- a/r2/r2/models/account.py +++ b/r2/r2/models/account.py @@ -239,7 +239,6 @@ class Account(Thing): - class FakeAccount(Account): _nodb = True diff --git a/r2/r2/models/builder.py b/r2/r2/models/builder.py index 5c30cd6d6..bbad6f640 100644 --- a/r2/r2/models/builder.py +++ b/r2/r2/models/builder.py @@ -23,9 +23,10 @@ from account import * from link import * from vote import * from report import * -from subreddit import SRMember +from subreddit import SRMember, FakeSubreddit from listing import Listing from pylons import i18n, request, g +from pylons.i18n import _ import subreddit @@ -44,6 +45,36 @@ from admintools import compute_votes, admintools EXTRA_FACTOR = 1.5 MAX_RECURSION = 10 +# Appends to the list "attrs" a tuple of: +# +def add_attr(attrs, code, label=None, link=None): + if code == 'F': + priority = 1 + cssclass = 'friend' + if not label: + label = _('friend') + if not link: + link = '/prefs/friends' + elif code == 'M': + priority = 2 + cssclass = 'moderator' + if not label: + raise ValueError ("Need a label") + if not link: + raise ValueError ("Need a link") + elif code == 'S': + priority = 3 + cssclass = 'submitter' + if not label: + label = _('submitter') + if not link: + raise ValueError ("Need a link") + else: + raise ValueError ("Got weird code [%s]" % code) + + attrs.append( (priority, code, cssclass, label, link) ) + class Builder(object): def __init__(self, wrap = Wrapped, keep_fn = None): self.wrap = wrap @@ -98,6 +129,21 @@ class Builder(object): types = {} wrapped = [] count = 0 + + if isinstance(c.site, FakeSubreddit): + mods = [] + else: + mods = c.site.moderators + modlink = '' + if c.cname: + modlink = '/about/moderators' + else: + modlink = '/r/%s/about/moderators' % c.site.name + + modlabel = (_('moderator of /r/%(reddit)s') % + dict(reddit = c.site.name) ) + + for item in items: w = self.wrap(item) wrapped.append(w) @@ -108,12 +154,26 @@ class Builder(object): #TODO pull the author stuff into add_props for links and #comments and messages? + w.author = None + w.friend = False + + # List of tuples + w.attribs = [] + try: w.author = authors.get(item.author_id) - w.friend = item.author_id in user.friends if user else False + if user and item.author_id in user.friends: + # deprecated old way: + w.friend = True + # new way: + add_attr(w.attribs, 'F') + except AttributeError: - w.author = None - w.friend = False + pass + + if getattr(item, "author_id", None) in mods: + add_attr(w.attribs, 'M', label=modlabel, link=modlink) if hasattr(item, "sr_id"): w.subreddit = subreddits[item.sr_id] diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index 2102ff278..2e21fe5b0 100644 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -501,6 +501,8 @@ class Comment(Thing, Printable): @classmethod def add_props(cls, user, wrapped): + from r2.models.builder import add_attr + #fetch parent links links = Link._byID(set(l.link_id for l in wrapped), data = True, @@ -539,6 +541,9 @@ class Comment(Thing, Printable): if not hasattr(item, 'subreddit'): item.subreddit = item.subreddit_slow + if item.author_id == item.link.author_id: + add_attr(item.attribs, 'S', + link = item.link.make_permalink(item.subreddit)) if not hasattr(item, 'target'): item.target = None if hasattr(item, 'parent_id'): diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index dc3a7ac5d..26d592815 100644 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -483,7 +483,9 @@ before enabling */ .tagline { color:#888; font-size:x-small; } .tagline a {color: #369; text-decoration: none; } -.tagline a.friend {color: orangered } +.tagline .friend { color: orangered } +.tagline .submitter { color: #0055df } +.tagline .moderator { color: #338833 } .tagline a:hover { text-decoration: underline } .media-button .option { color: red; } @@ -1242,7 +1244,7 @@ textarea.gray { color: gray; } .vote-note { padding-left: 3px; - max-width: 170px; + max-width: 150px; } .vote-a-notes { color: red; diff --git a/r2/r2/templates/comment.html b/r2/r2/templates/comment.html index 50096384a..0f5a56d70 100644 --- a/r2/r2/templates/comment.html +++ b/r2/r2/templates/comment.html @@ -69,7 +69,7 @@ ${parent.collapsed()} %if thing.deleted: ${_("deleted comment from")} %endif - ${unsafe(self.author(friend=thing.friend, gray = collapse))} + ${unsafe(self.author(attribs=thing.attribs, gray = collapse))} %else: ${_("[deleted]")} %endif diff --git a/r2/r2/templates/link.html b/r2/r2/templates/link.html index e99b8b235..9bc80a427 100644 --- a/r2/r2/templates/link.html +++ b/r2/r2/templates/link.html @@ -175,7 +175,7 @@ ${unsafe(taglinetext % dict(reddit = self.subreddit(), when = thing.timesince, - author= self.author(friend = thing.friend)))} + author= self.author(attribs = thing.attribs)))} <%def name="child()"> diff --git a/r2/r2/templates/link.mobile b/r2/r2/templates/link.mobile index 27cbf31d4..c8a2636f5 100644 --- a/r2/r2/templates/link.mobile +++ b/r2/r2/templates/link.mobile @@ -69,5 +69,5 @@ ${unsafe(taglinetext % dict(reddit = self.subreddit(), domain = self.domain(), when = thing.timesince, - author= self.author(friend = thing.friend)))} + author= self.author()))} diff --git a/r2/r2/templates/message.html b/r2/r2/templates/message.html index 3acf6d335..85650e51c 100644 --- a/r2/r2/templates/message.html +++ b/r2/r2/templates/message.html @@ -49,7 +49,7 @@ taglinetext = taglinetext.replace(' ', ' ') %> ${unsafe(taglinetext % dict(when = thing.timesince, - author= u"%s" % self.author(thing.friend), + author= u"%s" % self.author(thing.attribs), dest = u"%s" % thing.to.name))} %if c.user_is_admin: diff --git a/r2/r2/templates/printable.html b/r2/r2/templates/printable.html index 005907906..2a822cd2c 100644 --- a/r2/r2/templates/printable.html +++ b/r2/r2/templates/printable.html @@ -21,7 +21,7 @@ ################################################################################ <%! - from r2.lib.template_helpers import add_sr + from r2.lib.template_helpers import add_sr, find_author_class from r2.lib.strings import strings from r2.lib.pages.things import BanButtons %> @@ -115,33 +115,52 @@ thing id-${what._fullname} -<%def name="author(friend = False, gray = False)" buffered="True"> +<%def name="author(attribs = None, gray = False)" buffered="True"> %if thing.deleted and not c.user_is_admin: [deleted] %else: <% - target = None - if hasattr(thing, "target"): - target = thing.target + attribs.sort() + author_cls = find_author_class(thing, attribs, gray) + + target = getattr(thing, "target", None) + + disp_name = websafe(thing.author.name) + karma = "" + if c.user_is_admin: + karma = " (%d)" % (thing.author.link_karma) %> + %if thing.author._deleted: [deleted] %else: - <% - author = thing.author - author_cls = "author" - if friend: - author_cls += " friend" - elif gray: - author_cls += " gray" - disp_name = websafe(author.name) - if c.user_is_admin: - disp_name += " (%d)" % (author.link_karma) - %> - ${plain_link(disp_name, '/user/%s' % websafe(author.name), + ${plain_link(disp_name + karma, "/user/%s" % disp_name, _class = author_cls, _sr_path = False, target=target)} + %if attribs: + + [ + %for priority, abbv, css_class, label, attr_link in attribs: + %if attr_link: + ${abbv} + %else: + ${abbv} + %endif + ## author_cls contains the final css_class, so this is a hack + ## that will print a comma after all but the final attr + %if css_class not in author_cls: + , + %endif + %endfor + ] + %endif + %endif + %endif + %if c.user_is_admin and hasattr(thing, 'ip') and thing.ip: %endif