mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-05 03:00:15 -04:00
Update listing JSON template to include explicit before/after; fix validator to make /reddits/mine pagination work correctly.
This commit is contained in:
@@ -355,7 +355,7 @@ class VAccountByName(VRequired):
|
||||
return self.error()
|
||||
|
||||
def fullname_regex(thing_cls = None, multiple = False):
|
||||
pattern = Thing._type_prefix
|
||||
pattern = "[%s%s]" % (Relation._type_prefix, Thing._type_prefix)
|
||||
if thing_cls:
|
||||
pattern += utils.to36(thing_cls._type_id)
|
||||
else:
|
||||
|
||||
@@ -510,7 +510,7 @@ def Relation(type1, type2, denorm1 = None, denorm2 = None):
|
||||
_set_data = staticmethod(tdb.set_rel_data)
|
||||
_get_item = staticmethod(tdb.get_rel)
|
||||
_incr_data = staticmethod(tdb.incr_rel_data)
|
||||
_type_prefix = 'r'
|
||||
_type_prefix = Relation._type_prefix
|
||||
|
||||
def __init__(self, thing1, thing2, name, date = None, id = None, **attrs):
|
||||
DataThing.__init__(self)
|
||||
@@ -666,6 +666,7 @@ def Relation(type1, type2, denorm1 = None, denorm2 = None):
|
||||
|
||||
|
||||
return RelationCls
|
||||
Relation._type_prefix = 'r'
|
||||
|
||||
class Query(object):
|
||||
def __init__(self, kind, *rules, **kw):
|
||||
|
||||
@@ -321,7 +321,9 @@ class NullJsonTemplate(JsonTemplate):
|
||||
return ""
|
||||
|
||||
class ListingJsonTemplate(ThingJsonTemplate):
|
||||
_data_attrs_ = dict(children = "things")
|
||||
_data_attrs_ = dict(children = "things",
|
||||
after = "after",
|
||||
before = "before")
|
||||
|
||||
def thing_attr(self, thing, attr):
|
||||
if attr == "things":
|
||||
|
||||
@@ -312,9 +312,9 @@ class QueryBuilder(Builder):
|
||||
i.num = count
|
||||
last_item = i
|
||||
|
||||
#unprewrap the last item
|
||||
if self.prewrap_fn and last_item:
|
||||
last_item = orig_items[last_item._id]
|
||||
#unprewrap the last item
|
||||
if self.prewrap_fn and last_item:
|
||||
last_item = orig_items[last_item._id]
|
||||
|
||||
if self.reverse:
|
||||
items.reverse()
|
||||
|
||||
@@ -65,14 +65,18 @@ class Listing(object):
|
||||
self.things, prev, next, bcount, acount = self.get_items()
|
||||
|
||||
self.max_num = max(acount, bcount)
|
||||
self.after = None
|
||||
self.before = None
|
||||
|
||||
if self.nextprev and self.prev_link and prev and bcount > 1:
|
||||
p = request.get.copy()
|
||||
p.update({'after':None, 'before':prev._fullname, 'count':bcount})
|
||||
self.before = prev._fullname
|
||||
self.prev = (request.path + utils.query_string(p))
|
||||
if self.nextprev and self.next_link and next:
|
||||
p = request.get.copy()
|
||||
p.update({'after':next._fullname, 'before':None, 'count':acount})
|
||||
self.after = next._fullname
|
||||
self.next = (request.path + utils.query_string(p))
|
||||
#TODO: need name for template -- must be better way
|
||||
return Wrapped(self)
|
||||
|
||||
Reference in New Issue
Block a user