Skip to content
This repository
  • 2 commits
  • 2 files changed
  • 0 comments
  • 1 contributor
3  r2/r2/config/templates.py
@@ -57,4 +57,7 @@ def api(type, cls):
57 57
 api('flairlist', FlairListJsonTemplate)
58 58
 api('flaircsv', FlairCsvJsonTemplate)
59 59
 
  60
+api('subredditstylesheet', StylesheetTemplate)
  61
+api('createsubreddit', SubredditSettingsTemplate)
  62
+
60 63
 tpm.add_handler('usertableitem', 'api-html', UserItemHTMLJsonTemplate())
44  r2/r2/lib/jsontemplates.py
@@ -560,3 +560,47 @@ def row_to_json(row):
560 560
 class FlairCsvJsonTemplate(JsonTemplate):
561 561
     def render(self, thing, *a, **kw):
562 562
         return ObjectTemplate([l.__dict__ for l in thing.results_by_line])
  563
+
  564
+class StylesheetTemplate(ThingJsonTemplate):
  565
+    _data_attrs_ = dict(subreddit_id = '_fullname',
  566
+                        stylesheet = 'stylesheet_contents',
  567
+                        images = '_images')
  568
+
  569
+    def kind(self, wrapped):
  570
+        return 'stylesheet'
  571
+
  572
+    def images(self):
  573
+        images = []
  574
+        for name, url in c.site.get_images():
  575
+            images.append({'name': name,
  576
+                           'link': 'url(%%%%%s%%%%)' % name,
  577
+                           'url': url})
  578
+        return images
  579
+
  580
+    def thing_attr(self, thing, attr):
  581
+        if attr == '_images':
  582
+            return self.images()
  583
+        elif attr == '_fullname':
  584
+            return c.site._fullname
  585
+
  586
+class SubredditSettingsTemplate(ThingJsonTemplate):
  587
+    _data_attrs_ = dict(subreddit_id = 'site._fullname',
  588
+                        title = 'site.title',
  589
+                        description = 'site.description',
  590
+                        language = 'site.lang',
  591
+                        subreddit_type = 'site.type',
  592
+                        content_options = 'site.link_type',
  593
+                        over_18 = 'site.over_18',
  594
+                        default_set = 'site.allow_top',
  595
+                        show_media = 'site.show_media',
  596
+                        domain = 'site.domain',
  597
+                        domain_css = 'site.css_on_cname',
  598
+                        domain_sidebar = 'site.show_cname_sidebar')
  599
+
  600
+    def kind(self, wrapped):
  601
+        return 'subreddit_settings'
  602
+
  603
+    def thing_attr(self, thing, attr):
  604
+        if attr.startswith('site.'):
  605
+            return getattr(thing.site, attr[5:])
  606
+        return ThingJsonTemplate.thing_attr(self, thing, attr)

No commit comments for this range

Something went wrong with that request. Please try again.