Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix SpotlightListing to save max_num for spacing calculation.

The max_num property is used to calculate the width for the .rank
element so that listing items line up. This was getting overwritten by
Listing.listing(), causing the spotlight items to not line up with the
rest of the page.
  • Loading branch information...
commit d0504d3848a90699a74636b536b82e654abe3209 1 parent aedc271
Max Goodman authored
Showing with 14 additions and 8 deletions.
  1. +14 −8 r2/r2/models/listing.py
View
22 r2/r2/models/listing.py
@@ -45,7 +45,7 @@ def __init__(self, builder, nextprev = True, next_link = True,
self.prev_link = True
self.next = None
self.prev = None
- self.max_num = 1
+ self._max_num = 1
self.vote_hash_type = vote_hash_type
@property
@@ -53,6 +53,10 @@ def max_score(self):
scores = [x.score for x in self.things if hasattr(x, 'score')]
return max(scores) if scores else 0
+ @property
+ def max_num(self):
+ return self._max_num
+
def get_items(self, *a, **kw):
"""Wrapper around builder's get_items that caches the rendering."""
from r2.lib.template_helpers import replace_render
@@ -67,7 +71,7 @@ def get_items(self, *a, **kw):
def listing(self):
self.things, prev, next, bcount, acount = self.get_items()
- self.max_num = max(acount, bcount)
+ self._max_num = max(acount, bcount)
self.after = None
self.before = None
@@ -127,20 +131,22 @@ def __init__(self, *a, **kw):
Listing.__init__(self, *a, **kw)
self.nextprev = False
self.show_nums = True
- self._max_num = kw.get('max_num', 0)
- self._max_score = kw.get('max_score', 0)
+ self._parent_max_num = kw.get('max_num', 0)
+ self._parent_max_score = kw.get('max_score', 0)
self.spotlight_links = kw.get('spotlight_links', [])
self.visible_link = kw.get('visible_link', '')
@property
def max_score(self):
- return self._max_score
+ return self._parent_max_score
+
+ @property
+ def max_num(self):
+ return self._parent_max_num
def listing(self):
res = Listing.listing(self)
- # override score fields
- res.max_num = self._max_num
- res.max_score = self._max_score
+ # suppress item numbering
for t in res.things:
t.num = ""
return res
Please sign in to comment.
Something went wrong with that request. Please try again.