Run migrations! Another update to the tag structure, the previous migration did not correctly handle all tags, leaving some to get the wrong db_object fields. Also cleaned up the api for many of the Tag-related manager methods that now determins the db_model themselves without needing to give it as an argument. This resolves an issue with Permissions not being set correctly on the character level.

This commit is contained in:
Griatch 2017-01-25 22:06:54 +01:00
parent 5960985e65
commit 8b1d16fd5c
3 changed files with 16 additions and 18 deletions

View file

@ -1945,7 +1945,7 @@ class CmdExamine(ObjManipCommand):
if perms: if perms:
perms_string = (", ".join(perms)) perms_string = (", ".join(perms))
else: else:
perms_string = "Default" perms_string = "<None>"
if obj.is_superuser: if obj.is_superuser:
perms_string += " [Superuser]" perms_string += " [Superuser]"
@ -2004,9 +2004,10 @@ class CmdExamine(ObjManipCommand):
string += self.format_attributes(obj) string += self.format_attributes(obj)
# display Tags # display Tags
tags_string = utils.fill(", ".join(tag for tag in obj.tags.all()), indent=5) tags_string = utils.fill(", ".join("%s[%s]" % (tag, category)
for tag, category in obj.tags.all(return_key_and_category=True)), indent=5)
if tags_string: if tags_string:
string += "\n|wTags|n: %s" % tags_string string += "\n|wTags[category]|n: %s" % tags_string.strip()
# add the contents # add the contents
exits = [] exits = []

View file

@ -88,7 +88,8 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
attributes (list): The matching Attributes. attributes (list): The matching Attributes.
""" """
query = [("attribute__db_attrtype", attrtype)] dbmodel = self.model.__dbclass__.__name__.lower()
query = [("attribute__db_attrtype", attrtype), ("attribute__db_model", dbmodel)]
if obj: if obj:
query.append(("%s__id" % self.model.__name__.lower(), obj.id)) query.append(("%s__id" % self.model.__name__.lower(), obj.id))
if key: if key:
@ -149,7 +150,8 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
obj (list): Objects having the matching Attributes. obj (list): Objects having the matching Attributes.
""" """
query = [("db_attributes__db_attrtype", attrtype)] dbmodel = self.model.__dbclass__.__name__.lower()
query = [("db_attributes__db_attrtype", attrtype), ("db_attributes__db_model", dbmodel)]
if key: if key:
query.append(("db_attributes__db_key", key)) query.append(("db_attributes__db_key", key))
if category: if category:
@ -179,7 +181,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
# Tag manager methods # Tag manager methods
def get_tag(self, key=None, category=None, obj=None, tagtype=None, dbmodel="objectdb", global_search=False): def get_tag(self, key=None, category=None, obj=None, tagtype=None, global_search=False):
""" """
Return Tag objects by key, by category, by object (it is Return Tag objects by key, by category, by object (it is
stored on) or with a combination of those criteria. stored on) or with a combination of those criteria.
@ -192,9 +194,6 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
search for is. search for is.
tagtype (str, optional): One of None (normal tags), tagtype (str, optional): One of None (normal tags),
"alias" or "permission" "alias" or "permission"
dbobj (str, optional): A natural_key for which type of
entity this tag attaches to. Example, "objectdb" or
"scriptdb".
global_search (bool, optional): Include all possible tags, global_search (bool, optional): Include all possible tags,
not just tags on this object not just tags on this object
@ -205,6 +204,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
global _Tag global _Tag
if not _Tag: if not _Tag:
from evennia.typeclasses.models import Tag as _Tag from evennia.typeclasses.models import Tag as _Tag
dbmodel = self.model.__dbclass__.__name__.lower()
if global_search: if global_search:
# search all tags using the Tag model # search all tags using the Tag model
query = [("db_tagtype", tagtype), ("db_model", dbmodel)] query = [("db_tagtype", tagtype), ("db_model", dbmodel)]
@ -257,7 +257,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
return self.get_tag(key=key, category=category, obj=obj, tagtype="alias") return self.get_tag(key=key, category=category, obj=obj, tagtype="alias")
@returns_typeclass_list @returns_typeclass_list
def get_by_tag(self, key=None, category=None, tagtype=None, dbmodel="objectdb"): def get_by_tag(self, key=None, category=None, tagtype=None):
""" """
Return objects having tags with a given key or category or Return objects having tags with a given key or category or
combination of the two. combination of the two.
@ -268,11 +268,10 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
tagtype (str or None, optional): 'type' of Tag, by default tagtype (str or None, optional): 'type' of Tag, by default
this is either `None` (a normal Tag), `alias` or this is either `None` (a normal Tag), `alias` or
`permission`. `permission`.
dbmodel (str or None, optionsl): The naturalkey of the entity this Tag
attaches to. A string like "objectdb", "scriptdb" etc.
Returns: Returns:
objects (list): Objects with matching tag. objects (list): Objects with matching tag.
""" """
dbmodel = self.model.__dbclass__.__name__.lower()
query = [("db_tags__db_tagtype", tagtype), ("db_tags__db_model", dbmodel)] query = [("db_tags__db_tagtype", tagtype), ("db_tags__db_model", dbmodel)]
if key: if key:
query.append(("db_tags__db_key", key.lower())) query.append(("db_tags__db_key", key.lower()))
@ -306,7 +305,7 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
""" """
return self.get_by_tag(key=key, category=category, tagtype="alias") return self.get_by_tag(key=key, category=category, tagtype="alias")
def create_tag(self, key=None, category=None, data=None, tagtype=None, dbmodel="objectdb"): def create_tag(self, key=None, category=None, data=None, tagtype=None):
""" """
Create a new Tag of the base type associated with this Create a new Tag of the base type associated with this
object. This makes sure to create case-insensitive tags. object. This makes sure to create case-insensitive tags.
@ -322,9 +321,6 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
tagtype (str or None, optional): 'type' of Tag, by default tagtype (str or None, optional): 'type' of Tag, by default
this is either `None` (a normal Tag), `alias` or this is either `None` (a normal Tag), `alias` or
`permission`. `permission`.
dbmodel (str, optional): Which model type this Tag attaches to.
This is a natural_key like "dbobject" or "dbscript".
Notes: Notes:
The `data` field is not part of the uniqueness of the tag: The `data` field is not part of the uniqueness of the tag:
Setting `data` on an existing tag will overwrite the old Setting `data` on an existing tag will overwrite the old
@ -336,8 +332,9 @@ class TypedObjectManager(idmapper.manager.SharedMemoryManager):
data = str(data) if data is not None else None data = str(data) if data is not None else None
# try to get old tag # try to get old tag
dbmodel = self.model.__dbclass__.__name__.lower()
tag = self.get_tag(key=key, category=category, tagtype=tagtype, tag = self.get_tag(key=key, category=category, tagtype=tagtype,
dbmodel=dbmodel, global_search=True) global_search=True)
if tag and data is not None: if tag and data is not None:
# get tag from list returned by get_tag # get tag from list returned by get_tag
tag = tag[0] tag = tag[0]

View file

@ -259,7 +259,7 @@ class TagHandler(object):
# will overload data on an existing tag since that is not # will overload data on an existing tag since that is not
# considered part of making the tag unique) # considered part of making the tag unique)
tagobj = self.obj.__class__.objects.create_tag(key=tagstr, category=category, data=data, tagobj = self.obj.__class__.objects.create_tag(key=tagstr, category=category, data=data,
tagtype=self._tagtype, dbmodel=self._model) tagtype=self._tagtype)
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)