Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying layout upon create collection #186

Merged
merged 1 commit into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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