Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Added json view for about/stylesheet.
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe authored and Logan Hanks committed Apr 17, 2012
1 parent cae49da commit c946cf0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions r2/r2/config/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ def api(type, cls):
api('flairlist', FlairListJsonTemplate)
api('flaircsv', FlairCsvJsonTemplate)

api('subredditstylesheet', StylesheetTemplate)

tpm.add_handler('usertableitem', 'api-html', UserItemHTMLJsonTemplate())
23 changes: 23 additions & 0 deletions r2/r2/lib/jsontemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,26 @@ def row_to_json(row):
class FlairCsvJsonTemplate(JsonTemplate):
def render(self, thing, *a, **kw):
return ObjectTemplate([l.__dict__ for l in thing.results_by_line])

class StylesheetTemplate(ThingJsonTemplate):
_data_attrs_ = dict(subreddit_id = '_fullname',
stylesheet = 'stylesheet_contents',
images = '_images')

def kind(self, wrapped):
return 'stylesheet'

def images(self):
images = []
for name, url in c.site.get_images():
images.append({'name': name,
'link': 'url(%%%%%s%%%%)' % name,
'url': url})
return images

def thing_attr(self, thing, attr):
if attr == '_images':
return self.images()
elif attr == '_fullname':
return c.site._fullname
return ThingJsonTemplate.thing_attr(self, thing, attr)

0 comments on commit c946cf0

Please sign in to comment.