Fixes towards resolving issue99.
This commit is contained in:
parent
933e29afee
commit
72bb8ac667
2 changed files with 32 additions and 3 deletions
|
|
@ -14,11 +14,13 @@ That an object is controlled by a player/user is just defined by its
|
||||||
'user' property being set. This means a user may switch which object
|
'user' property being set. This means a user may switch which object
|
||||||
they control by simply linking to a new object's user property.
|
they control by simply linking to a new object's user property.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from src.typeclasses.typeclass import TypeClass
|
from src.typeclasses.typeclass import TypeClass
|
||||||
from src.commands.cmdsethandler import CmdSetHandler
|
from src.commands.cmdsethandler import CmdSetHandler
|
||||||
from src.scripts.scripthandler import ScriptHandler
|
from src.scripts.scripthandler import ScriptHandler
|
||||||
#from src.permissions.permissions import has_perm
|
|
||||||
from src.objects.exithandler import EXITHANDLER
|
from src.objects.exithandler import EXITHANDLER
|
||||||
|
from src.utils import utils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Base class to inherit from.
|
# Base class to inherit from.
|
||||||
|
|
@ -48,12 +50,13 @@ class Object(TypeClass):
|
||||||
try:
|
try:
|
||||||
dummy = object.__getattribute__(dbobj, 'scripts')
|
dummy = object.__getattribute__(dbobj, 'scripts')
|
||||||
create_scripts = type(dbobj.scripts) != ScriptHandler
|
create_scripts = type(dbobj.scripts) != ScriptHandler
|
||||||
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
create_scripts = True
|
create_scripts = True
|
||||||
if create_cmdset:
|
if create_cmdset:
|
||||||
dbobj.cmdset = CmdSetHandler(dbobj)
|
dbobj.cmdset = CmdSetHandler(dbobj)
|
||||||
if dbobj.player:
|
if utils.inherits_from(self, settings.BASE_CHARACTER_TYPECLASS):
|
||||||
dbobj.cmdset.outside_access = False
|
dbobj.cmdset.outside_access = False
|
||||||
if create_scripts:
|
if create_scripts:
|
||||||
dbobj.scripts = ScriptHandler(dbobj)
|
dbobj.scripts = ScriptHandler(dbobj)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -249,3 +249,29 @@ def validate_email_address(emailaddress):
|
||||||
return True # Email address is fine.
|
return True # Email address is fine.
|
||||||
else:
|
else:
|
||||||
return False # Email address has funny characters.
|
return False # Email address has funny characters.
|
||||||
|
|
||||||
|
|
||||||
|
def inherits_from(obj, parent):
|
||||||
|
"""
|
||||||
|
Takes an object and tries to determine if it inherits
|
||||||
|
from parent. What differs this function from e.g. isinstance()
|
||||||
|
is that obj may be both an instance and a class, and parent
|
||||||
|
may be an instance, a class, or the python path to a class (counting
|
||||||
|
from the evennia root directory).
|
||||||
|
"""
|
||||||
|
|
||||||
|
if callable(obj):
|
||||||
|
# this is a class
|
||||||
|
obj_paths = ["%s.%s" % (mod.__module__, mod.__name__) for mod in obj.mro()]
|
||||||
|
else:
|
||||||
|
obj_paths = ["%s.%s" % (mod.__module__, mod.__name__) for mod in obj.__class__.mro()]
|
||||||
|
|
||||||
|
if isinstance(parent, basestring):
|
||||||
|
# a given string path, for direct matching
|
||||||
|
parent_path = parent
|
||||||
|
elif callable(parent):
|
||||||
|
# this is a class
|
||||||
|
parent_path = "%s.%s" % (parent.__module__, parent.__name__)
|
||||||
|
else:
|
||||||
|
parent_path = "%s.%s" % (parent.__class__.__module__, parent.__class__.__name__)
|
||||||
|
return any(True for obj_path in obj_paths if obj_path == parent_path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue