From 88d191eebfdb26b9b7c79eb6a3abc986d226e631 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Sat, 24 Dec 2011 23:32:17 -0800 Subject: [PATCH] Gold feature: personal karma breakdown by subreddit. --- r2/r2/models/account.py | 20 +++++----- r2/r2/public/static/css/reddit.css | 51 ++++++++++++++++++++++++ r2/r2/templates/profilebar.html | 63 ++++++++++++++++++------------ 3 files changed, 100 insertions(+), 34 deletions(-) diff --git a/r2/r2/models/account.py b/r2/r2/models/account.py index 3554f19f8..ba61526db 100644 --- a/r2/r2/models/account.py +++ b/r2/r2/models/account.py @@ -31,6 +31,7 @@ from r2.lib import filters from r2.lib.log import log_text from pylons import g +from pylons.i18n import _ import time, sha from copy import copy from datetime import datetime, timedelta @@ -159,7 +160,7 @@ class Account(Thing): return True def all_karmas(self): - """returns a list of tuples in the form (name, link_karma, + """returns a list of tuples in the form (name, hover-text, link_karma, comment_karma)""" link_suffix = '_link_karma' comment_suffix = '_comment_karma' @@ -171,19 +172,18 @@ class Account(Thing): elif k.endswith(comment_suffix): sr_names.add(k[:-len(comment_suffix)]) for sr_name in sr_names: - karmas.append((sr_name, + karmas.append((sr_name, None, self._t.get(sr_name + link_suffix, 0), self._t.get(sr_name + comment_suffix, 0))) - karmas.sort(key = lambda x: abs(x[1] + x[2]), reverse=True) + karmas.sort(key = lambda x: abs(x[2] + x[3]), reverse=True) - karmas.insert(0, ('total', - self.karma('link'), - self.karma('comment'))) - - karmas.append(('old', - self._t.get('link_karma', 0), - self._t.get('comment_karma', 0))) + old_link_karma = self._t.get('link_karma', 0) + old_comment_karma = self._t.get('comment_karma', 0) + if old_link_karma or old_comment_karma: + karmas.append((_('ancient history'), + _('really obscure karma from before it was cool to track per-subreddit'), + old_link_karma, old_comment_karma)) return karmas diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index 3f59dadce..c18a67365 100644 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -4605,6 +4605,57 @@ tr.gold-accent + tr > td { padding-top: 10px; } +#per-sr-karma { + width: 300px; + margin: .6em auto 0 auto; + table-layout: fixed; +} + +#per-sr-karma thead th, +#per-sr-karma td { + text-align: right; +} + +#per-sr-karma tbody th { + text-align: left; +} + +#per-sr-karma #sr-karma-header { + width: 150px; + text-align: left; +} + +#per-sr-karma thead th { + font-weight: bold; + padding-bottom: 2px; +} + +#per-sr-karma tbody th { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + -o-text-overflow: ellipsis; +} + +#per-sr-karma tbody td { + font-weight: bold; + color: #666; +} + +#per-sr-karma th.helpful span { + border-bottom: 1px dotted #666; + cursor: help; + display: inline-block; +} + +.more-karmas { + display: none; +} + +.giftgold.karma-breakdown { + margin-top: .6em; +} + .friend-note button[type=submit] { display: none; font-size: x-small; diff --git a/r2/r2/templates/profilebar.html b/r2/r2/templates/profilebar.html index 444c54629..db35bb0b5 100644 --- a/r2/r2/templates/profilebar.html +++ b/r2/r2/templates/profilebar.html @@ -58,42 +58,57 @@ %endif - %if c.user_is_admin: - + ${locale.format("%d", thing.user.safe_karma, True)} + + ${_("link karma")} + +
+ ${locale.format("%d", thing.user.comment_karma, True)} + + ${_("comment karma")} + + %if c.user_is_admin or (c.user.gold and c.user == thing.user): +
+ + + + + + + <% karmas = thing.user.all_karmas() %> - %for i, (label, lc, cc) in enumerate(karmas): + + %for i, (label, title, lc, cc) in enumerate(karmas): = 5: class="more-karmas" - style="text-align:right; display: none" - %endif + % endif > - - - - + % if title: + + % else: + + % endif + + %endfor +
subredditlinkcomment
${label}:${lc}/${cc}${label}${label}${lc}${cc}
- %if i >= 5: + % if not c.user_is_admin or len(karmas) > 5: +
- show karma for all ${len(karmas)} reddits + show karma breakdown by subreddit - %endif - %else: - ${locale.format("%d", thing.user.safe_karma, True)} - - ${_("link karma")} - -
- ${locale.format("%d", thing.user.comment_karma, True)} - - ${_("comment karma")} +
+ % endif %endif %if thing.gold_remaining: