Attempt at making bulk deletion clear out handlers, to remove the problem of orphaned Attributes.

This commit is contained in:
Tehom 2017-02-03 12:58:00 -05:00 committed by Griatch
parent 02a4ac5231
commit b67faf45d9
6 changed files with 42 additions and 5 deletions

View file

@ -8,3 +8,5 @@ inherit from the models in this package. Here is also were the
Attribute and Tag models are defined along with their handlers.
"""
default_app_config = "evennia.typeclasses.apps.TypeclassesConfig"

View file

@ -0,0 +1,10 @@
from __future__ import unicode_literals
from django.apps import AppConfig
class TypeclassesConfig(AppConfig):
name = 'typeclasses'
def ready(self):
from . import signals

View file

@ -99,6 +99,7 @@ class Attribute(SharedMemoryModel):
class Meta(object):
"Define Django meta options"
verbose_name = "Evennia Attribute"
app_label = 'typeclasses'
# read-only wrappers
key = property(lambda self: self.db_key)

View file

@ -606,11 +606,6 @@ class TypedObject(SharedMemoryModel):
"""
global TICKER_HANDLER
self.permissions.clear()
self.attributes.clear()
self.aliases.clear()
if hasattr(self, "nicks"):
self.nicks.clear()
# scrambling properties
self.delete = self._deleted

View file

@ -0,0 +1,28 @@
from .models import TypedObject
from django.db.models.signals import pre_delete
def get_subclasses(cls):
result = []
classes_to_inspect = [cls]
while classes_to_inspect:
class_to_inspect = classes_to_inspect.pop()
for subclass in class_to_inspect.__subclasses__():
if subclass not in result:
result.append(subclass)
classes_to_inspect.append(subclass)
return result
def remove_attributes_on_delete(sender, instance, **kwargs):
print "remove_attribtes_on_delete called in instance %s" % instance
instance.permissions.clear()
instance.attributes.clear()
instance.aliases.clear()
if hasattr(instance, "nicks"):
instance.nicks.clear()
for subclass in get_subclasses(TypedObject):
pre_delete.connect(remove_attributes_on_delete, subclass)
print "connected to subclass %s" % subclass

View file

@ -63,6 +63,7 @@ class Tag(models.Model):
verbose_name = "Tag"
unique_together = (('db_key', 'db_category', 'db_tagtype', 'db_model'),)
index_together = (('db_key', 'db_category', 'db_tagtype', 'db_model'),)
app_label = 'typeclasses'
def __unicode__(self):
return u"<Tag: %s%s>" % (self.db_key, "(category:%s)" % self.db_category if self.db_category else "")