Skip to content

Commit

Permalink
Merge 905bbb8 into 05691b4
Browse files Browse the repository at this point in the history
  • Loading branch information
LilSpazJoekp committed Nov 2, 2021
2 parents 05691b4 + 905bbb8 commit ccd48d5
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 91 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Unreleased

- An import error when using PRAW in environments where ``libsqlite3-dev`` is needed to
utilize the ``sqlite3`` builtin.
- Fixed bug where some keyword arguments that are passed to :meth:`.Draft.submit` would
not have an effect.

7.4.0 (2021/07/30)
------------------
Expand Down
19 changes: 13 additions & 6 deletions praw/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@


class DraftHelper(PRAWBase):
"""Provide a set of functions to interact with Drafts."""
r"""Provide a set of functions to interact with :class:`Draft` instances.
.. note::
The methods provided by this class will only work on the currently authenticated
user's :class:`Draft`\ s.
"""

def __call__(
self, *, draft_id: Optional[str] = None
) -> Union[List["praw.models.Draft"], "praw.models.Draft"]:
"""Return a list of the currently authenticated user's Drafts.
"""Return a list of :class:`.Draft` instances.
:param draft_id: When provided, return :class:`.Draft` instance (default:
``None``).
Expand All @@ -36,7 +43,7 @@ def __call__(
.. code-block:: python
draft_id = "124862bc-e1e9-11eb-aa4f-e68667a77cbb"
draft = reddit.drafts(draft_id)
draft = reddit.drafts(draft_id=draft_id)
print(draft)
"""
Expand All @@ -45,9 +52,9 @@ def __call__(
return self._draft_list()

def _draft_list(self) -> List["praw.models.Draft"]:
"""Get a list of Draft objects.
"""Get a list of :class:`.Draft` instances.
:returns: A list of instances of :class:`.Draft`.
:returns: A list of :class:`.Draft` instances.
"""
return self._reddit.get(API_PATH["drafts"], params={"md_body": True})
Expand All @@ -70,7 +77,7 @@ def create(
url: Optional[str] = None,
**draft_kwargs,
):
"""Create a new Draft.
"""Create a new :class:`.Draft`.
:param flair_id: The flair template to select (default: ``None``).
:param flair_text: If the template's ``flair_text_editable`` value is ``True``,
Expand Down
36 changes: 20 additions & 16 deletions praw/models/reddit/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class Draft(RedditBase):
"""A class for submissions to reddit.
"""A class that represents a Reddit submission draft.
**Typical Attributes**
Expand All @@ -25,7 +25,8 @@ class Draft(RedditBase):
Attribute Description
========================== ======================================================
``link_flair_template_id`` The link flair's ID.
``link_flair_text`` The link flair's text content, or None if not flaired.
``link_flair_text`` The link flair's text content, or ``None`` if not
flaired.
``modified`` Time the submission draft was modified, represented in
`Unix Time`_.
``original_content`` Whether the submission draft will be set as original
Expand All @@ -36,7 +37,7 @@ class Draft(RedditBase):
``subreddit`` Provides an instance of :class:`.Subreddit` or
:class:`.UserSubreddit` (if set).
``title`` The title of the submission draft.
``url`` The URL the submission draft links to. Will b
``url`` The URL the submission draft links to.
========================== ======================================================
.. _unix time: https://en.wikipedia.org/wiki/Unix_time
Expand Down Expand Up @@ -239,16 +240,18 @@ def submit(
"""Submit a draft.
:param flair_id: The flair template to select (default: ``None``).
:param flair_text: If the template's ``flair_text_editable`` value is True, this
value will set a custom text (default: ``None``). ``flair_id`` is required
when ``flair_text`` is provided.
:param flair_text: If the template's ``flair_text_editable`` value is ``True``,
this value will set a custom text (default: ``None``). ``flair_id`` is
required when ``flair_text`` is provided.
:param nsfw: Whether or not the submission should be marked NSFW (default:
``None``).
:param selftext: The Markdown formatted content for a ``text`` submission. Use
an empty string, ``""``, to make a title-only submission (default:
``None``).
:param spoiler: Whether or not the submission should be marked as a spoiler
(default: ``None``).
:param subreddit: The subreddit to submit the draft to. This accepts a subreddit
display name, :class:`.Subreddit` object, or :class:`.UserSubreddit` object.
:param title: The title of the submission (default: ``None``).
:param url: The URL for a ``link`` submission (default: ``None``).
Expand Down Expand Up @@ -289,17 +292,18 @@ def submit(
raise ValueError(
"`subreddit` must be set on the Draft or passed as a keyword argument."
)
for key in [
"flair_id",
"flair_text",
"nsfw",
"selftext",
"spoiler",
"title",
"url",
for key, attribute in [
("flair_id", flair_id),
("flair_text", flair_text),
("nsfw", nsfw),
("selftext", selftext),
("spoiler", spoiler),
("title", title),
("url", url),
]:
if getattr(self, key, None) is not None:
submit_kwargs[key] = getattr(self, key)
value = attribute or getattr(self, key, None)
if value is not None:
submit_kwargs[key] = value
if isinstance(subreddit, str):
_subreddit = self._reddit.subreddit(subreddit)
elif isinstance(subreddit, (Subreddit, UserSubreddit)):
Expand Down
Loading

0 comments on commit ccd48d5

Please sign in to comment.