Removed some references to get_profile(), fixed some spelling errors, fixed post_clear signal.
This commit is contained in:
parent
66802f291d
commit
5320381060
9 changed files with 37 additions and 47 deletions
|
|
@ -37,7 +37,7 @@ msgid " Type \"help\" for help."
|
||||||
msgstr "Skriv \"help\" för hjälp."
|
msgstr "Skriv \"help\" för hjälp."
|
||||||
|
|
||||||
#: src/commands/cmdhandler.py:212
|
#: src/commands/cmdhandler.py:212
|
||||||
msgid "There where multiple matches."
|
msgid "There were multiple matches."
|
||||||
msgstr "Det fanns många träffar."
|
msgstr "Det fanns många träffar."
|
||||||
|
|
||||||
#: src/commands/cmdparser.py:144
|
#: src/commands/cmdparser.py:144
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ def at_multimatch_cmd(caller, matches):
|
||||||
"""
|
"""
|
||||||
Format multiple command matches to a useful error.
|
Format multiple command matches to a useful error.
|
||||||
"""
|
"""
|
||||||
string = "There where multiple matches:"
|
string = "There were multiple matches:"
|
||||||
for num, match in enumerate(matches):
|
for num, match in enumerate(matches):
|
||||||
# each match is a tuple (candidate, cmd)
|
# each match is a tuple (candidate, cmd)
|
||||||
cmdname, arg, cmd, dum, dum = match
|
cmdname, arg, cmd, dum, dum = match
|
||||||
|
|
|
||||||
|
|
@ -298,12 +298,8 @@ class CmdDelPlayer(MuxCommand):
|
||||||
string = "No Player nor User found matching '%s'." % args
|
string = "No Player nor User found matching '%s'." % args
|
||||||
self.msg(string)
|
self.msg(string)
|
||||||
return
|
return
|
||||||
try:
|
|
||||||
player = user.get_profile()
|
|
||||||
except Exception:
|
|
||||||
player = None
|
|
||||||
|
|
||||||
if player and not player.access(caller, 'delete'):
|
if user and not user.access(caller, 'delete'):
|
||||||
string = "You don't have the permissions to delete this player."
|
string = "You don't have the permissions to delete this player."
|
||||||
self.msg(string)
|
self.msg(string)
|
||||||
return
|
return
|
||||||
|
|
@ -311,9 +307,9 @@ class CmdDelPlayer(MuxCommand):
|
||||||
string = ""
|
string = ""
|
||||||
name = user.username
|
name = user.username
|
||||||
user.delete()
|
user.delete()
|
||||||
if player:
|
if user:
|
||||||
name = player.name
|
name = user.name
|
||||||
player.delete()
|
user.delete()
|
||||||
string = "Player %s was deleted." % name
|
string = "Player %s was deleted." % name
|
||||||
else:
|
else:
|
||||||
string += "The User %s was deleted. It had no Player associated with it." % name
|
string += "The User %s was deleted. It had no Player associated with it." % name
|
||||||
|
|
@ -322,16 +318,16 @@ class CmdDelPlayer(MuxCommand):
|
||||||
|
|
||||||
elif utils.is_iter(players):
|
elif utils.is_iter(players):
|
||||||
string = "There were multiple matches:"
|
string = "There were multiple matches:"
|
||||||
for player in players:
|
for user in players:
|
||||||
string += "\n %s %s" % (player.id, player.key)
|
string += "\n %s %s" % (user.id, user.key)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# one single match
|
# one single match
|
||||||
|
|
||||||
player = players
|
user = players
|
||||||
user = player.user
|
user = user.user
|
||||||
|
|
||||||
if not player.access(caller, 'delete'):
|
if not user.access(caller, 'delete'):
|
||||||
string = "You don't have the permissions to delete that player."
|
string = "You don't have the permissions to delete that player."
|
||||||
self.msg(string)
|
self.msg(string)
|
||||||
return
|
return
|
||||||
|
|
@ -342,12 +338,12 @@ class CmdDelPlayer(MuxCommand):
|
||||||
string = "\nYour account '%s' is being *permanently* deleted.\n" % uname
|
string = "\nYour account '%s' is being *permanently* deleted.\n" % uname
|
||||||
if reason:
|
if reason:
|
||||||
string += " Reason given:\n '%s'" % reason
|
string += " Reason given:\n '%s'" % reason
|
||||||
player.unpuppet_all()
|
user.unpuppet_all()
|
||||||
for session in SESSIONS.sessions_from_player(player):
|
for session in SESSIONS.sessions_from_player(user):
|
||||||
player.msg(string, sessid=session.sessid)
|
user.msg(string, sessid=session.sessid)
|
||||||
player.disconnect_session_from_player(session.sessid)
|
user.disconnect_session_from_player(session.sessid)
|
||||||
|
user.delete()
|
||||||
user.delete()
|
user.delete()
|
||||||
player.delete()
|
|
||||||
self.msg("Player %s was successfully deleted." % uname)
|
self.msg("Player %s was successfully deleted." % uname)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ class SystemMultimatch(MuxCommand):
|
||||||
src.commands.cmdhandler.
|
src.commands.cmdhandler.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
string = "There where multiple matches:"
|
string = "There were multiple matches:"
|
||||||
for num, match in enumerate(matches):
|
for num, match in enumerate(matches):
|
||||||
# each match is a tuple (candidate, cmd)
|
# each match is a tuple (candidate, cmd)
|
||||||
candidate, cmd = match
|
candidate, cmd = match
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,6 @@ def identify_object(inp):
|
||||||
obj = inp
|
obj = inp
|
||||||
typ = type(obj)
|
typ = type(obj)
|
||||||
if typ == _PlayerDB: return obj, "player"
|
if typ == _PlayerDB: return obj, "player"
|
||||||
if typ == _User: return obj.get_profile(), "player"
|
|
||||||
elif typ == _ObjectDB: return obj, "object"
|
elif typ == _ObjectDB: return obj, "object"
|
||||||
elif typ == _Channel: return obj, "channel"
|
elif typ == _Channel: return obj, "channel"
|
||||||
elif dbref(obj): return dbref(obj), "dbref"
|
elif dbref(obj): return dbref(obj), "dbref"
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class PlayerDBChangeForm(UserChangeForm):
|
||||||
username = self.cleaned_data['username']
|
username = self.cleaned_data['username']
|
||||||
if username.upper() == self.instance.username.upper():
|
if username.upper() == self.instance.username.upper():
|
||||||
return username
|
return username
|
||||||
elif User.objects.filter(username__iexact=username):
|
elif PlayerDB.objects.filter(username__iexact=username):
|
||||||
raise forms.ValidationError('A player with that name already exists.')
|
raise forms.ValidationError('A player with that name already exists.')
|
||||||
return self.cleaned_data['username']
|
return self.cleaned_data['username']
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ class PlayerDBCreationForm(UserCreationForm):
|
||||||
|
|
||||||
def clean_username(self):
|
def clean_username(self):
|
||||||
username = self.cleaned_data['username']
|
username = self.cleaned_data['username']
|
||||||
if User.objects.filter(username__iexact=username):
|
if PlayerDB.objects.filter(username__iexact=username):
|
||||||
raise forms.ValidationError('A player with that name already exists.')
|
raise forms.ValidationError('A player with that name already exists.')
|
||||||
return username
|
return username
|
||||||
|
|
||||||
|
|
@ -139,7 +139,9 @@ class PlayerDBAdmin(BaseUserAdmin):
|
||||||
('Website dates', {'fields': ('last_login', 'date_joined'),
|
('Website dates', {'fields': ('last_login', 'date_joined'),
|
||||||
'description':'<i>Relevant only to the website.</i>'}),
|
'description':'<i>Relevant only to the website.</i>'}),
|
||||||
('Website Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser', 'user_permissions','groups'),
|
('Website Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser', 'user_permissions','groups'),
|
||||||
'description': "<i>These are permissions/permission groups for accessing the admin site. They are unrelated to in-game access rights.</i>"}),)
|
'description': "<i>These are permissions/permission groups for accessing the admin site. They are unrelated to in-game access rights.</i>"}),
|
||||||
|
('Game Options', {'fields': ('db_typeclass_path', 'db_cmdset_storage', 'db_permissions', 'db_lock_storage'),
|
||||||
|
'description': '<i>These are attributes that are more relevant to gameplay.</i>'}))
|
||||||
|
|
||||||
|
|
||||||
add_fieldsets = (
|
add_fieldsets = (
|
||||||
|
|
@ -152,8 +154,7 @@ class PlayerDBAdmin(BaseUserAdmin):
|
||||||
"Run all hooks on the player object"
|
"Run all hooks on the player object"
|
||||||
super(PlayerDBAdmin, self).save_formset(request, form, formset, change)
|
super(PlayerDBAdmin, self).save_formset(request, form, formset, change)
|
||||||
userobj = form.instance
|
userobj = form.instance
|
||||||
playerobj = userobj.get_profile()
|
userobj.name = userobj.username
|
||||||
playerobj.name = userobj.username
|
|
||||||
if not change:
|
if not change:
|
||||||
#uname, passwd, email = str(request.POST.get(u"username")), \
|
#uname, passwd, email = str(request.POST.get(u"username")), \
|
||||||
# str(request.POST.get(u"password1")), str(request.POST.get(u"email"))
|
# str(request.POST.get(u"password1")), str(request.POST.get(u"email"))
|
||||||
|
|
@ -161,6 +162,6 @@ class PlayerDBAdmin(BaseUserAdmin):
|
||||||
create.create_player("","","",
|
create.create_player("","","",
|
||||||
user=userobj,
|
user=userobj,
|
||||||
typeclass=typeclass,
|
typeclass=typeclass,
|
||||||
player_dbobj=playerobj)
|
player_dbobj=userobj)
|
||||||
|
|
||||||
admin.site.register(PlayerDB, PlayerDBAdmin)
|
admin.site.register(PlayerDB, PlayerDBAdmin)
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,14 @@
|
||||||
"""
|
"""
|
||||||
Player
|
Player
|
||||||
|
|
||||||
The Player class is a simple extension of the django User model using
|
The player class is an extension of the default Django user class,
|
||||||
the 'profile' system of django. A profile is a model that tack new
|
and is customized for the needs of Evennia.
|
||||||
fields to the User model without actually editing the User model
|
|
||||||
(which would mean hacking into django internals which we want to avoid
|
|
||||||
for future compatability reasons). The profile, which we call
|
|
||||||
'Player', is accessed with user.get_profile() by the property 'player'
|
|
||||||
defined on ObjectDB objects. Since we can customize it, we will try to
|
|
||||||
abstract as many operations as possible to work on Player rather than
|
|
||||||
on User.
|
|
||||||
|
|
||||||
We use the Player to store a more mud-friendly style of permission
|
We use the Player to store a more mud-friendly style of permission
|
||||||
system as well as to allow the admin more flexibility by storing
|
system as well as to allow the admin more flexibility by storing
|
||||||
attributes on the Player. Within the game we should normally use the
|
attributes on the Player. Within the game we should normally use the
|
||||||
Player manager's methods to create users, since that automatically
|
Player manager's methods to create users so that permissions are set
|
||||||
adds the profile extension.
|
correctly.
|
||||||
|
|
||||||
To make the Player model more flexible for your own game, it can also
|
To make the Player model more flexible for your own game, it can also
|
||||||
persistently store attributes of its own. This is ideal for extra
|
persistently store attributes of its own. This is ideal for extra
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,8 @@ def post_attr_update(sender, **kwargs):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# forward relation changed (the Object holding the Attribute m2m field)
|
# forward relation changed (the Object holding the Attribute m2m field)
|
||||||
|
if not kwargs["pk_set"]:
|
||||||
|
return
|
||||||
if action == "post_add":
|
if action == "post_add":
|
||||||
# cache all added objects
|
# cache all added objects
|
||||||
for attr_id in kwargs["pk_set"]:
|
for attr_id in kwargs["pk_set"]:
|
||||||
|
|
@ -185,10 +187,7 @@ def post_attr_update(sender, **kwargs):
|
||||||
attr_obj.delete()
|
attr_obj.delete()
|
||||||
elif action == "post_clear":
|
elif action == "post_clear":
|
||||||
# obj.db_attributes.clear() was called
|
# obj.db_attributes.clear() was called
|
||||||
for attr_id in kwargs["pk_set"]:
|
clear_obj_attr_cache(obj)
|
||||||
attr_obj = model.objects.get(pk=attr_id)
|
|
||||||
del_attr_cache(obj, _GA(attr_obj, "db_key"))
|
|
||||||
attr_obj.delete()
|
|
||||||
|
|
||||||
# access methods
|
# access methods
|
||||||
|
|
||||||
|
|
@ -215,6 +214,11 @@ def flush_attr_cache():
|
||||||
global _ATTR_CACHE
|
global _ATTR_CACHE
|
||||||
_ATTR_CACHE = {}
|
_ATTR_CACHE = {}
|
||||||
|
|
||||||
|
def clear_obj_attr_cache(obj):
|
||||||
|
global _ATTR_CACHE
|
||||||
|
hid = hashid(obj)
|
||||||
|
_ATTR_CACHE = {key:value for key, value in _ATTR_CACHE if not key.startswith(hid)}
|
||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
# Property cache - this is a generic cache for properties stored on models.
|
# Property cache - this is a generic cache for properties stored on models.
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -51,10 +51,7 @@ def create_objects():
|
||||||
god_player = get_god_player()
|
god_player = get_god_player()
|
||||||
|
|
||||||
# Create a Player 'user profile' object to hold eventual
|
# Create a Player 'user profile' object to hold eventual
|
||||||
# mud-specific settings for the bog standard User object. This is
|
# mud-specific settings for the PlayerDB object.
|
||||||
# accessed by user.get_profile() and can also store attributes.
|
|
||||||
# It also holds mud permissions, but for a superuser these
|
|
||||||
# have no effect anyhow.
|
|
||||||
player_typeclass = settings.BASE_PLAYER_TYPECLASS
|
player_typeclass = settings.BASE_PLAYER_TYPECLASS
|
||||||
|
|
||||||
# run all creation hooks on god_player (we must do so manually since the manage.py command does not)
|
# run all creation hooks on god_player (we must do so manually since the manage.py command does not)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue