Add helper function to get the plural tag

This commit is contained in:
JonnyWong16 2021-01-24 14:36:38 -08:00
parent cfc5bdae26
commit 1b378d3f1c
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
2 changed files with 11 additions and 2 deletions

View file

@ -5,7 +5,7 @@ from urllib.parse import quote_plus, urlencode
from plexapi import log, utils
from plexapi.exceptions import BadRequest, NotFound, UnknownType, Unsupported
from plexapi.utils import tag_helper
from plexapi.utils import get_plural_attr, tag_helper
DONT_RELOAD_FOR_KEYS = ['key', 'session']
OPERATORS = {
@ -462,7 +462,7 @@ class PlexPartialObject(PlexObject):
"""
if not isinstance(items, list):
items = [items]
value = getattr(self, tag + 's')
value = getattr(self, get_plural_attr(tag))
existing_cols = [t.tag for t in value if t and remove is False]
d = tag_helper(tag, existing_cols + items, locked, remove)
self.edit(**d)

View file

@ -335,6 +335,15 @@ def download(url, token, filename=None, savepath=None, session=None, chunksize=4
return fullpath
def get_plural_attr(tag):
if tag == 'country':
return 'countries'
elif tag == 'similar':
return 'similar'
else:
return tag + 's'
def tag_helper(tag, items, locked=True, remove=False):
""" Simple tag helper for editing a object. """
if not isinstance(items, list):