mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 07:48:16 -05:00
Added user attributes. I'll be optimistic and not call this "User Attributes Checkin #1"
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -239,7 +239,6 @@ class Account(Thing):
|
||||
|
||||
|
||||
|
||||
|
||||
class FakeAccount(Account):
|
||||
_nodb = True
|
||||
|
||||
|
||||
@@ -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:
|
||||
# <priority (higher trumps lower), letter,
|
||||
# css class, i18n'ed mouseover label, hyperlink (or None)>
|
||||
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 <priority (higher trumps lower), letter,
|
||||
# css class, i18n'ed mouseover label, hyperlink (or None)>
|
||||
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]
|
||||
|
||||
@@ -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'):
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -69,7 +69,7 @@ ${parent.collapsed()}
|
||||
%if thing.deleted:
|
||||
<em>${_("deleted comment from")}</em> 
|
||||
%endif
|
||||
${unsafe(self.author(friend=thing.friend, gray = collapse))} 
|
||||
${unsafe(self.author(attribs=thing.attribs, gray = collapse))} 
|
||||
%else:
|
||||
<em>${_("[deleted]")}</em> 
|
||||
%endif
|
||||
|
||||
@@ -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>
|
||||
|
||||
<%def name="child()">
|
||||
|
||||
@@ -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()))}
|
||||
</%def>
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
taglinetext = taglinetext.replace(' ', ' ')
|
||||
%>
|
||||
${unsafe(taglinetext % dict(when = thing.timesince,
|
||||
author= u"<b>%s</b>" % self.author(thing.friend),
|
||||
author= u"<b>%s</b>" % self.author(thing.attribs),
|
||||
dest = u"<b>%s</b>" % thing.to.name))}
|
||||
</span>
|
||||
%if c.user_is_admin:
|
||||
|
||||
@@ -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}
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
<%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:
|
||||
<span>[deleted]</span>
|
||||
%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:
|
||||
<span class="userattrs">
|
||||
 [
|
||||
%for priority, abbv, css_class, label, attr_link in attribs:
|
||||
%if attr_link:
|
||||
<a class="${css_class}" title="${label}"
|
||||
%if target:
|
||||
target="${target}"
|
||||
%endif
|
||||
href="${attr_link}">${abbv}</a>
|
||||
%else:
|
||||
<span class="${css_class}" title="${label}">${abbv}</span>
|
||||
%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
|
||||
]
|
||||
</span>
|
||||
%endif
|
||||
%endif
|
||||
%endif
|
||||
|
||||
%if c.user_is_admin and hasattr(thing, 'ip') and thing.ip:
|
||||
<span class="ip" style="display: none;">${thing.ip}</span>
|
||||
%endif
|
||||
|
||||
Reference in New Issue
Block a user