Change TagHandler.add/has(tag=...) kwarg to key= for consistency. Resolve #2396
This commit is contained in:
parent
7639b98bf3
commit
00b29a693d
2 changed files with 11 additions and 9 deletions
|
|
@ -112,6 +112,8 @@ Up requirements to Django 3.2+, Twisted 21+
|
||||||
to avoid known security issues with players entering MXP links.
|
to avoid known security issues with players entering MXP links.
|
||||||
- Add browser name to webclient `CLIENT_NAME` in `session.protocol_flags`, e.g.
|
- Add browser name to webclient `CLIENT_NAME` in `session.protocol_flags`, e.g.
|
||||||
`"Evennia webclient (websocket:firefox)"` or `"evennia webclient (ajax:chrome)"`.
|
`"Evennia webclient (websocket:firefox)"` or `"evennia webclient (ajax:chrome)"`.
|
||||||
|
- `TagHandler.add/has(tag=...)` kwarg changed to `add/has(key=...)` for consistency
|
||||||
|
with other handlers.
|
||||||
|
|
||||||
### Evennia 0.9.5 (2019-2020)
|
### Evennia 0.9.5 (2019-2020)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -290,12 +290,12 @@ class TagHandler(object):
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
self._catcache = {}
|
self._catcache = {}
|
||||||
|
|
||||||
def add(self, tag=None, category=None, data=None):
|
def add(self, key=None, category=None, data=None):
|
||||||
"""
|
"""
|
||||||
Add a new tag to the handler.
|
Add a new tag to the handler.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
tag (str or list): The name of the tag to add. If a list,
|
key (str or list): The name of the tag to add. If a list,
|
||||||
add several Tags.
|
add several Tags.
|
||||||
category (str, optional): Category of Tag. `None` is the default category.
|
category (str, optional): Category of Tag. `None` is the default category.
|
||||||
data (str, optional): Info text about the tag(s) added.
|
data (str, optional): Info text about the tag(s) added.
|
||||||
|
|
@ -308,11 +308,11 @@ class TagHandler(object):
|
||||||
will be created.
|
will be created.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not tag:
|
if not key:
|
||||||
return
|
return
|
||||||
if not self._cache_complete:
|
if not self._cache_complete:
|
||||||
self._fullcache()
|
self._fullcache()
|
||||||
for tagstr in make_iter(tag):
|
for tagstr in make_iter(key):
|
||||||
if not tagstr:
|
if not tagstr:
|
||||||
continue
|
continue
|
||||||
tagstr = str(tagstr).strip().lower()
|
tagstr = str(tagstr).strip().lower()
|
||||||
|
|
@ -327,12 +327,12 @@ class TagHandler(object):
|
||||||
getattr(self.obj, self._m2m_fieldname).add(tagobj)
|
getattr(self.obj, self._m2m_fieldname).add(tagobj)
|
||||||
self._setcache(tagstr, category, tagobj)
|
self._setcache(tagstr, category, tagobj)
|
||||||
|
|
||||||
def has(self, tag=None, category=None, return_list=False):
|
def has(self, key=None, category=None, return_list=False):
|
||||||
"""
|
"""
|
||||||
Checks if the given Tag (or list of Tags) exists on the object.
|
Checks if the given Tag (or list of Tags) exists on the object.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
tag (str or iterable): The Tag key or tags to check for.
|
key (str or iterable): The Tag key or tags to check for.
|
||||||
If `None`, search by category.
|
If `None`, search by category.
|
||||||
category (str, optional): Limit the check to Tags with this
|
category (str, optional): Limit the check to Tags with this
|
||||||
category (note, that `None` is the default category).
|
category (note, that `None` is the default category).
|
||||||
|
|
@ -347,8 +347,8 @@ class TagHandler(object):
|
||||||
"""
|
"""
|
||||||
ret = []
|
ret = []
|
||||||
category = category.strip().lower() if category is not None else None
|
category = category.strip().lower() if category is not None else None
|
||||||
if tag:
|
if key:
|
||||||
for tag_str in make_iter(tag):
|
for tag_str in make_iter(key):
|
||||||
tag_str = tag_str.strip().lower()
|
tag_str = tag_str.strip().lower()
|
||||||
ret.extend(bool(tag) for tag in self._getcache(tag_str, category))
|
ret.extend(bool(tag) for tag in self._getcache(tag_str, category))
|
||||||
elif category:
|
elif category:
|
||||||
|
|
@ -515,7 +515,7 @@ class TagHandler(object):
|
||||||
keys[tup[1]].append(tup[0])
|
keys[tup[1]].append(tup[0])
|
||||||
data[tup[1]] = tup[2] # overwrite previous
|
data[tup[1]] = tup[2] # overwrite previous
|
||||||
for category, key in keys.items():
|
for category, key in keys.items():
|
||||||
self.add(tag=key, category=category, data=data.get(category, None))
|
self.add(key=key, category=category, data=data.get(category, None))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return ",".join(self.all())
|
return ",".join(self.all())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue