Add ATTRIBUTE_STORED_MODEL_RENAME setting to manage renamed models stored in Attributes.

This commit is contained in:
Griatch 2017-09-07 22:04:37 +02:00
parent 3c1544ca16
commit 14fc12fb6b
2 changed files with 16 additions and 0 deletions

View file

@ -250,6 +250,17 @@ DATABASES = {
# If you get errors about the database having gone away after long idle
# periods, shorten this value (e.g. MySQL defaults to a timeout of 8 hrs)
CONN_MAX_AGE = 3600 * 7
# When removing or renaming models, such models stored in Attributes may
# become orphaned and will return as None. If the change is a rename (that
# is, there is a 1:1 pk mapping between the old and the new), the unserializer
# can convert old to new when retrieving them. This is a list of tuples
# (old_natural_key, new_natural_key). Note that Django ContentTypes'
# natural_keys are themselves tuples (appname, modelname). If new_natural_key
# does not exist, `None` will be returned and stored back as if no replacement
# was set.
ATTRIBUTE_STORED_MODEL_RENAME = [
((u"players", u"playerdb"), (u"accounts", u"accountdb")),
((u"typeclasses", u"defaultplayer"), (u"typeclasses", u"defaultaccount"))]
######################################################################

View file

@ -115,13 +115,18 @@ def _init_globals():
_FROM_MODEL_MAP = defaultdict(str)
_FROM_MODEL_MAP.update(dict((c.model, c.natural_key()) for c in ContentType.objects.all()))
if not _TO_MODEL_MAP:
from django.conf import settings
_TO_MODEL_MAP = defaultdict(str)
_TO_MODEL_MAP.update(dict((c.natural_key(), c.model_class()) for c in ContentType.objects.all()))
for src_key, dst_key in settings.ATTRIBUTE_STORED_MODEL_RENAME:
_TO_MODEL_MAP[src_key] = _TO_MODEL_MAP.get(dst_key, None)
# handle old player models by converting them to accounts
_TO_MODEL_MAP[(u"players", u"playerdb")] = _TO_MODEL_MAP[(u"accounts", u"accountdb")]
_TO_MODEL_MAP[(u"typeclasses", u"defaultplayer")] = _TO_MODEL_MAP[(u"typeclasses", u"defaultaccount")]
if not _SESSION_HANDLER:
from evennia.server.sessionhandler import SESSION_HANDLER as _SESSION_HANDLER
#
# SaverList, SaverDict, SaverSet - Attribute-specific helper classes and functions
#