-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
96 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"""Provide the Flair class.""" | ||
from .base import RedditBase | ||
|
||
|
||
class SubmissionFlair(RedditBase): | ||
"""An individual SubmissionFlair object. | ||
**Typical Attributes** | ||
This table describes attributes that typically belong to objects of this | ||
class. Since attributes are dynamically provided (see | ||
:ref:`determine-available-attributes-of-an-object`), there is not a | ||
guarantee that these attributes will always be present, nor is this list | ||
necessarily comprehensive. | ||
======================= =================================================== | ||
Attribute Description | ||
======================= =================================================== | ||
``flair_template_id`` The id of the flair template. | ||
``flair_text_editable`` Whether or not the flair text can be edited. | ||
``flair_text`` The text of the flair | ||
""" | ||
|
||
STR_FIELD = "flair_text" | ||
|
||
def __eq__(self, other): | ||
"""Check that two flairs are the same flair.""" | ||
if isinstance(other, str): | ||
return str(self) == other | ||
return ( | ||
isinstance(other, self.__class__) | ||
and str(self) == str(other) | ||
and self.flair_template_id == other.flair_template_id | ||
) | ||
|
||
def __hash__(self): | ||
"""Return the hash of the flair.""" | ||
return ( | ||
hash(self.__class__.__name__) | ||
^ hash(str(self)) | ||
^ hash(self.flair_template_id) | ||
^ hash(self.submission) | ||
) | ||
|
||
def __init__(self, reddit, submission, _data): | ||
"""Instantizes the flair object.""" | ||
self.submission = submission | ||
super().__init__(reddit, _data=_data) | ||
|
||
def change_text(self, text): | ||
"""Allow the submission author to give a custom text to the flair. | ||
Please verify that the flair is editable before editing the text of the | ||
flair. | ||
""" | ||
self.flair_text = text | ||
|
||
|
||
class SubmissionModerationFlair(SubmissionFlair): | ||
"""A special flair that is returned to moderators. | ||
It has the same typical values as :class:`.SubmissionFlair`. | ||
""" | ||
|
||
def change_css_class(self, css_class): | ||
"""Change the css class of the flair (Mod only).""" | ||
self.flair_css_class = css_class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters