mirror of
https://github.com/evennia/evennia.git
synced 2026-03-23 00:06:30 +01:00
Fix django admin for other typeclasses. ChannelDB still requires subscribers to validate. Changed PickleField's clean method to prevent attribute errors for attributes added during basetype setup.
This commit is contained in:
parent
c16a03fb5e
commit
ee19a92c55
4 changed files with 54 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ This defines how Comm models are displayed in the web admin interface.
|
|||
from django.contrib import admin
|
||||
from evennia.comms.models import ChannelDB
|
||||
from evennia.typeclasses.admin import AttributeInline, TagInline
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class ChannelAttributeInline(AttributeInline):
|
||||
|
|
@ -70,4 +71,23 @@ class ChannelAdmin(admin.ModelAdmin):
|
|||
"""
|
||||
return ", ".join([str(sub) for sub in obj.db_subscriptions.all()])
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
"""
|
||||
Model-save hook.
|
||||
|
||||
Args:
|
||||
request (Request): Incoming request.
|
||||
obj (Object): Database object.
|
||||
form (Form): Form instance.
|
||||
change (bool): If this is a change or a new object.
|
||||
|
||||
"""
|
||||
obj.save()
|
||||
if not change:
|
||||
# adding a new object
|
||||
# have to call init with typeclass passed to it
|
||||
obj.set_class_from_typeclass(typeclass_path=settings.BASE_CHANNEL_TYPECLASS)
|
||||
obj.at_init()
|
||||
|
||||
|
||||
admin.site.register(ChannelDB, ChannelAdmin)
|
||||
|
|
|
|||
|
|
@ -241,9 +241,16 @@ class PlayerDBAdmin(BaseUserAdmin):
|
|||
obj.save()
|
||||
if not change:
|
||||
#calling hooks for new player
|
||||
ply = obj
|
||||
ply.basetype_setup()
|
||||
ply.at_player_creation()
|
||||
obj.set_class_from_typeclass(typeclass_path=settings.BASE_PLAYER_TYPECLASS)
|
||||
obj.basetype_setup()
|
||||
obj.at_player_creation()
|
||||
|
||||
def response_add(self, request, obj, post_url_continue=None):
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
if '_continue' in request.POST:
|
||||
return HttpResponseRedirect(reverse("admin:players_playerdb_change", args=[obj.id]))
|
||||
return HttpResponseRedirect(reverse("admin:players_playerdb_change", args=[obj.id]))
|
||||
|
||||
## TODO! Remove User reference!
|
||||
#def save_formset(self, request, form, formset, change):
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
# This sets up how models are displayed
|
||||
# in the web admin interface.
|
||||
#
|
||||
from django.conf import settings
|
||||
|
||||
from evennia.typeclasses.admin import AttributeInline, TagInline
|
||||
|
||||
from evennia.scripts.models import ScriptDB
|
||||
|
|
@ -50,5 +52,22 @@ class ScriptDBAdmin(admin.ModelAdmin):
|
|||
)
|
||||
inlines = [ScriptTagInline, ScriptAttributeInline]
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
"""
|
||||
Model-save hook.
|
||||
|
||||
Args:
|
||||
request (Request): Incoming request.
|
||||
obj (Object): Database object.
|
||||
form (Form): Form instance.
|
||||
change (bool): If this is a change or a new object.
|
||||
|
||||
"""
|
||||
obj.save()
|
||||
if not change:
|
||||
# adding a new object
|
||||
# have to call init with typeclass passed to it
|
||||
obj.set_class_from_typeclass(typeclass_path=obj.db_typeclass_path)
|
||||
|
||||
|
||||
admin.site.register(ScriptDB, ScriptDBAdmin)
|
||||
|
|
|
|||
|
|
@ -147,8 +147,11 @@ class PickledFormField(CharField):
|
|||
super(PickledFormField, self).__init__(*args, **kwargs)
|
||||
|
||||
def clean(self, value):
|
||||
if not value.strip():
|
||||
# Field was left blank. Make this None.
|
||||
try:
|
||||
if not value.strip():
|
||||
# Field was left blank. Make this None.
|
||||
value = 'None'
|
||||
except AttributeError:
|
||||
value = 'None'
|
||||
try:
|
||||
return literal_eval(value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue