diff --git a/r2/r2/config/templates.py b/r2/r2/config/templates.py index e73c9fbee..6989fd36b 100644 --- a/r2/r2/config/templates.py +++ b/r2/r2/config/templates.py @@ -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()) diff --git a/r2/r2/lib/jsontemplates.py b/r2/r2/lib/jsontemplates.py index 635725b7d..3a40ccd1c 100644 --- a/r2/r2/lib/jsontemplates.py +++ b/r2/r2/lib/jsontemplates.py @@ -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"