Now solving issues with faulty imports. Still nothing functional.

This commit is contained in:
Griatch 2014-12-20 17:03:34 +01:00
parent 08d0442f9c
commit 8314d8ba5e
8 changed files with 77 additions and 37 deletions

View file

@ -14,7 +14,19 @@ class Channel(ChannelDB):
This is the base class for all Comms. Inherit from this to create different This is the base class for all Comms. Inherit from this to create different
types of communication channels. types of communication channels.
""" """
__metaclass__ = TypeclassBase
def __new__(cls, *args, **kwargs):
"""
We must define our Typeclasses as proxies. We also store the path
directly on the class, this is useful for managers.
"""
if hasattr(cls, "Meta"):
cls.Meta.proxy = True
else:
class Meta:
proxy = True
cls.Meta = Meta
return super(TypeclassBase, cls).__new__(*args, **kwargs)
# helper methods, for easy overloading # helper methods, for easy overloading

View file

@ -37,9 +37,21 @@ class Object(ObjectDB):
This is the base class for all in-game objects. Inherit from this This is the base class for all in-game objects. Inherit from this
to create different types of objects in the game. to create different types of objects in the game.
""" """
__metaclass__ = TypeclassBase def __new__(cls, *args, **kwargs):
"""
We must define our Typeclasses as proxies. We also store the path
directly on the class, this is useful for managers.
"""
if hasattr(cls, "Meta"):
cls.Meta.proxy = True
else:
class Meta:
proxy = True
cls.Meta = Meta
return super(Object, cls).__new__(*args, **kwargs)
# __init__ is only defined here in order to present docstring to API. # __init__ is only defined here in order to present docstring to API.
def __init__(self, dbobj): def __init__(self):
""" """
This is the root typeclass object, representing all entities This is the root typeclass object, representing all entities
that have an actual presence in-game. Objects generally have a that have an actual presence in-game. Objects generally have a
@ -190,7 +202,7 @@ class Object(ObjectDB):
this object speaks this object speaks
""" """
super(Object, self).__init__(dbobj) super(Object, self).__init__()
## methods inherited from the database object (overload them here) ## methods inherited from the database object (overload them here)

View file

@ -162,11 +162,6 @@ class PlayerDB(TypedObject, AbstractUser):
_GA(self, "save")() _GA(self, "save")()
cmdset_storage = property(cmdset_storage_get, cmdset_storage_set, cmdset_storage_del) cmdset_storage = property(cmdset_storage_get, cmdset_storage_set, cmdset_storage_del)
class Meta:
"Define Django meta options"
verbose_name = "Player"
verbose_name_plural = "Players"
# #
# PlayerDB main class properties and methods # PlayerDB main class properties and methods
# #

View file

@ -14,7 +14,6 @@ instead for most things).
import datetime import datetime
from django.conf import settings from django.conf import settings
from src.players.models import PlayerDB from src.players.models import PlayerDB
from src.typeclasses.models import TypeclassBase
from src.comms.models import ChannelDB from src.comms.models import ChannelDB
from src.utils import logger from src.utils import logger
__all__ = ("Player",) __all__ = ("Player",)
@ -28,9 +27,20 @@ class Player(PlayerDB):
""" """
Base typeclass for all Players. Base typeclass for all Players.
""" """
__metaclass__ = TypeclassBase def __new__(cls, *args, **kwargs):
"""
We must define our Typeclasses as proxies. We also store the path
directly on the class, this is useful for managers.
"""
if hasattr(cls, "Meta"):
cls.Meta.proxy = True
else:
class Meta:
proxy = True
cls.Meta = Meta
return super(Player, cls).__new__(*args, **kwargs)
def __init__(self, dbobj): def __init__(self):
""" """
This is the base Typeclass for all Players. Players represent This is the base Typeclass for all Players. Players represent
the person playing the game and tracks account info, password the person playing the game and tracks account info, password
@ -104,7 +114,7 @@ class Player(PlayerDB):
at_server_shutdown() at_server_shutdown()
""" """
super(Player, self).__init__(dbobj) super(Player, self).__init__()
## methods inherited from database model ## methods inherited from database model

View file

@ -113,9 +113,22 @@ class ScriptBase(ScriptDB):
Base class for scripts. Don't inherit from this, inherit Base class for scripts. Don't inherit from this, inherit
from the class 'Script' instead. from the class 'Script' instead.
""" """
__metaclass__ = TypeclassBase #__metaclass__ = TypeclassBase
# private methods # private methods
def __new__(cls, *args, **kwargs):
"""
We must define our Typeclasses as proxies. We also store the path
directly on the class, this is useful for managers.
"""
if hasattr(cls, "Meta"):
cls.Meta.proxy = True
else:
class Meta:
proxy = True
cls.Meta = Meta
return super(ScriptBase, cls).__new__(*args, **kwargs)
def __eq__(self, other): def __eq__(self, other):
""" """
This has to be located at this level, having it in the This has to be located at this level, having it in the
@ -355,7 +368,7 @@ class Script(ScriptBase):
the hooks called by the script machinery. the hooks called by the script machinery.
""" """
def __init__(self, dbobj): def __init__(self):
""" """
This is the base TypeClass for all Scripts. Scripts describe events, This is the base TypeClass for all Scripts. Scripts describe events,
timers and states in game, they can have a time component or describe timers and states in game, they can have a time component or describe
@ -442,7 +455,7 @@ class Script(ScriptBase):
""" """
super(Script, self).__init__(dbobj) super(Script, self).__init__()
def at_script_creation(self): def at_script_creation(self):
""" """

View file

@ -8,7 +8,7 @@ from django.db.models import Q
from src.utils import idmapper from src.utils import idmapper
from src.utils.utils import make_iter, variable_from_module from src.utils.utils import make_iter, variable_from_module
__all__ = ("AttributeManager", "TypedObjectManager") __all__ = ("TypedObjectManager", )
_GA = object.__getattribute__ _GA = object.__getattribute__
_Tag = None _Tag = None

View file

@ -742,24 +742,23 @@ class PermissionHandler(TagHandler):
# imported for access by other # imported for access by other
from src.utils.idmapper.base import SharedMemoryModelBase from src.utils.idmapper.base import SharedMemoryModelBase
class TypeclassBase(SharedMemoryModelBase): #class TypeclassBase(SharedMemoryModelBase):
""" # """
Metaclass which should be set for the root of model proxies # Metaclass which should be set for the root of model proxies
that don't define any new fields, like Object, Script etc. # that don't define any new fields, like Object, Script etc.
""" # """
def __init__(cls, *args, **kwargs): # def __new__(cls, name, bases, attrs):
""" # """
We must define our Typeclasses as proxies. We also store the path # We must define our Typeclasses as proxies. We also store the path
directly on the class, this is useful for managers. # directly on the class, this is useful for managers.
""" # """
super(TypeclassBase, cls).__init__(*args, **kwargs) # if hasattr(cls, "Meta"):
class Meta: # cls.Meta.proxy = True
# this is the important bit # else:
proxy = True # class Meta:
cls.Meta = Meta # proxy = True
# convenience for manager methods # cls.Meta = Meta
#cls.typename = cls.__name__ # return super(TypeclassBase, cls).__new__(name, bases, attrs)
#cls.path = "%s.%s" % (cls.__module__, cls.__name__)
class TypedObject(SharedMemoryModel): class TypedObject(SharedMemoryModel):

View file

@ -95,7 +95,6 @@ class SharedMemoryModelBase(ModelBase):
already has a wrapper of the given name, the automatic creation is skipped. Note: Remember to already has a wrapper of the given name, the automatic creation is skipped. Note: Remember to
document this auto-wrapping in the class header, this could seem very much like magic to the user otherwise. document this auto-wrapping in the class header, this could seem very much like magic to the user otherwise.
""" """
def create_wrapper(cls, fieldname, wrappername, editable=True, foreignkey=False): def create_wrapper(cls, fieldname, wrappername, editable=True, foreignkey=False):
"Helper method to create property wrappers with unique names (must be in separate call)" "Helper method to create property wrappers with unique names (must be in separate call)"
def _get(cls, fname): def _get(cls, fname):
@ -190,7 +189,6 @@ class SharedMemoryModelBase(ModelBase):
#print "wrapping %s -> %s" % (fieldname, wrappername) #print "wrapping %s -> %s" % (fieldname, wrappername)
create_wrapper(cls, fieldname, wrappername, editable=field.editable, foreignkey=foreignkey) create_wrapper(cls, fieldname, wrappername, editable=field.editable, foreignkey=foreignkey)
# django patch # django patch
# Evennia mod, based on Django Ticket #11560: https://code.djangoproject.com/ticket/11560 # Evennia mod, based on Django Ticket #11560: https://code.djangoproject.com/ticket/11560
# The actual patch is small and further down. # The actual patch is small and further down.
@ -432,6 +430,7 @@ class SharedMemoryModelBase(ModelBase):
super(SharedMemoryModelBase, cls).__init__(*args, **kwargs) super(SharedMemoryModelBase, cls).__init__(*args, **kwargs)
cls.typename = cls.__name__ cls.typename = cls.__name__
cls.path = "%s.%s" % (cls.__module__, cls.__name__) cls.path = "%s.%s" % (cls.__module__, cls.__name__)
print "shared __init__", cls
class SharedMemoryModel(Model): class SharedMemoryModel(Model):
# CL: setting abstract correctly to allow subclasses to inherit the default # CL: setting abstract correctly to allow subclasses to inherit the default