Add JSON api access to various user lists.

This commit is contained in:
Max Goodman
2011-11-09 17:37:59 -08:00
parent 2a63d862f4
commit 94ac558ca4
2 changed files with 24 additions and 2 deletions

View File

@@ -43,7 +43,10 @@ api('morechildren', MoreCommentJsonTemplate)
api('reddit', RedditJsonTemplate)
api('panestack', PanestackJsonTemplate)
api('listing', ListingJsonTemplate)
api('usertableitem', UserItemJsonTemplate)
api('modlist', UserListJsonTemplate)
api('contributorlist', UserListJsonTemplate)
api('bannedlist', UserListJsonTemplate)
api('friendlist', UserListJsonTemplate)
api('account', AccountJsonTemplate)
api('organiclisting', OrganicListingJsonTemplate)
@@ -52,3 +55,5 @@ api('takedownpane', TakedownJsonTemplate)
api('flairlist', FlairListJsonTemplate)
api('flaircsv', FlairCsvJsonTemplate)
tpm.add_handler('usertableitem', 'api-html', UserItemHTMLJsonTemplate())

View File

@@ -91,7 +91,7 @@ class TableRowTemplate(JsonTemplate):
css_class = self.css_class(thing),
cells = self.cells(thing)))
class UserItemJsonTemplate(TableRowTemplate):
class UserItemHTMLJsonTemplate(TableRowTemplate):
def cells(self, thing):
cells = []
for cell in thing.cells:
@@ -468,6 +468,23 @@ class ListingJsonTemplate(ThingJsonTemplate):
def kind(self, wrapped):
return "Listing"
class UserListJsonTemplate(ThingJsonTemplate):
_data_attrs_ = dict(children = "users")
def thing_attr(self, thing, attr):
if attr == "users":
res = []
for a in thing.users:
res.append(a.user.name)
return res
return ThingJsonTemplate.thing_attr(self, thing, attr)
def rendered_data(self, thing):
return self.thing_attr(thing, "users")
def kind(self, wrapped):
return "UserList"
class OrganicListingJsonTemplate(ListingJsonTemplate):
def kind(self, wrapped):
return "OrganicListing"