Don't create votehash attribute on each thing.

This commit is contained in:
Brian Simpson
2013-07-12 09:05:15 -07:00
parent 4408f479a7
commit 639dab92d4
6 changed files with 7 additions and 13 deletions

View File

@@ -22,7 +22,7 @@
from r2.models import *
from filters import unsafe, websafe, _force_unicode, _force_utf8
from r2.lib.utils import vote_hash, UrlParser, timesince, is_subdomain
from r2.lib.utils import UrlParser, timesince, is_subdomain
from r2.lib import hooks
from r2.lib.static import static_mtime
@@ -162,6 +162,7 @@ def js_config(extra_config=None):
"uitracker_url": g.uitracker_url,
"static_root": static(''),
"over_18": bool(c.over18),
"vote_hash": c.vote_hash,
}
if extra_config:
@@ -280,10 +281,6 @@ def replace_render(listing, item, render_func):
replacements["midcolmargin"] = mid_margin
#$votehash is only present when voting arrows are present
if c.user_is_loggedin:
replacements['votehash'] = vote_hash(c.user, item,
listing.vote_hash_type)
if hasattr(item, "num_comments"):
com_label, com_cls = comment_label(item.num_comments)
if style == "compact":

View File

@@ -39,7 +39,7 @@ class Listing(object):
_js_cls = "Listing"
def __init__(self, builder, nextprev = True, next_link = True,
prev_link = True, vote_hash_type = 'valid', **kw):
prev_link = True, **kw):
self.builder = builder
self.nextprev = nextprev
self.next_link = True
@@ -47,7 +47,6 @@ class Listing(object):
self.next = None
self.prev = None
self._max_num = 1
self.vote_hash_type = vote_hash_type
@property
def max_score(self):
@@ -138,7 +137,6 @@ class SpotlightListing(Listing):
_js_cls = "OrganicListing"
def __init__(self, *a, **kw):
self.vote_hash_type = kw.get('vote_hash_type', 'organic')
self.nextprev = False
self.show_nums = True
self._parent_max_num = kw.get('max_num', 0)

View File

@@ -46,7 +46,7 @@ class Printable(object):
'downvotes', '_downs',
'subreddit_slow', '_deleted', '_spam',
'cachable', 'make_permalink', 'permalink',
'timesince', 'votehash'
'timesince',
])
@classmethod
@@ -57,7 +57,6 @@ class Printable(object):
# caching of thing templates
item.display = CachedVariable("display")
item.timesince = CachedVariable("timesince")
item.votehash = CachedVariable("votehash")
item.childlisting = CachedVariable("childlisting")
score_fmt = getattr(item, "score_fmt", Score.number_only)

View File

@@ -31,7 +31,7 @@
title="${_('vote %(direction)s') % dict(direction=direction)}"
%if thing.user_is_loggedin:
href="javascript:void(0);"
onclick="$(this).vote('${thing.votehash}', null, event)"
onclick="$(this).vote(r.config.vote_hash, null, event)"
%else:
href="${thing.loginurl}"
target="_top"

View File

@@ -170,7 +170,7 @@
title="${_('vote %(direction)s') % dict(direction=direction)}"
%if thing.user_is_loggedin:
href="javascript:void(0);"
onclick="$(this).vote('${thing.votehash}', null, event)"
onclick="$(this).vote(r.config.vote_hash, null, event)"
%else:
href="${thing.loginurl}"
target="_top"

View File

@@ -153,7 +153,7 @@ ${self.RenderPrintable()}
%>
<div class="arrow ${_class} login-required"
%if getattr(thing, "votable", True):
onclick="$(this).vote('${thing.votehash}', null, event)"
onclick="$(this).vote(r.config.vote_hash, null, event)"
%else:
onclick="$(this).show_unvotable_message()"
%endif