Skip to content

Commit

Permalink
Change add and clear to private methods of flair template class
Browse files Browse the repository at this point in the history
  • Loading branch information
leviroth committed Jun 19, 2017
1 parent bffc093 commit 02a53c5
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions praw/models/reddit/subreddit.py
Expand Up @@ -807,49 +807,13 @@ def __init__(self, subreddit):
"""
self.subreddit = subreddit

def add(self, text, css_class='', text_editable=False, is_link=None):
"""Add a flair template to the associated subreddit.
:param text: The flair template's text (required).
:param css_class: The flair template's css_class (default: '').
:param text_editable: (boolean) Indicate if the flair text can be
modified for each Redditor that sets it (default: False).
:param is_link: (boolean) When None, choose a template type in a
subclass-defined way. Otherwise, add a link flair template when
True and a Redditor flair template when false (default: None).
For example, to add an editable link flair try:
.. code-block:: python
reddit.subreddit('NAME').flair.templates.add(
css_class='praw', text_editable=True, is_link=True)
"""
if is_link is None:
is_link = self.is_link
def _add(self, text, css_class='', text_editable=False, is_link=None):
url = API_PATH['flairtemplate'].format(subreddit=self.subreddit)
data = {'css_class': css_class, 'flair_type': self.flair_type(is_link),
'text': text, 'text_editable': bool(text_editable)}
self.subreddit._reddit.post(url, data=data)

def clear(self, is_link=None):
"""Remove all flair templates from the subreddit.
:param is_link: (boolean) When None, choose a template type in a
subclass-defined way. Otherwise, clear all link flair templates
when True and all Redditor flair template when false (default:
None).
For example, to clear all Redditor flair templates, run:
.. code-block:: python
reddit.subreddit('NAME').flair.templates.clear()
"""
if is_link is None:
is_link = self.is_link
def _clear(self, is_link=None):
url = API_PATH['flairtemplateclear'].format(subreddit=self.subreddit)
self.subreddit._reddit.post(
url, data={'flair_type': self.flair_type(is_link)})
Expand Down Expand Up @@ -897,19 +861,6 @@ def update(self, template_id, text, css_class='', text_editable=False):
class SubredditRedditorFlairTemplates(SubredditFlairTemplates):
"""Provide functions to interact with Redditor flair templates."""

def __init__(self, *args, **kwargs):
"""Create a SubredditRedditorFlairTemplate instance.
:param subreddit: The subreddit whose flair templates to work with.
.. note:: This class should not be initialized directly. Instead obtain
an instance via:
``reddit.subreddit('subreddit_name').flair.templates``
"""
super(SubredditRedditorFlairTemplates, self).__init__(*args, **kwargs)
self.is_link = False

def __iter__(self):
"""Iterate through the user flair templates.
Expand All @@ -927,22 +878,40 @@ def __iter__(self):
for template in self.subreddit._reddit.post(url, data=data)['choices']:
yield template

def add(self, text, css_class='', text_editable=False):
"""Add a Redditor flair template to the associated subreddit.
class SubredditLinkFlairTemplates(SubredditFlairTemplates):
"""Provide functions to interact with link flair templates."""
:param text: The flair template's text (required).
:param css_class: The flair template's css_class (default: '').
:param text_editable: (boolean) Indicate if the flair text can be
modified for each Redditor that sets it (default: False).
def __init__(self, *args, **kwargs):
"""Create a SubredditLinkFlairTemplate instance.
For example, to add an editable Redditor flair try:
:param subreddit: The subreddit whose flair templates to work with.
.. code-block:: python
.. note:: This class should not be initialized directly. Instead obtain
an instance via:
``reddit.subreddit('subreddit_name').flair.link_templates``
reddit.subreddit('NAME').flair.templates.add(
css_class='praw', text_editable=True)
"""
super(SubredditLinkFlairTemplates, self).__init__(*args, **kwargs)
self.is_link = True
self._add(text, css_class=css_class, text_editable=text_editable,
is_link=False)

def clear(self):
"""Remove all Redditor flair templates from the subreddit.
For example:
.. code-block:: python
reddit.subreddit('NAME').flair.templates.clear()
"""
self._clear(is_link=False)


class SubredditLinkFlairTemplates(SubredditFlairTemplates):
"""Provide functions to interact with link flair templates."""

def __iter__(self):
"""Iterate through the link flair templates.
Expand All @@ -960,6 +929,37 @@ def __iter__(self):
for template in self.subreddit._reddit.get(url):
yield template

def add(self, text, css_class='', text_editable=False):
"""Add a link flair template to the associated subreddit.
:param text: The flair template's text (required).
:param css_class: The flair template's css_class (default: '').
:param text_editable: (boolean) Indicate if the flair text can be
modified for each Redditor that sets it (default: False).
For example, to add an editable link flair try:
.. code-block:: python
reddit.subreddit('NAME').flair.link_templates.add(
css_class='praw', text_editable=True)
"""
self._add(text, css_class=css_class, text_editable=text_editable,
is_link=True)

def clear(self):
"""Remove all link flair templates from the subreddit.
For example:
.. code-block:: python
reddit.subreddit('NAME').flair.link_templates.clear()
"""
self._clear(is_link=True)


class SubredditModeration(object):
"""Provides a set of moderation functions to a Subreddit."""
Expand Down

0 comments on commit 02a53c5

Please sign in to comment.