mirror of
https://github.com/evennia/evennia.git
synced 2026-03-23 16:26:30 +01:00
Experiment/test char creation in admin
This commit is contained in:
parent
69bb854c3c
commit
ce19978157
4 changed files with 65 additions and 19 deletions
|
|
@ -382,7 +382,7 @@ class CmdInventory(COMMAND_DEFAULT_CLASS):
|
|||
table = self.styled_table(border="header")
|
||||
for item in items:
|
||||
table.add_row(f"|C{item.name}|n",
|
||||
"{}|n".format(utils.crop(raw_ansi(item.db.desc), width=50) or ""))
|
||||
"{}|n".format(utils.crop(raw_ansi(item.db.desc or ""), width=50) or ""))
|
||||
string = f"|wYou are carrying:\n{table}"
|
||||
self.caller.msg(string)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ from django import forms
|
|||
from django.conf import settings
|
||||
from django.contrib import admin, messages
|
||||
from django.contrib.admin.options import IS_POPUP_VAR
|
||||
from django.contrib.admin.widgets import ForeignKeyRawIdWidget
|
||||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||
from django.utils.translation import gettext as _
|
||||
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
|
||||
from django.contrib.admin.utils import unquote
|
||||
from django.template.response import TemplateResponse
|
||||
|
|
@ -18,6 +20,7 @@ from django.utils.html import escape
|
|||
from django.urls import path, reverse
|
||||
from django.contrib.auth import update_session_auth_hash
|
||||
|
||||
from evennia.objects.models import ObjectDB
|
||||
from evennia.accounts.models import AccountDB
|
||||
from evennia.utils import create
|
||||
from .attributes import AttributeInline
|
||||
|
|
@ -240,11 +243,12 @@ class AccountAdmin(BaseUserAdmin):
|
|||
This is the main creation screen for Users/accounts
|
||||
|
||||
"""
|
||||
from .objects import ObjectInline
|
||||
|
||||
list_display = ("username", "email", "is_staff", "is_superuser")
|
||||
form = AccountChangeForm
|
||||
add_form = AccountCreationForm
|
||||
inlines = [AccountTagInline, AccountAttributeInline]
|
||||
inlines = [AccountTagInline, AccountAttributeInline, ObjectInline]
|
||||
readonly_fields = ["db_date_created", "serialized_string"]
|
||||
fieldsets = (
|
||||
(
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ from django import forms
|
|||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin.utils import flatten_fieldsets
|
||||
from django.contrib.admin.widgets import ForeignKeyRawIdWidget
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from evennia.objects.models import ObjectDB
|
||||
from evennia.accounts.models import AccountDB
|
||||
from .attributes import AttributeInline
|
||||
from .tags import TagInline
|
||||
from . import utils as adminutils
|
||||
|
|
@ -59,6 +61,14 @@ class ObjectCreateForm(forms.ModelForm):
|
|||
"as part of Evennia's startup.",
|
||||
choices=adminutils.get_and_load_typeclasses(parent=ObjectDB))
|
||||
|
||||
db_lock_storage = forms.CharField( label="Locks",
|
||||
required=False,
|
||||
widget=forms.Textarea(attrs={"cols": "100", "rows": "2"}),
|
||||
help_text="In-game lock definition string. If not given, defaults will be used. "
|
||||
"This string should be on the form "
|
||||
"<i>type:lockfunction(args);type2:lockfunction2(args);...",
|
||||
)
|
||||
|
||||
db_cmdset_storage = forms.CharField(
|
||||
label="CmdSet",
|
||||
initial="",
|
||||
|
|
@ -68,6 +78,15 @@ class ObjectCreateForm(forms.ModelForm):
|
|||
" and can leave this field blank.",
|
||||
)
|
||||
|
||||
db_account = forms.ModelChoiceField(
|
||||
AccountDB.objects.all(),
|
||||
label="Controlling Account",
|
||||
required=False,
|
||||
widget=ForeignKeyRawIdWidget(
|
||||
ObjectDB._meta.get_field('db_account').remote_field, admin.site),
|
||||
help_text="Only needed for characters in MULTISESSION_MODE=1 or 2."
|
||||
)
|
||||
|
||||
raw_id_fields = ("db_destination", "db_location", "db_home")
|
||||
|
||||
|
||||
|
|
@ -81,19 +100,32 @@ class ObjectEditForm(ObjectCreateForm):
|
|||
model = ObjectDB
|
||||
fields = "__all__"
|
||||
|
||||
db_lock_storage = forms.CharField( label="Locks",
|
||||
required=False,
|
||||
widget=forms.Textarea(attrs={"cols": "100", "rows": "2"}),
|
||||
help_text="In-game lock definition string. If not given, defaults will be used. "
|
||||
"This string should be on the form "
|
||||
"<i>type:lockfunction(args);type2:lockfunction2(args);...",
|
||||
|
||||
class ObjectInline(admin.StackedInline):
|
||||
"""
|
||||
Inline creation of Object.
|
||||
|
||||
"""
|
||||
model = ObjectDB
|
||||
# template = "admin/accounts/stacked.html"
|
||||
form = ObjectCreateForm
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
("db_key", "db_typeclass_path"),
|
||||
("db_location", "db_home", "db_destination", "db_account"),
|
||||
"db_cmdset_storage",
|
||||
"db_lock_storage",
|
||||
)
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
db_typeclass_path = forms.ChoiceField(
|
||||
label="Typeclass",
|
||||
help_text="This is the Python-path to the class implementing the actual object functionality. "
|
||||
"<BR>If your custom class is not found here, it may not be imported as part of Evennia's startup.",
|
||||
choices=adminutils.get_and_load_typeclasses(parent=ObjectDB))
|
||||
extra = 1
|
||||
max_num = 1
|
||||
raw_id_fields = ("db_destination", "db_location", "db_home", "db_account")
|
||||
|
||||
|
||||
@admin.register(ObjectDB)
|
||||
|
|
@ -108,7 +140,7 @@ class ObjectAdmin(admin.ModelAdmin):
|
|||
list_display_links = ("id", "db_key")
|
||||
ordering = ["db_account", "db_typeclass_path", "id"]
|
||||
search_fields = ["=id", "^db_key", "db_typeclass_path", "^db_account__db_key"]
|
||||
raw_id_fields = ("db_destination", "db_location", "db_home")
|
||||
raw_id_fields = ("db_destination", "db_location", "db_home", "db_account")
|
||||
readonly_fields = ("serialized_string", )
|
||||
|
||||
save_as = True
|
||||
|
|
@ -125,7 +157,7 @@ class ObjectAdmin(admin.ModelAdmin):
|
|||
{
|
||||
"fields": (
|
||||
("db_key", "db_typeclass_path"),
|
||||
("db_location", "db_home", "db_destination"),
|
||||
("db_location", "db_home", "db_destination", "db_account"),
|
||||
"db_cmdset_storage",
|
||||
"db_lock_storage",
|
||||
"serialized_string"
|
||||
|
|
@ -141,8 +173,7 @@ class ObjectAdmin(admin.ModelAdmin):
|
|||
{
|
||||
"fields": (
|
||||
("db_key", "db_typeclass_path"),
|
||||
("db_location", "db_home"),
|
||||
"db_destination",
|
||||
("db_location", "db_home", "db_destination", "db_account"),
|
||||
"db_cmdset_storage",
|
||||
)
|
||||
},
|
||||
|
|
@ -206,15 +237,17 @@ class ObjectAdmin(admin.ModelAdmin):
|
|||
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)
|
||||
obj.save()
|
||||
obj.basetype_setup()
|
||||
obj.basetype_posthook_setup()
|
||||
obj.at_object_creation()
|
||||
obj.at_init()
|
||||
else:
|
||||
obj.save()
|
||||
obj.at_init()
|
||||
|
||||
def response_add(self, request, obj, post_url_continue=None):
|
||||
from django.http import HttpResponseRedirect
|
||||
|
|
|
|||
|
|
@ -54,6 +54,15 @@
|
|||
making them very efficient.
|
||||
</p>
|
||||
|
||||
<p class="card-text">
|
||||
<h4><a href="{% url "admin:server_serverconfig_changelist" %}">ServerConfig</a></h4>
|
||||
These are constants saved by the running server. While maybe interesting for
|
||||
debugging, you should usually not modify these manually unless you
|
||||
<i>really</i> know what you are doing. For example, the
|
||||
<i>BASE_*_TYPECLASS</i> fields are stored in order to auto-update
|
||||
when their setting changes; they must <i>not</i> be changed manually here.
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<h3>Website-only</h3>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue