Skip to content
This repository
Browse code

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 June 25, 2012

Showing 1 changed file with 14 additions and 8 deletions. Show diff stats Hide diff stats

  1. 22  r2/r2/models/listing.py
22  r2/r2/models/listing.py
@@ -45,7 +45,7 @@ def __init__(self, builder, nextprev = True, next_link = True,
45 45
         self.prev_link = True
46 46
         self.next = None
47 47
         self.prev = None
48  
-        self.max_num = 1
  48
+        self._max_num = 1
49 49
         self.vote_hash_type = vote_hash_type
50 50
 
51 51
     @property
@@ -53,6 +53,10 @@ def max_score(self):
53 53
         scores = [x.score for x in self.things if hasattr(x, 'score')]
54 54
         return max(scores) if scores else 0
55 55
 
  56
+    @property
  57
+    def max_num(self):
  58
+        return self._max_num
  59
+
56 60
     def get_items(self, *a, **kw):
57 61
         """Wrapper around builder's get_items that caches the rendering."""
58 62
         from r2.lib.template_helpers import replace_render
@@ -67,7 +71,7 @@ def get_items(self, *a, **kw):
67 71
     def listing(self):
68 72
         self.things, prev, next, bcount, acount = self.get_items()
69 73
 
70  
-        self.max_num = max(acount, bcount)
  74
+        self._max_num = max(acount, bcount)
71 75
         self.after = None
72 76
         self.before = None
73 77
 
@@ -127,20 +131,22 @@ def __init__(self, *a, **kw):
127 131
         Listing.__init__(self, *a, **kw)
128 132
         self.nextprev   = False
129 133
         self.show_nums  = True
130  
-        self._max_num   = kw.get('max_num', 0)
131  
-        self._max_score = kw.get('max_score', 0)
  134
+        self._parent_max_num   = kw.get('max_num', 0)
  135
+        self._parent_max_score = kw.get('max_score', 0)
132 136
         self.spotlight_links  = kw.get('spotlight_links', [])
133 137
         self.visible_link = kw.get('visible_link', '')
134 138
 
135 139
     @property
136 140
     def max_score(self):
137  
-        return self._max_score
  141
+        return self._parent_max_score
  142
+
  143
+    @property
  144
+    def max_num(self):
  145
+        return self._parent_max_num
138 146
 
139 147
     def listing(self):
140 148
         res = Listing.listing(self)
141  
-        # override score fields
142  
-        res.max_num = self._max_num
143  
-        res.max_score = self._max_score
  149
+        # suppress item numbering
144 150
         for t in res.things:
145 151
             t.num = ""
146 152
         return res

0 notes on commit d0504d3

Please sign in to comment.
Something went wrong with that request. Please try again.