Skip to content

Commit

Permalink
Add support for specifying layout upon create collection
Browse files Browse the repository at this point in the history
(cherry picked from commit praw-dev/praw@9cce279)
  • Loading branch information
jsk56143 authored and LilSpazJoekp committed Jun 11, 2022
1 parent 2e16864 commit 3ec77a5
Show file tree
Hide file tree
Showing 9 changed files with 2,065 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Unreleased
- :meth:`.pin` to manage pinned submissions on the authenticated user's profile.
- :meth:`.update_display_layout` to update the display layout of posts in a
:class:`.Collection`.
- :meth:`.SubredditCollectionsModeration.create` keyword argument ``display_layout`` for
specifying a display layout when creating a :class:`.Collection`.

**Changed**

Expand Down
35 changes: 27 additions & 8 deletions asyncpraw/models/reddit/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ async def update_display_layout(self, display_layout: str):
"""Update the collection's display layout.
:param display_layout: Either ``"TIMELINE"`` for events or discussions or
``"GALLERY"`` for images or memes. Passing ``""`` or ``None`` will clear the
set layout and ``collection.display_layout`` will be ``None``, however, the
``"GALLERY"`` for images or memes. Passing ``None`` will clear the set
layout and ``collection.display_layout`` will be ``None``, however, the
collection will appear on Reddit as if ``display_layout`` is set to
``"TIMELINE"``.
Expand Down Expand Up @@ -465,14 +465,20 @@ def __init__(
super().__init__(reddit, _data)
self.subreddit = subreddit

async def create(self, title: str, description: str):
async def create(
self, title: str, description: str, display_layout: Optional[str] = None
):
"""Create a new :class:`.Collection`.
The authenticated account must have appropriate moderator permissions in the
subreddit this collection belongs to.
:param title: The title of the collection, up to 300 characters.
:param description: The description, up to 500 characters.
:param display_layout: Either ``"TIMELINE"`` for events or discussions or
``"GALLERY"`` for images or memes. Passing ``""`` or ``None`` will make the
collection appear on Reddit as if this is set to ``"TIMELINE"`` (default:
``None``).
:returns: The newly created :class:`.Collection`.
Expand All @@ -484,20 +490,33 @@ async def create(self, title: str, description: str):
new_collection = await sub.collections.mod.create("Title", "desc")
await new_collection.mod.add_post("bgibu9")
To specify the display layout as ``"GALLERY"`` when creating the collection:
.. code-block:: python
my_sub = await reddit.subreddit("test")
new_collection = await my_sub.collections.mod.create(
title="Title", description="desc", display_layout="GALLERY"
)
await new_collection.mod.add_post("bgibu9")
.. seealso::
:meth:`~.CollectionModeration.delete`
"""
if not self.subreddit._fetched:
await self.subreddit._fetch()
data = {
"sr_fullname": self.subreddit.fullname,
"title": title,
"description": description,
}
if display_layout:
data["display_layout"] = display_layout
return await self._reddit.post(
API_PATH["collection_create"],
data={
"sr_fullname": self.subreddit.fullname,
"title": title,
"description": description,
},
data=data,
)


Expand Down
Loading

0 comments on commit 3ec77a5

Please sign in to comment.