Migrating models, many admin tweaks

This commit is contained in:
Griatch 2021-05-20 23:42:12 +02:00
parent a7f1e24c9c
commit 1bdcafcef4
15 changed files with 211 additions and 25 deletions

View file

@ -0,0 +1,19 @@
# Generated by Django 3.2.3 on 2021-05-20 21:37
from django.db import migrations, models
import evennia.accounts.manager
class Migration(migrations.Migration):
dependencies = [
('accounts', '0009_auto_20191025_0831'),
]
operations = [
migrations.AlterField(
model_name='accountdb',
name='first_name',
field=models.CharField(blank=True, max_length=150, verbose_name='first name'),
),
]

View file

@ -0,0 +1,57 @@
# Generated by Django 3.2.3 on 2021-05-20 21:37
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('scripts', '0014_auto_20210520_2137'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('objects', '0011_auto_20191025_0831'),
('comms', '0020_auto_20210514_2210'),
]
operations = [
migrations.AlterField(
model_name='msg',
name='db_receiver_external',
field=models.CharField(blank=True, db_index=True, help_text='Identifier for single external receiver, for use with recievers not represented by a regular database model.', max_length=1024, null=True, verbose_name='external receiver'),
),
migrations.AlterField(
model_name='msg',
name='db_receivers_accounts',
field=models.ManyToManyField(blank=True, help_text='account receivers', related_name='receiver_account_set', to=settings.AUTH_USER_MODEL, verbose_name='Receivers (Accounts)'),
),
migrations.AlterField(
model_name='msg',
name='db_receivers_objects',
field=models.ManyToManyField(blank=True, help_text='object receivers', related_name='receiver_object_set', to='objects.ObjectDB', verbose_name='Receivers (Objects)'),
),
migrations.AlterField(
model_name='msg',
name='db_receivers_scripts',
field=models.ManyToManyField(blank=True, help_text='script_receivers', related_name='receiver_script_set', to='scripts.ScriptDB', verbose_name='Receivers (Scripts)'),
),
migrations.AlterField(
model_name='msg',
name='db_sender_accounts',
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_account_set', to=settings.AUTH_USER_MODEL, verbose_name='Senders (Accounts)'),
),
migrations.AlterField(
model_name='msg',
name='db_sender_external',
field=models.CharField(blank=True, db_index=True, help_text='Identifier for single external sender, for use with senders not represented by a regular database model.', max_length=255, null=True, verbose_name='external sender'),
),
migrations.AlterField(
model_name='msg',
name='db_sender_objects',
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_object_set', to='objects.ObjectDB', verbose_name='Senders (Objects)'),
),
migrations.AlterField(
model_name='msg',
name='db_sender_scripts',
field=models.ManyToManyField(blank=True, db_index=True, related_name='sender_script_set', to='scripts.ScriptDB', verbose_name='Senders (Scripts)'),
),
]

View file

@ -0,0 +1,22 @@
# Generated by Django 3.2.3 on 2021-05-20 21:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('help', '0003_auto_20190128_1820'),
]
operations = [
migrations.RemoveField(
model_name='helpentry',
name='db_staff_only',
),
migrations.AddField(
model_name='helpentry',
name='db_date_created',
field=models.DateTimeField(auto_now=True, verbose_name='creation date'),
),
]

View file

@ -9,6 +9,7 @@ forms of help that do not concern commands, like information about the
game world, policy info, rules and similar.
"""
from datetime import datetime
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.urls import reverse
@ -76,9 +77,8 @@ class HelpEntry(SharedMemoryModel):
help_text="tags on this object. Tags are simple string markers to "
"identify, group and alias objects.",
)
# (deprecated, only here to allow MUX helpfile load (don't use otherwise)).
# TODO: remove this when not needed anymore.
db_staff_only = models.BooleanField(default=False)
# Creation date. This is not changed once the object is created.
db_date_created = models.DateTimeField("creation date", editable=False, auto_now=True)
# Database manager
objects = HelpEntryManager()

View file

@ -0,0 +1,23 @@
# Generated by Django 3.2.3 on 2021-05-20 21:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('scripts', '0013_auto_20191025_0831'),
]
operations = [
migrations.AlterField(
model_name='scriptdb',
name='db_interval',
field=models.IntegerField(default=-1, help_text='how often to repeat script, in seconds. <= 0 means off.', verbose_name='interval'),
),
migrations.AlterField(
model_name='scriptdb',
name='db_persistent',
field=models.BooleanField(default=True, verbose_name='survive server reboot'),
),
]

View file

@ -960,6 +960,7 @@ INSTALLED_APPS = [
"django.contrib.flatpages",
"django.contrib.sites",
"django.contrib.staticfiles",
"evennia.web.utils.adminsite.EvenniaAdminApp", # replaces django.contrib.admin
"django.contrib.messages",
"rest_framework",
"django_filters",
@ -973,7 +974,6 @@ INSTALLED_APPS = [
"evennia.help",
"evennia.scripts",
"evennia.web",
"evennia.web.utils.adminsite.EvenniaAdminApp", # replaces django.contrib.admin
]
# The user profile extends the User object with more functionality;
# This should usually not be changed.

View file

@ -0,0 +1,17 @@
# Generated by Django 3.2.3 on 2021-05-20 21:37
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('typeclasses', '0014_alter_tag_db_category'),
]
operations = [
migrations.AlterModelOptions(
name='attribute',
options={'verbose_name': 'Attribute'},
),
]

View file

@ -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):

View file

@ -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(

View file

@ -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.

View file

@ -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)

View file

@ -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>&nbsp;',
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]))

View file

@ -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):

View file

@ -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

View file

@ -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),
]