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 additional SubredditFlairTemplate params #1138

Merged

Conversation

jackodsteel
Copy link
Contributor

Specifically, added allowable_content and max_emojis params.

As discussed as wanted in this Reddit thread by /u/Levi-Ackerbot:
https://www.reddit.com/r/redditdev/comments/dy1qw7/is_there_any_way_to_limit_the_amount_of_emojis_in/

@jarhill0
Copy link
Contributor

Hi @jackodsteel,

The PR failed to pass CI because of an error in the documentation. Here's a link to the CI build. The error is

CHANGES.rst:15:py:meth reference target not found: SubredditFlairTemplates.add

I believe you can fix the error by replacing

:meth:`~SubredditFlairTemplates.add` and :meth:`~SubredditFlairTemplates.update`

with

:meth:`~.SubredditFlairTemplates.add` and :meth:`~.SubredditFlairTemplates.update`

The dot is necessary to tell Sphinx that the full path of the class (which happens to be praw.models.reddit.subreddit.SubredditFlairTemplates) has been omitted.

@jackodsteel jackodsteel force-pushed the add-additional-flair-template-params branch from 11d6f11 to 2f1ce80 Compare November 21, 2019 00:56
Specifically, added allowable_content and max_emojis params.

As discussed as wanted in this Reddit thread by /u/Levi-Ackerbot:
https://www.reddit.com/r/redditdev/comments/dy1qw7/is_there_any_way_to_limit_the_amount_of_emojis_in/
@jackodsteel jackodsteel force-pushed the add-additional-flair-template-params branch from 2f1ce80 to 828c3d5 Compare November 21, 2019 01:08
@jackodsteel
Copy link
Contributor Author

My bad! Checks are passing now @jarhill0

@jarhill0
Copy link
Contributor

Thanks for the PR!

Unrelated to your changes, I'm not happy with the existing behavior of these methods, which seems to reset all parameters not passed to their default values. For example, updating the text of a template resets its text color. This behavior predates your changes and I'm not sure what exactly to do about it, but it's unrelated to the scope of this PR.

There is one thing I noticed about your changes in playing around with them, which is that I can't seem to set allowable_content='emoji'. Here's part of my REPL session:


In [5]: ft = subreddit.flair.templates

In [8]: ft.update('11c32eee-1482-11e9-bfc0-0efc81a5e8e8', allowable_content='emo
   ...: ji')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-ecb84a90731c> in <module>()
----> 1 ft.update('11c32eee-1482-11e9-bfc0-0efc81a5e8e8', allowable_content='emoji')

TypeError: update() missing 1 required positional argument: 'text'

In [9]: ft.update('11c32eee-1482-11e9-bfc0-0efc81a5e8e8', allowable_content='emo
   ...: ji', text='')
---------------------------------------------------------------------------
APIException                              Traceback (most recent call last)
<ipython-input-9-597c2b5ae6e4> in <module>()
----> 1 ft.update('11c32eee-1482-11e9-bfc0-0efc81a5e8e8', allowable_content='emoji', text='')

~/PycharmProjects/jarhill0praw/praw/models/reddit/subreddit.py in update(self, template_id, text, css_class, text_editable, background_color, text_color, mod_only, allowable_content, max_emojis)
   1361             "max_emojis": max_emojis,
   1362         }
-> 1363         self.subreddit._reddit.post(url, data=data)
   1364 
   1365 

~/PycharmProjects/jarhill0praw/praw/reddit.py in post(self, path, data, files, params)
    527             "POST", path, data=data or {}, files=files, params=params
    528         )
--> 529         return self._objector.objectify(data)
    530 
    531     def put(self, path, data=None):

~/PycharmProjects/jarhill0praw/praw/objector.py in objectify(self, data)
    156             errors = data["json"]["errors"]
    157             if len(errors) == 1:
--> 158                 raise APIException(*errors[0])
    159             assert not errors
    160         elif isinstance(data, dict):

APIException: FLAIR_TEXT_DISALLOWED: 'Text is not allowed in this flair' on field 'text'

Here, PRAW is enforcing that I pass the text parameter, but the API is responding with an error if I pass the text parameter and try to set allowable_content='emoji'.

I'll need to take some time later to look over this PR fully, but it looks like it shouldn't be too much trouble to get it merged.

…ditional-flair-template-params

� Conflicts:
�	CHANGES.rst
@jackodsteel
Copy link
Contributor Author

jackodsteel commented Nov 21, 2019

Here, PRAW is enforcing that I pass the text parameter, but the API is responding with an error if I pass the text parameter and try to set allowable_content='emoji'.

The issue you're seeing is that if you set allowable_content='emoji then your text must be valid "emoji text" to go with it, and emojis need to be enabled.

To work successfully first make sure emojis are enabled on your test sub at:
https://www.reddit.com/r/SUBREDDIT/about/emojis
Go to top right (only works in redesign, and I can't find an API endpoint to do this 😞) and click emoji settings and make sure emojis are enabled.

Then to add/edit a flair template with allowable_content='emoji, you need the text to match up with some emojis e.g. text=':doge:'. It cannot be an empty string for whatever reason.

So I think it is working as it should, but the API is pretty unclear. I've updated the docs to better explain the requirement.

Note that these two commands succeed:

ft.add(text=":doge:", allowable_content='emoji')
ft.update(template_id="b14c1ed4-0c03-11ea-b1a6-0e09f42e0501", text=":doge:", allowable_content="emoji")

Now properly explain that of set to 'emoji' then the 'text' param
  is constrained to valid emoji strings
@jackodsteel
Copy link
Contributor Author

Unrelated to your changes, I'm not happy with the existing behavior of these methods, which seems to reset all parameters not passed to their default values.

I agree about this being a bad behaviour. I think it should be fairly simple to populate the data with the existing then overwrite with new, but like you say that's an issue for another PR. I've opened #1139 to track it.

I could probably get to it some time next week, but otherwise if you want to do it feel free.

Copy link
Member

@bboe bboe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor modification requests. Otherwise this looks great. Thanks!

praw/models/reddit/subreddit.py Outdated Show resolved Hide resolved
praw/models/reddit/subreddit.py Outdated Show resolved Hide resolved
praw/models/reddit/subreddit.py Outdated Show resolved Hide resolved
praw/models/reddit/subreddit.py Outdated Show resolved Hide resolved
praw/models/reddit/subreddit.py Outdated Show resolved Hide resolved
@jackodsteel jackodsteel force-pushed the add-additional-flair-template-params branch from 2674fa6 to 8f0c462 Compare December 3, 2019 05:10
@jackodsteel jackodsteel requested a review from bboe December 4, 2019 03:08
@bboe bboe merged commit 3be7569 into praw-dev:master Dec 4, 2019
@bboe
Copy link
Member

bboe commented Dec 4, 2019

Thanks for the pull request! You're awesome. 🎆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants