Permalink
Browse files

Added a proper subreddit update_settings function.

  • Loading branch information...
1 parent 2c1ac39 commit 855087090e59927f3cf53cc70300fbc41994cb98 @bboe bboe committed Apr 19, 2012
Showing with 36 additions and 6 deletions.
  1. +26 −6 reddit/__init__.py
  2. +4 −0 reddit/objects.py
  3. +6 −0 reddit/reddit_test.py
View
32 reddit/__init__.py
@@ -468,7 +468,11 @@ def set_flair_csv(self, subreddit, flair_mapping):
def set_settings(self, subreddit, title, description='', language='en',
subreddit_type='public', content_options='any',
over_18=False, default_set=True, show_media=False,
- domain='', header_hover_text=''):
+ domain='', domain_css=False, domain_sidebar=False,
+ header_hover_text=''):
+ def bool_str(item):
+ return 'on' if item else 'off'
+
"""Set the settings for the given subreddit."""
params = {'r': six.text_type(subreddit),
'sr': subreddit.content_id,
@@ -477,11 +481,16 @@ def set_settings(self, subreddit, title, description='', language='en',
'lang': language,
'type': subreddit_type,
'link_type': content_options,
- 'header-title': header_hover_text,
- 'over_18': 'on' if over_18 else 'off',
- 'allow_top': 'on' if default_set else 'off',
- 'show_media': 'on' if show_media else 'off',
- 'domain': domain}
+ 'over_18': bool_str(over_18),
+ 'allow_top': bool_str(default_set),
+ 'show_media': bool_str(show_media),
+ 'domain': domain or '',
+ 'domain_css': bool_str(domain_css),
+ 'domain_sidebar': bool_str(domain_sidebar),
+ 'header-title': header_hover_text}
+ # pylint: disable-msg=E1101,W0212
+ reddit.helpers._request.evict([self.config['subreddit_settings'] %
+ six.text_type(subreddit)])
return self.request_json(self.config['site_admin'], params)
@reddit.decorators.require_login
@@ -526,6 +535,17 @@ def unsubscribe(self, subreddit):
"""Unsubscribe from the given subreddit by name."""
self._subscribe(sr_name=subreddit, unsubscribe=True)
+ def update_settings(self, subreddit, **kwargs):
+ """Update only the given settings for the given subreddit.
+
+ The settings to update must be given by keyword and match one of the
+ parameter names in `set_settings`.
+ """
+ settings = self.get_settings(subreddit)
+ settings.update(kwargs)
+ del settings['subreddit_id']
+ return self.set_settings(subreddit, **settings)
+
class LoggedInExtension(BaseReddit):
def __init__(self, *args, **kwargs):
View
4 reddit/objects.py
@@ -737,6 +737,10 @@ def unsubscribe(self):
return self.reddit_session._subscribe(self.content_id,
unsubscribe=True)
+ def update_settings(self, *args, **kwargs):
+ """Update only the settings provided for this subreddit."""
+ return self.reddit_session.update_settings(self, *args, **kwargs)
+
class UserList(RedditContentObject):
"""A class for UserList."""
View
6 reddit/reddit_test.py
@@ -335,6 +335,12 @@ def test_set_stylesheet(self):
self.assertEqual(self.subreddit.get_stylesheet()['stylesheet'],
stylesheet)
+ def test_update_settings(self):
+ settings = self.subreddit.get_settings()
+ settings['description'] = 'Description %s' % uuid.uuid4()
+ self.subreddit.update_settings(description=settings['description'])
+ self.assertEqual(self.subreddit.get_settings(), settings)
+
class FlairTest(unittest.TestCase, AuthenticatedHelper):
def setUp(self):

0 comments on commit 8550870

Please sign in to comment.