mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-24 22:38:09 -05:00
Gold feature: personal karma breakdown by subreddit.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -58,42 +58,57 @@
|
||||
</div>
|
||||
%endif
|
||||
|
||||
%if c.user_is_admin:
|
||||
<table>
|
||||
<span class="karma">${locale.format("%d", thing.user.safe_karma, True)}</span>
|
||||
 
|
||||
${_("link karma")}
|
||||
|
||||
<br/>
|
||||
<span class="karma comment-karma">${locale.format("%d", thing.user.comment_karma, True)}</span>
|
||||
 
|
||||
${_("comment karma")}
|
||||
|
||||
%if c.user_is_admin or (c.user.gold and c.user == thing.user):
|
||||
<table id="per-sr-karma"
|
||||
% if not c.user_is_admin:
|
||||
class="more-karmas"
|
||||
% endif
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th id="sr-karma-header">subreddit</th>
|
||||
<th>link</th>
|
||||
<th>comment</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<%
|
||||
karmas = thing.user.all_karmas()
|
||||
%>
|
||||
%for i, (label, lc, cc) in enumerate(karmas):
|
||||
<tbody>
|
||||
%for i, (label, title, lc, cc) in enumerate(karmas):
|
||||
<tr
|
||||
%if i < 5:
|
||||
style="text-align:right"
|
||||
%else:
|
||||
% if c.user_is_admin and i >= 5:
|
||||
class="more-karmas"
|
||||
style="text-align:right; display: none"
|
||||
%endif
|
||||
% endif
|
||||
>
|
||||
<th>${label}:</th>
|
||||
<td><b>${lc}</b></td>
|
||||
<td>/</td>
|
||||
<td><b>${cc}</b></td>
|
||||
% if title:
|
||||
<th class="helpful" title="${title}"><span>${label}</span></th>
|
||||
% else:
|
||||
<th>${label}</th>
|
||||
% endif
|
||||
<td>${lc}</td>
|
||||
<td>${cc}</td>
|
||||
</tr>
|
||||
%endfor
|
||||
</tbody>
|
||||
</table>
|
||||
%if i >= 5:
|
||||
% if not c.user_is_admin or len(karmas) > 5:
|
||||
<div class="giftgold karma-breakdown">
|
||||
<a href="javascript:void(0)"
|
||||
onclick="$('.more-karmas').show();$(this).hide();return false">
|
||||
show karma for all ${len(karmas)} reddits
|
||||
show karma breakdown by subreddit
|
||||
</a>
|
||||
%endif
|
||||
%else:
|
||||
<span class="karma">${locale.format("%d", thing.user.safe_karma, True)}</span>
|
||||
 
|
||||
${_("link karma")}
|
||||
|
||||
<br/>
|
||||
<span class="karma">${locale.format("%d", thing.user.comment_karma, True)}</span>
|
||||
 
|
||||
${_("comment karma")}
|
||||
</div>
|
||||
% endif
|
||||
%endif
|
||||
|
||||
%if thing.gold_remaining:
|
||||
|
||||
Reference in New Issue
Block a user