One needs to turn off all imports of typeclasses in __init__ or django will create migrations for them. This might be interesting for the future but not for development.

This commit is contained in:
Griatch 2014-12-23 11:53:32 +01:00
parent 749715a193
commit 969b947ba0
8 changed files with 50 additions and 45 deletions

4
ev.py
View file

@ -100,7 +100,7 @@ from src.help.models import HelpEntry
from src.typeclasses.models import Attribute from src.typeclasses.models import Attribute
# players # players
from src.players.player import Player from src.players.player import DefaultPlayer
from src.players.models import PlayerDB from src.players.models import PlayerDB
# commands # commands
@ -119,7 +119,7 @@ from src.comms.models import Msg, ChannelDB
from src.comms.comms import Channel from src.comms.comms import Channel
# objects # objects
from src.objects.objects import Object, Character, Room, Exit from src.objects.objects import DefaultObject, DefaultCharacter, DefaultRoom, DefaultExit
# utils # utils

View file

@ -843,3 +843,4 @@ class ObjectDB(TypedObject):
# Perform the deletion of the object # Perform the deletion of the object
super(ObjectDB, self).delete() super(ObjectDB, self).delete()
return True return True

View file

@ -33,7 +33,7 @@ _DA = object.__delattr__
# Base class to inherit from. # Base class to inherit from.
# #
class Object(ObjectDB): class DefaultObject(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.
@ -194,7 +194,7 @@ class Object(ObjectDB):
this object speaks this object speaks
""" """
super(Object, self).__init__(*args, **kwargs) super(DefaultObject, self).__init__(*args, **kwargs)
## methods inherited from the database object (overload them here) ## methods inherited from the database object (overload them here)
@ -268,7 +268,7 @@ class Object(ObjectDB):
if searchdata.lower() in ("me", "self",): if searchdata.lower() in ("me", "self",):
return self return self
return super(Object, self).search(searchdata, return super(DefaultObject, self).search(searchdata,
global_search=global_search, global_search=global_search,
use_nicks=use_nicks, use_nicks=use_nicks,
typeclass=typeclass, typeclass=typeclass,
@ -305,7 +305,7 @@ class Object(ObjectDB):
# searchdata is a string; wrap some common self-references # searchdata is a string; wrap some common self-references
if searchdata.lower() in ("me", "self",): if searchdata.lower() in ("me", "self",):
return self.player return self.player
return super(Object, self).search_player(searchdata, quiet=quiet) return super(DefaultObject, self).search_player(searchdata, quiet=quiet)
def execute_cmd(self, raw_string, sessid=None, **kwargs): def execute_cmd(self, raw_string, sessid=None, **kwargs):
""" """
@ -333,7 +333,7 @@ class Object(ObjectDB):
useful for coders intending to implement some sort of nested useful for coders intending to implement some sort of nested
command structure. command structure.
""" """
return super(Object, self).execute_cmd(raw_string, sessid=sessid, **kwargs) return super(DefaultObject, self).execute_cmd(raw_string, sessid=sessid, **kwargs)
def msg(self, text=None, from_obj=None, sessid=None, **kwargs): def msg(self, text=None, from_obj=None, sessid=None, **kwargs):
""" """
@ -347,7 +347,7 @@ class Object(ObjectDB):
default to self.sessid or from_obj.sessid. default to self.sessid or from_obj.sessid.
""" """
super(Object, self).msg(text=text, from_obj=from_obj, sessid=sessid, **kwargs) super(DefaultObject, self).msg(text=text, from_obj=from_obj, sessid=sessid, **kwargs)
def msg_contents(self, text=None, exclude=None, from_obj=None, **kwargs): def msg_contents(self, text=None, exclude=None, from_obj=None, **kwargs):
""" """
@ -356,7 +356,7 @@ class Object(ObjectDB):
exclude is a list of objects not to send to. See self.msg() for exclude is a list of objects not to send to. See self.msg() for
more info. more info.
""" """
super(Object, self).msg_contents(text, exclude=exclude, super(DefaultObject, self).msg_contents(text, exclude=exclude,
from_obj=from_obj, **kwargs) from_obj=from_obj, **kwargs)
def move_to(self, destination, quiet=False, def move_to(self, destination, quiet=False,
@ -387,7 +387,7 @@ class Object(ObjectDB):
emit_to_obj. emit_to_obj.
""" """
return super(Object, self).move_to(destination, quiet=quiet, return super(DefaultObject, self).move_to(destination, quiet=quiet,
emit_to_obj=emit_to_obj, emit_to_obj=emit_to_obj,
use_destination=use_destination) use_destination=use_destination)
@ -400,9 +400,9 @@ class Object(ObjectDB):
new_key (string) - new key/name of copied object. If new_key is not new_key (string) - new key/name of copied object. If new_key is not
specified, the copy will be named specified, the copy will be named
<old_key>_copy by default. <old_key>_copy by default.
Returns: Object (copy of this one) Returns: DefaultObject (copy of this one)
""" """
return super(Object, self).copy(new_key=new_key) return super(DefaultObject, self).copy(new_key=new_key)
def delete(self): def delete(self):
""" """
@ -415,7 +415,7 @@ class Object(ObjectDB):
were errors during deletion or deletion otherwise were errors during deletion or deletion otherwise
failed. failed.
""" """
return super(Object, self).delete() return super(DefaultObject, self).delete()
# methods inherited from the typeclass system # methods inherited from the typeclass system
@ -434,7 +434,7 @@ class Object(ObjectDB):
Returns: Boolean Returns: Boolean
""" """
return super(Object, self).is_typeclass(typeclass, exact=exact) return super(DefaultObject, self).is_typeclass(typeclass, exact=exact)
def swap_typeclass(self, new_typeclass, clean_attributes=False, no_default=True): def swap_typeclass(self, new_typeclass, clean_attributes=False, no_default=True):
""" """
@ -470,7 +470,7 @@ class Object(ObjectDB):
""" """
return super(Object, self).swap_typeclass(new_typeclass, return super(DefaultObject, self).swap_typeclass(new_typeclass,
clean_attributes=clean_attributes, no_default=no_default) clean_attributes=clean_attributes, no_default=no_default)
def access(self, accessing_obj, access_type='read', default=False, **kwargs): def access(self, accessing_obj, access_type='read', default=False, **kwargs):
@ -483,7 +483,7 @@ class Object(ObjectDB):
default (bool) - what to return if no lock of access_type was found default (bool) - what to return if no lock of access_type was found
**kwargs - passed to at_access hook along with result,accessing_obj and access_type **kwargs - passed to at_access hook along with result,accessing_obj and access_type
""" """
result = super(Object, self).access(accessing_obj, access_type=access_type, default=default) result = super(DefaultObject, self).access(accessing_obj, access_type=access_type, default=default)
self.at_access(result, accessing_obj, access_type, **kwargs) self.at_access(result, accessing_obj, access_type, **kwargs)
return result return result
@ -504,7 +504,7 @@ class Object(ObjectDB):
permission on the object. permission on the object.
(example: 'Builders') (example: 'Builders')
""" """
return super(Object, self).check_permstring(permstring) return super(DefaultObject, self).check_permstring(permstring)
def __eq__(self, other): def __eq__(self, other):
""" """
@ -901,11 +901,12 @@ class Object(ObjectDB):
""" """
return message return message
# #
# Base Character object # Base Character object
# #
class Character(Object): class DefaultCharacter(DefaultObject):
""" """
This is just like the Object except it implements its own This is just like the Object except it implements its own
version of the at_object_creation to set up the script version of the at_object_creation to set up the script
@ -921,7 +922,7 @@ class Character(Object):
you want to fundamentally change how a Character object works). you want to fundamentally change how a Character object works).
""" """
super(Character, self).basetype_setup() super(DefaultCharacter, self).basetype_setup()
self.locks.add(";".join(["get:false()", # noone can pick up the character self.locks.add(";".join(["get:false()", # noone can pick up the character
"call:false()"])) # no commands can be called on character from outside "call:false()"])) # no commands can be called on character from outside
# add the default cmdset # add the default cmdset
@ -982,7 +983,7 @@ class Character(Object):
# Base Room object # Base Room object
# #
class Room(Object): class DefaultRoom(DefaultObject):
""" """
This is the base room object. It's just like any Object except its This is the base room object. It's just like any Object except its
location is None. location is None.
@ -993,7 +994,7 @@ class Room(Object):
(since default is None anyway) (since default is None anyway)
""" """
super(Room, self).basetype_setup() super(DefaultRoom, self).basetype_setup()
self.locks.add(";".join(["get:false()", self.locks.add(";".join(["get:false()",
"puppet:false()"])) # would be weird to puppet a room ... "puppet:false()"])) # would be weird to puppet a room ...
self.location = None self.location = None
@ -1003,7 +1004,7 @@ class Room(Object):
# Base Exit object # Base Exit object
# #
class Exit(Object): class DefaultExit(DefaultObject):
""" """
This is the base exit object - it connects a location to another. This is the base exit object - it connects a location to another.
This is done by the exit assigning a "command" on itself with the This is done by the exit assigning a "command" on itself with the
@ -1079,7 +1080,7 @@ class Exit(Object):
You should normally not need to overload this - if you do make sure you You should normally not need to overload this - if you do make sure you
include all the functionality in this method. include all the functionality in this method.
""" """
super(Exit, self).basetype_setup() super(DefaultExit, self).basetype_setup()
# setting default locks (overload these in at_object_creation() # setting default locks (overload these in at_object_creation()
self.locks.add(";".join(["puppet:false()", # would be weird to puppet an exit ... self.locks.add(";".join(["puppet:false()", # would be weird to puppet an exit ...

View file

@ -24,7 +24,7 @@ _MULTISESSION_MODE = settings.MULTISESSION_MODE
_CMDSET_PLAYER = settings.CMDSET_PLAYER _CMDSET_PLAYER = settings.CMDSET_PLAYER
_CONNECT_CHANNEL = None _CONNECT_CHANNEL = None
class Player(PlayerDB): class DefaultPlayer(PlayerDB):
""" """
Base typeclass for all Players. Base typeclass for all Players.
""" """
@ -105,7 +105,7 @@ class Player(PlayerDB):
at_server_shutdown() at_server_shutdown()
""" """
super(Player, self).__init__(*args, **kwargs) super(DefaultPlayer, self).__init__(*args, **kwargs)
## methods inherited from database model ## methods inherited from database model
@ -116,7 +116,7 @@ class Player(PlayerDB):
the server. the server.
text (string) - text data to send text (string) - text data to send
from_obj (Object/Player) - source object of message to send from_obj (Object/DefaultPlayer) - source object of message to send
sessid - the session id of the session to send to. If not given, sessid - the session id of the session to send to. If not given,
return to all sessions connected to this player. This is usually only return to all sessions connected to this player. This is usually only
relevant when using msg() directly from a player-command (from relevant when using msg() directly from a player-command (from
@ -124,7 +124,7 @@ class Player(PlayerDB):
handles the sessid). handles the sessid).
kwargs - extra data to send through protocol kwargs - extra data to send through protocol
""" """
super(Player, self).msg(text=text, from_obj=from_obj, sessid=sessid, **kwargs) super(DefaultPlayer, self).msg(text=text, from_obj=from_obj, sessid=sessid, **kwargs)
def swap_character(self, new_character, delete_old_character=False): def swap_character(self, new_character, delete_old_character=False):
""" """
@ -135,7 +135,7 @@ class Player(PlayerDB):
Returns: True/False depending on if swap suceeded or not. Returns: True/False depending on if swap suceeded or not.
""" """
return super(Player, self).swap_character(new_character, delete_old_character=delete_old_character) return super(DefaultPlayer, self).swap_character(new_character, delete_old_character=delete_old_character)
def execute_cmd(self, raw_string, sessid=None, **kwargs): def execute_cmd(self, raw_string, sessid=None, **kwargs):
""" """
@ -163,7 +163,7 @@ class Player(PlayerDB):
be useful for coders intending to implement some sort of nested be useful for coders intending to implement some sort of nested
command structure. command structure.
""" """
return super(Player, self).execute_cmd(raw_string, sessid=sessid, **kwargs) return super(DefaultPlayer, self).execute_cmd(raw_string, sessid=sessid, **kwargs)
def search(self, searchdata, return_puppet=False, **kwargs): def search(self, searchdata, return_puppet=False, **kwargs):
""" """
@ -183,7 +183,7 @@ class Player(PlayerDB):
# handle wrapping of common terms # handle wrapping of common terms
if searchdata.lower() in ("me", "*me", "self", "*self",): if searchdata.lower() in ("me", "*me", "self", "*self",):
return self return self
return super(Player, self).search(searchdata, return_puppet=return_puppet, **kwargs) return super(DefaultPlayer, self).search(searchdata, return_puppet=return_puppet, **kwargs)
def is_typeclass(self, typeclass, exact=False): def is_typeclass(self, typeclass, exact=False):
""" """
@ -200,7 +200,7 @@ class Player(PlayerDB):
Returns: Boolean Returns: Boolean
""" """
return super(Player, self).is_typeclass(typeclass, exact=exact) return super(DefaultPlayer, self).is_typeclass(typeclass, exact=exact)
def swap_typeclass(self, new_typeclass, clean_attributes=False, no_default=True): def swap_typeclass(self, new_typeclass, clean_attributes=False, no_default=True):
""" """
@ -235,7 +235,7 @@ class Player(PlayerDB):
boolean True/False depending on if the swap worked or not. boolean True/False depending on if the swap worked or not.
""" """
super(Player, self).swap_typeclass(new_typeclass, super(DefaultPlayer, self).swap_typeclass(new_typeclass,
clean_attributes=clean_attributes, no_default=no_default) clean_attributes=clean_attributes, no_default=no_default)
def access(self, accessing_obj, access_type='read', default=False, **kwargs): def access(self, accessing_obj, access_type='read', default=False, **kwargs):
@ -248,7 +248,7 @@ class Player(PlayerDB):
default (bool) - what to return if no lock of access_type was found default (bool) - what to return if no lock of access_type was found
**kwargs - passed to the at_access hook along with the result. **kwargs - passed to the at_access hook along with the result.
""" """
result = super(Player, self).access(accessing_obj, access_type=access_type, default=default) result = super(DefaultPlayer, self).access(accessing_obj, access_type=access_type, default=default)
self.at_access(result, accessing_obj, access_type, **kwargs) self.at_access(result, accessing_obj, access_type, **kwargs)
return result return result
@ -261,7 +261,7 @@ class Player(PlayerDB):
on the object. (example: 'Builders') on the object. (example: 'Builders')
Note that this method does -not- call the at_access hook. Note that this method does -not- call the at_access hook.
""" """
return super(Player, self).check_permstring(permstring) return super(DefaultPlayer, self).check_permstring(permstring)
## player hooks ## player hooks
@ -431,7 +431,7 @@ class Player(PlayerDB):
""" """
pass pass
class Guest(Player): class Guest(DefaultPlayer):
""" """
This class is used for guest logins. Unlike Players, Guests and their This class is used for guest logins. Unlike Players, Guests and their
characters are deleted after disconnection. characters are deleted after disconnection.

View file

@ -7,7 +7,9 @@ Also, the initiated object manager is available as src.scripts.manager.
""" """
from src.scripts.scripts import * # Note - we MUST NOT import src.scripts.scripts here, or
# proxy models will fall under Django migrations.
#from src.scripts.scripts import *
from src.scripts.models import ScriptDB from src.scripts.models import ScriptDB
manager = ScriptDB.objects manager = ScriptDB.objects

View file

@ -345,7 +345,6 @@ class ScriptBase(ScriptDB):
"called when typeclass re-caches. Usually not used for scripts." "called when typeclass re-caches. Usually not used for scripts."
pass pass
# #
# Base Script - inherit from this # Base Script - inherit from this
# #

View file

@ -288,17 +288,17 @@ PLAYER_TYPECLASS_PATHS = ["game.gamesrc.objects", "contrib"]
CHANNEL_TYPECLASS_PATHS = ["game.gamesrc.conf", "contrib"] CHANNEL_TYPECLASS_PATHS = ["game.gamesrc.conf", "contrib"]
# Typeclass for player objects (linked to a character) (fallback) # Typeclass for player objects (linked to a character) (fallback)
BASE_PLAYER_TYPECLASS = "src.players.player.Player" BASE_PLAYER_TYPECLASS = "src.players.player.DefaultPlayer"
# Typeclass and base for all objects (fallback) # Typeclass and base for all objects (fallback)
BASE_OBJECT_TYPECLASS = "src.objects.objects.Object" BASE_OBJECT_TYPECLASS = "src.objects.objects.DefaultObject"
# Typeclass for character objects linked to a player (fallback) # Typeclass for character objects linked to a player (fallback)
BASE_CHARACTER_TYPECLASS = "src.objects.objects.Character" BASE_CHARACTER_TYPECLASS = "src.objects.objects.DefaultCharacter"
# Typeclass for rooms (fallback) # Typeclass for rooms (fallback)
BASE_ROOM_TYPECLASS = "src.objects.objects.Room" BASE_ROOM_TYPECLASS = "src.objects.objects.DefaultRoom"
# Typeclass for Exit objects (fallback). # Typeclass for Exit objects (fallback).
BASE_EXIT_TYPECLASS = "src.objects.objects.Exit" BASE_EXIT_TYPECLASS = "src.objects.objects.DefaultExit"
# Typeclass for Channel (fallback). # Typeclass for Channel (fallback).
BASE_CHANNEL_TYPECLASS = "src.comms.comms.Channel" BASE_CHANNEL_TYPECLASS = "src.comms.comms.DefaultChannel"
# Typeclass for Scripts (fallback). You usually don't need to change this # Typeclass for Scripts (fallback). You usually don't need to change this
# but create custom variations of scripts on a per-case basis instead. # but create custom variations of scripts on a per-case basis instead.
BASE_SCRIPT_TYPECLASS = "src.scripts.scripts.DoNothing" BASE_SCRIPT_TYPECLASS = "src.scripts.scripts.DoNothing"

View file

@ -780,7 +780,6 @@ class TypeclassBase(SharedMemoryModelBase):
proxy = True proxy = True
attrs["Meta"] = Meta attrs["Meta"] = Meta
attrs["Meta"].proxy = True attrs["Meta"].proxy = True
attrs["Meta"].app_label = attrs["path"]
# patch start - django multi-inheritance # patch start - django multi-inheritance
# this is a copy of django.db.models.base.__new__ # this is a copy of django.db.models.base.__new__
@ -1086,7 +1085,10 @@ class TypedObject(SharedMemoryModel):
def _import_class(self, path): def _import_class(self, path):
path, clsname = path.rsplit(".", 1) path, clsname = path.rsplit(".", 1)
mod = import_module(path) mod = import_module(path)
return getattr(mod, clsname) try:
return getattr(mod, clsname)
except AttributeError:
raise AttributeError("module '%s' has no attribute '%s'" % (path, clsname))
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
typeclass_path = kwargs.pop("typeclass", None) typeclass_path = kwargs.pop("typeclass", None)