1a107601fa490ca69215facceebe3d0dc5e7f1f8 | 6bcef0037bdb2d139a15065c3f31e872bae79df3 | ||
---|---|---|---|
30 | from r2.lib.memoize import memoize, clear_memo | 30 | from r2.lib.memoize import memoize, clear_memo |
31 | from r2.lib.utils import tup | 31 | from r2.lib.utils import tup |
32 | from r2.lib.strings import strings, Score | 32 | from r2.lib.strings import strings, Score |
33 | from r2.lib.filters import _force_unicode | ||
33 | 34 | ||
34 | import os.path | 35 | import os.path |
35 | 36 | ||
... | ... | ||
37 | _defaults = dict(static_path = g.static_path, | 38 | _defaults = dict(static_path = g.static_path, |
38 | stylesheet = None, | 39 | stylesheet = None, |
39 | stylesheet_rtl = None, | 40 | stylesheet_rtl = None, |
41 | stylesheet_contents = '', | ||
42 | stylesheet_hash = '0', | ||
40 | description = None, | 43 | description = None, |
41 | firsttext = strings.firsttext, | 44 | firsttext = strings.firsttext, |
42 | header = os.path.join(g.static_path, | 45 | header = os.path.join(g.static_path, |
... | ... | ||
45 | reported = 0, | 48 | reported = 0, |
46 | valid_votes = 0, | 49 | valid_votes = 0, |
47 | show_media = False, | 50 | show_media = False, |
51 | domain = None, | ||
48 | ) | 52 | ) |
49 | 53 | ||
50 | @classmethod | 54 | @classmethod |
... | ... | ||
91 | else: | 95 | else: |
92 | raise NotFound, 'Subreddit %s' % name | 96 | raise NotFound, 'Subreddit %s' % name |
93 | 97 | ||
98 | @classmethod | ||
99 | @memoize('subreddit._by_domain') | ||
100 | def _by_domain_cache(cls, name): | ||
101 | q = cls._query(cls.c.domain == name, | ||
102 | cls.c.over_18 == (True, False), | ||
103 | limit = 1) | ||
104 | l = list(q) | ||
105 | if l: | ||
106 | return l[0]._id | ||
107 | |||
108 | @classmethod | ||
109 | def _by_domain(cls, domain): | ||
110 | sr_id = cls._by_domain_cache(_force_unicode(domain)) | ||
111 | if sr_id: | ||
112 | return cls._byID(sr_id, True) | ||
113 | else: | ||
114 | return None | ||
115 | |||
94 | @property | 116 | @property |
95 | def moderators(self): | 117 | def moderators(self): |
96 | return self.moderator_ids() | 118 | return self.moderator_ids() |
... | ... | ||
138 | and (c.user_is_admin | 160 | and (c.user_is_admin |
139 | or self.is_moderator(user))) | 161 | or self.is_moderator(user))) |
140 | 162 | ||
163 | def can_change_stylesheet(self, user): | ||
164 | if c.user_is_loggedin: | ||
165 | return c.user_is_admin or self.is_moderator(user) | ||
166 | else: | ||
167 | return False | ||
168 | |||
141 | def is_special(self, user): | 169 | def is_special(self, user): |
142 | return (user | 170 | return (user |
143 | and (c.user_is_admin | 171 | and (c.user_is_admin |
... | ... | ||
341 | def can_submit(self, user): | 369 | def can_submit(self, user): |
342 | return False | 370 | return False |
343 | 371 | ||
372 | def can_change_stylesheet(self, user): | ||
373 | return False | ||
374 | |||
344 | def is_banned(self, user): | 375 | def is_banned(self, user): |
345 | return False | 376 | return False |
346 | 377 |