Migrating models, many admin tweaks
This commit is contained in:
parent
a7f1e24c9c
commit
1bdcafcef4
15 changed files with 211 additions and 25 deletions
|
|
@ -280,7 +280,7 @@ class AccountAdmin(BaseUserAdmin):
|
|||
form = AccountChangeForm
|
||||
add_form = AccountCreationForm
|
||||
inlines = [AccountTagInline, AccountAttributeInline, ObjectPuppetInline]
|
||||
readonly_fields = ["db_date_created", "serialized_string", "link_button"]
|
||||
readonly_fields = ["db_date_created", "serialized_string"]
|
||||
view_on_site = False
|
||||
fieldsets = (
|
||||
(
|
||||
|
|
@ -337,9 +337,7 @@ class AccountAdmin(BaseUserAdmin):
|
|||
return str(dbserialize.pack_dbobj(obj))
|
||||
|
||||
serialized_string.help_text = (
|
||||
"Copy & paste this string into an Attribute's `value` field to store it there. "
|
||||
"Note that you cannot (easily) add multiple accounts this way - better do that "
|
||||
"in code."
|
||||
"Copy & paste this string into an Attribute's `value` field to store it there."
|
||||
)
|
||||
|
||||
def get_form(self, request, obj=None, **kwargs):
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class AttributeForm(forms.ModelForm):
|
|||
"""
|
||||
|
||||
attr_key = forms.CharField(
|
||||
label="Attribute Name", required=False, initial="Enter Attribute Name Here",
|
||||
label="Attribute Name", required=False,
|
||||
help_text="The main identifier of the Attribute. For Nicks, this is the pattern-matching string."
|
||||
)
|
||||
attr_category = forms.CharField(
|
||||
|
|
|
|||
|
|
@ -69,14 +69,14 @@ class MsgAdmin(admin.ModelAdmin):
|
|||
ordering = ["db_date_created", ]
|
||||
# readonly_fields = ['db_message', 'db_sender', 'db_receivers', 'db_channels']
|
||||
search_fields = ["id", "^db_date_created", "^db_message"]
|
||||
readonly_fields = ["db_date_created"]
|
||||
readonly_fields = ["db_date_created", "serialized_string"]
|
||||
save_as = True
|
||||
save_on_top = True
|
||||
list_select_related = True
|
||||
view_on_site = False
|
||||
|
||||
raw_id_fields = (
|
||||
"db_date_created", "db_sender_accounts",
|
||||
"db_sender_accounts",
|
||||
"db_sender_objects", "db_sender_scripts",
|
||||
"db_receivers_accounts", "db_receivers_objects",
|
||||
"db_receivers_scripts", "db_hide_from_accounts",
|
||||
|
|
@ -91,7 +91,7 @@ class MsgAdmin(admin.ModelAdmin):
|
|||
("db_receivers_accounts", "db_receivers_objects", "db_receivers_scripts", "db_receiver_external"),
|
||||
("db_hide_from_accounts", "db_hide_from_objects"),
|
||||
"db_header",
|
||||
"db_message"
|
||||
"db_message", "serialized_string"
|
||||
)
|
||||
},
|
||||
),
|
||||
|
|
@ -117,6 +117,30 @@ class MsgAdmin(admin.ModelAdmin):
|
|||
msg = msg[:50] + "[...]"
|
||||
return msg
|
||||
|
||||
def serialized_string(self, obj):
|
||||
"""
|
||||
Get the serialized version of the object.
|
||||
|
||||
"""
|
||||
from evennia.utils import dbserialize
|
||||
return str(dbserialize.pack_dbobj(obj))
|
||||
|
||||
serialized_string.help_text = (
|
||||
"Copy & paste this string into an Attribute's `value` field to store it there."
|
||||
)
|
||||
|
||||
def get_form(self, request, obj=None, **kwargs):
|
||||
"""
|
||||
Overrides help texts.
|
||||
|
||||
"""
|
||||
help_texts = kwargs.get("help_texts", {})
|
||||
help_texts["serialized_string"] = self.serialized_string.help_text
|
||||
kwargs["help_texts"] = help_texts
|
||||
return super().get_form(request, obj, **kwargs)
|
||||
|
||||
|
||||
|
||||
class ChannelAttributeInline(AttributeInline):
|
||||
"""
|
||||
Inline display of Channel Attribute - experimental
|
||||
|
|
@ -169,6 +193,7 @@ class ChannelAdmin(admin.ModelAdmin):
|
|||
list_display_links = ("id", "db_key")
|
||||
ordering = ["db_key"]
|
||||
search_fields = ["id", "db_key", "db_tags__db_key"]
|
||||
readonly_fields = ["serialized_string"]
|
||||
save_as = True
|
||||
save_on_top = True
|
||||
list_select_related = True
|
||||
|
|
@ -182,6 +207,7 @@ class ChannelAdmin(admin.ModelAdmin):
|
|||
"db_lock_storage",
|
||||
"db_account_subscriptions",
|
||||
"db_object_subscriptions",
|
||||
"serialized_string"
|
||||
)
|
||||
},
|
||||
),
|
||||
|
|
@ -207,6 +233,28 @@ class ChannelAdmin(admin.ModelAdmin):
|
|||
"""
|
||||
return sum(1 for sub in obj.subscriptions.all())
|
||||
|
||||
def serialized_string(self, obj):
|
||||
"""
|
||||
Get the serialized version of the object.
|
||||
|
||||
"""
|
||||
from evennia.utils import dbserialize
|
||||
return str(dbserialize.pack_dbobj(obj))
|
||||
|
||||
serialized_string.help_text = (
|
||||
"Copy & paste this string into an Attribute's `value` field to store it there."
|
||||
)
|
||||
|
||||
def get_form(self, request, obj=None, **kwargs):
|
||||
"""
|
||||
Overrides help texts.
|
||||
|
||||
"""
|
||||
help_texts = kwargs.get("help_texts", {})
|
||||
help_texts["serialized_string"] = self.serialized_string.help_text
|
||||
kwargs["help_texts"] = help_texts
|
||||
return super().get_form(request, obj, **kwargs)
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
"""
|
||||
Model-save hook.
|
||||
|
|
|
|||
|
|
@ -49,10 +49,14 @@ class HelpEntryAdmin(admin.ModelAdmin):
|
|||
(
|
||||
None,
|
||||
{
|
||||
"fields": (("db_key", "db_help_category"), "db_entrytext", "db_lock_storage"),
|
||||
"fields": (
|
||||
("db_key", "db_help_category"),
|
||||
"db_entrytext",
|
||||
"db_lock_storage",
|
||||
# "db_date_created",
|
||||
),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
admin.site.register(HelpEntry, HelpEntryAdmin)
|
||||
|
|
|
|||
|
|
@ -219,9 +219,8 @@ class ObjectAdmin(admin.ModelAdmin):
|
|||
return str(dbserialize.pack_dbobj(obj))
|
||||
|
||||
serialized_string.help_text = (
|
||||
"Copy & paste this string into an Attribute's `value` field to store it there. "
|
||||
"Note that you cannot (easily) add multiple objects this way - better do that "
|
||||
"in code.")
|
||||
"Copy & paste this string into an Attribute's `value` field to store it there."
|
||||
)
|
||||
|
||||
def get_fieldsets(self, request, obj=None):
|
||||
"""
|
||||
|
|
@ -272,7 +271,7 @@ class ObjectAdmin(admin.ModelAdmin):
|
|||
'<a class="button" href="{}">Link to Account</a> ',
|
||||
reverse("admin:object-account-link", args=[obj.pk])
|
||||
)
|
||||
link_button.short_description = "Create puppet links for MULTISESSION_MODE 0/1"
|
||||
link_button.short_description = "Create attrs/locks for puppeting"
|
||||
link_button.allow_tags = True
|
||||
|
||||
def link_object_to_account(self, request, object_id):
|
||||
|
|
@ -305,8 +304,9 @@ class ObjectAdmin(admin.ModelAdmin):
|
|||
f"Added {obj} to Account.db._playable_characters list, "
|
||||
f"Added 'puppet:pid({account.id})' lock to {obj}.")
|
||||
else:
|
||||
self.message_user(request, "Account must be connected to set up puppet links "
|
||||
"(set Puppeting Account and save this page first).", level=messages.ERROR)
|
||||
self.message_user(request, "Account must be connected for this action "
|
||||
"(set Puppeting Account and save this page first).",
|
||||
level=messages.ERROR)
|
||||
|
||||
# stay on the same page
|
||||
return HttpResponseRedirect(reverse("admin:objects_objectdb_change", args=[obj.pk]))
|
||||
|
|
|
|||
|
|
@ -127,9 +127,8 @@ class ScriptAdmin(admin.ModelAdmin):
|
|||
return str(dbserialize.pack_dbobj(obj))
|
||||
|
||||
serialized_string.help_text = (
|
||||
"Copy & paste this string into an Attribute's `value` field to store it there. "
|
||||
"Note that you cannot (easily) add multiple scripts this way - better do that "
|
||||
"in code.")
|
||||
"Copy & paste this string into an Attribute's `value` field to store it there."
|
||||
)
|
||||
|
||||
|
||||
def get_form(self, request, obj=None, **kwargs):
|
||||
|
|
|
|||
|
|
@ -215,7 +215,6 @@ class TagAdmin(admin.ModelAdmin):
|
|||
|
||||
search_fields = ("db_key", "db_category", "db_tagtype")
|
||||
list_display = ("db_key", "db_category", "db_tagtype", "db_model", "db_data")
|
||||
fields = ("db_key", "db_category", "db_tagtype", "db_model", "db_data")
|
||||
list_filter = ("db_tagtype", "db_category", "db_model")
|
||||
form = TagForm
|
||||
view_on_site = False
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ if settings.EVENNIA_ADMIN:
|
|||
|
||||
urlpatterns += [
|
||||
# Our override for the admin.
|
||||
url("^/$", frontpage.evennia_admin, name="evennia_admin"),
|
||||
url("^$", frontpage.evennia_admin, name="evennia_admin"),
|
||||
# Makes sure that other admin pages get loaded.
|
||||
url(r"^/", admin.site.urls),
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue