Update listing JSON template to include explicit before/after; fix validator to make /reddits/mine pagination work correctly.

This commit is contained in:
KeyserSosa
2009-07-08 15:47:08 -07:00
parent 5ea7b2e3ef
commit cb491d858e
5 changed files with 13 additions and 6 deletions

View File

@@ -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:

View File

@@ -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):

View File

@@ -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":

View File

@@ -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()

View File

@@ -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)