mirror of
https://github.com/evennia/evennia.git
synced 2026-03-27 10:16:32 +01:00
Attempt at making bulk deletion clear out handlers, to remove the problem of orphaned Attributes.
This commit is contained in:
parent
02a4ac5231
commit
b67faf45d9
6 changed files with 42 additions and 5 deletions
|
|
@ -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"
|
||||
|
|
|
|||
10
evennia/typeclasses/apps.py
Normal file
10
evennia/typeclasses/apps.py
Normal 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
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
28
evennia/typeclasses/signals.py
Normal file
28
evennia/typeclasses/signals.py
Normal 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
|
||||
|
|
@ -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 "")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue