Run black reformatter on code

This commit is contained in:
Griatch 2022-02-08 13:03:52 +01:00
parent 4582eb4085
commit bd3e31bf3c
178 changed files with 4511 additions and 3385 deletions

View file

@ -78,13 +78,13 @@ class AccountChangeForm(UserChangeForm):
)
is_superuser = forms.BooleanField(
label = "Superuser status",
label="Superuser status",
required=False,
help_text="Superusers bypass all in-game locks and has all "
"permissions without explicitly assigning them. Usually "
"only one superuser (user #1) is needed and only a superuser "
"can create another superuser.<BR>"
"Only Superusers can change the user/group permissions below."
"permissions without explicitly assigning them. Usually "
"only one superuser (user #1) is needed and only a superuser "
"can create another superuser.<BR>"
"Only Superusers can change the user/group permissions below.",
)
def clean_username(self):
@ -165,11 +165,13 @@ class AccountAttributeInline(AttributeInline):
model = AccountDB.db_attributes.through
related_field = "accountdb"
class ObjectPuppetInline(admin.StackedInline):
"""
Inline creation of puppet-Object in Account.
"""
from .objects import ObjectCreateForm
verbose_name = "Puppeted Object"
@ -185,19 +187,26 @@ class ObjectPuppetInline(admin.StackedInline):
"fields": (
("db_key", "db_typeclass_path"),
("db_location", "db_home", "db_destination"),
"db_cmdset_storage",
"db_lock_storage",
"db_cmdset_storage",
"db_lock_storage",
),
"description": "Object currently puppeted by the account (note that this "
"will go away if account logs out or unpuppets)",
"will go away if account logs out or unpuppets)",
},
),
)
extra = 0
readonly_fields = ("db_key", "db_typeclass_path", "db_destination",
"db_location", "db_home", "db_account",
"db_cmdset_storage", "db_lock_storage")
readonly_fields = (
"db_key",
"db_typeclass_path",
"db_destination",
"db_location",
"db_home",
"db_account",
"db_cmdset_storage",
"db_lock_storage",
)
# disable adding/deleting this inline - read-only!
def has_add_permission(self, request, obj=None):
@ -213,7 +222,15 @@ class AccountAdmin(BaseUserAdmin):
This is the main creation screen for Users/accounts
"""
list_display = ("id", "username", "is_staff", "is_superuser", "db_typeclass_path", "db_date_created")
list_display = (
"id",
"username",
"is_staff",
"is_superuser",
"db_typeclass_path",
"db_date_created",
)
list_display_links = ("id", "username")
form = AccountChangeForm
add_form = AccountCreationForm
@ -277,6 +294,7 @@ class AccountAdmin(BaseUserAdmin):
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 this account there."
)
@ -289,8 +307,8 @@ class AccountAdmin(BaseUserAdmin):
return mark_safe(
", ".join(
'<a href="{url}">{name}</a>'.format(
url=reverse("admin:objects_objectdb_change", args=[obj.id]),
name=obj.db_key)
url=reverse("admin:objects_objectdb_change", args=[obj.id]), name=obj.db_key
)
for obj in ObjectDB.objects.filter(db_account=obj)
)
)
@ -316,9 +334,7 @@ class AccountAdmin(BaseUserAdmin):
form = super().get_form(request, obj, **kwargs)
disabled_fields = set()
if not request.user.is_superuser:
disabled_fields |= {
'is_superuser', 'user_permissions', 'user_groups'
}
disabled_fields |= {"is_superuser", "user_permissions", "user_groups"}
for field_name in disabled_fields:
if field_name in form.base_fields:
form.base_fields[field_name].disabled = True

View file

@ -27,28 +27,30 @@ class AttributeForm(forms.ModelForm):
"""
attr_key = forms.CharField(
label="Attribute Name", required=False,
help_text="The main identifier of the Attribute. For Nicks, this is the pattern-matching string."
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(
label="Category",
help_text="Categorization. Unset (default) gives a category of `None`, which is "
"is what is searched with e.g. `obj.db.attrname`. For 'nick'-type attributes, this is usually "
"'inputline' or 'channel'.",
required=False, max_length=128
"is what is searched with e.g. `obj.db.attrname`. For 'nick'-type attributes, this is usually "
"'inputline' or 'channel'.",
required=False,
max_length=128,
)
attr_value = PickledFormField(
label="Value",
help_text="Value to pickle/save. Db-objects are serialized as a list "
"containing `__packed_dbobj__` (they can't easily be added from here). Nicks "
"store their pattern-replacement here.",
required=False
required=False,
)
attr_type = forms.ChoiceField(
label="Type",
choices=[(None, "-"), ("nick", "nick")],
help_text="Unset for regular Attributes, 'nick' for Nick-replacement usage.",
required=False
required=False,
)
attr_lockstring = forms.CharField(
label="Locks",
@ -62,10 +64,10 @@ class AttributeForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
"""
If we have an Attribute, then we'll prepopulate our instance with the fields we'd expect it
to have based on the Attribute. attr_key, attr_category, attr_value, attr_type,
and attr_lockstring all refer to the corresponding Attribute fields. The initial data of the form fields will
similarly be populated.
If we have an Attribute, then we'll prepopulate our instance with the fields we'd expect it
to have based on the Attribute. attr_key, attr_category, attr_value, attr_type,
and attr_lockstring all refer to the corresponding Attribute fields. The initial data of the form fields will
similarly be populated.
"""
super().__init__(*args, **kwargs)

View file

@ -17,9 +17,11 @@ class MsgTagInline(TagInline):
Inline display for Msg-tags.
"""
model = Msg.db_tags.through
related_field = "msg"
class MsgForm(forms.ModelForm):
"""
Custom Msg form.
@ -35,7 +37,7 @@ class MsgForm(forms.ModelForm):
required=False,
widget=forms.Textarea(attrs={"cols": "100", "rows": "2"}),
help_text="Optional header for the message; it could be a title or "
"metadata depending on msg-use."
"metadata depending on msg-use.",
)
db_lock_storage = forms.CharField(
@ -48,7 +50,6 @@ class MsgForm(forms.ModelForm):
)
@admin.register(Msg)
class MsgAdmin(admin.ModelAdmin):
"""
@ -67,11 +68,19 @@ class MsgAdmin(admin.ModelAdmin):
)
list_display_links = ("id", "db_date_created", "start_of_message")
ordering = ["-db_date_created", "-id"]
search_fields = ["=id", "^db_date_created", "^db_message",
"^db_sender_accounts__db_key", "^db_sender_objects__db_key",
"^db_sender_scripts__db_key", "^db_sender_external",
"^db_receivers_accounts__db_key", "^db_receivers_objects__db_key",
"^db_receivers_scripts__db_key", "^db_receiver_external"]
search_fields = [
"=id",
"^db_date_created",
"^db_message",
"^db_sender_accounts__db_key",
"^db_sender_objects__db_key",
"^db_sender_scripts__db_key",
"^db_sender_external",
"^db_receivers_accounts__db_key",
"^db_receivers_objects__db_key",
"^db_receivers_scripts__db_key",
"^db_receiver_external",
]
readonly_fields = ["db_date_created", "serialized_string"]
save_as = True
save_on_top = True
@ -80,21 +89,36 @@ class MsgAdmin(admin.ModelAdmin):
raw_id_fields = (
"db_sender_accounts",
"db_sender_objects", "db_sender_scripts",
"db_receivers_accounts", "db_receivers_objects",
"db_receivers_scripts", "db_hide_from_accounts",
"db_hide_from_objects")
"db_sender_objects",
"db_sender_scripts",
"db_receivers_accounts",
"db_receivers_objects",
"db_receivers_scripts",
"db_hide_from_accounts",
"db_hide_from_objects",
)
fieldsets = (
(
None,
{
"fields": (
("db_sender_accounts", "db_sender_objects", "db_sender_scripts", "db_sender_external"),
("db_receivers_accounts", "db_receivers_objects", "db_receivers_scripts", "db_receiver_external"),
(
"db_sender_accounts",
"db_sender_objects",
"db_sender_scripts",
"db_sender_external",
),
(
"db_receivers_accounts",
"db_receivers_objects",
"db_receivers_scripts",
"db_receiver_external",
),
("db_hide_from_accounts", "db_hide_from_objects"),
"db_header",
"db_message", "serialized_string"
"db_message",
"serialized_string",
)
},
),
@ -104,12 +128,14 @@ class MsgAdmin(admin.ModelAdmin):
senders = [o for o in obj.senders if o]
if senders:
return senders[0]
sender.help_text = "If multiple, only the first is shown."
def receiver(self, obj):
receivers = [o for o in obj.receivers if o]
if receivers:
return receivers[0]
receiver.help_text = "If multiple, only the first is shown."
def start_of_message(self, obj):
@ -126,6 +152,7 @@ class MsgAdmin(admin.ModelAdmin):
"""
from evennia.utils import dbserialize
return str(dbserialize.pack_dbobj(obj))
serialized_string.help_text = (
@ -144,7 +171,6 @@ class MsgAdmin(admin.ModelAdmin):
return super().get_form(request, obj, **kwargs)
class ChannelAttributeInline(AttributeInline):
"""
Inline display of Channel Attribute - experimental
@ -170,6 +196,7 @@ class ChannelForm(forms.ModelForm):
Form for accessing channels.
"""
class Meta:
model = ChannelDB
fields = "__all__"
@ -193,8 +220,14 @@ class ChannelAdmin(admin.ModelAdmin):
inlines = [ChannelTagInline, ChannelAttributeInline]
form = ChannelForm
list_display = ("id", "db_key", "no_of_subscribers", "db_lock_storage", "db_typeclass_path",
"db_date_created")
list_display = (
"id",
"db_key",
"no_of_subscribers",
"db_lock_storage",
"db_typeclass_path",
"db_date_created",
)
list_display_links = ("id", "db_key")
ordering = ["-db_date_created", "-id", "-db_key"]
search_fields = ["id", "db_key", "db_tags__db_key"]
@ -212,7 +245,7 @@ class ChannelAdmin(admin.ModelAdmin):
"db_lock_storage",
"db_account_subscriptions",
"db_object_subscriptions",
"serialized_string"
"serialized_string",
)
},
),
@ -244,6 +277,7 @@ class ChannelAdmin(admin.ModelAdmin):
"""
from evennia.utils import dbserialize
return str(dbserialize.pack_dbobj(obj))
serialized_string.help_text = (

View file

@ -30,7 +30,8 @@ class HelpEntryForm(forms.ModelForm):
widget=forms.Textarea(attrs={"cols": "100", "rows": "2"}),
help_text="Set lock to view:all() unless you want it to only show to certain users."
"<BR>Use the `edit:` limit if wanting to limit who can edit from in-game. By default it's "
"only limited to who can use the `sethelp` command (Builders).")
"only limited to who can use the `sethelp` command (Builders).",
)
@admin.register(HelpEntry)

View file

@ -63,9 +63,11 @@ class ObjectCreateForm(forms.ModelForm):
f"<BR>If you are creating a Character you usually need <B>{settings.BASE_CHARACTER_TYPECLASS}</B> "
"or a subclass of that. <BR>If your custom class is not found in the list, it may not be imported "
"into Evennia yet.",
choices=lambda: adminutils.get_and_load_typeclasses(parent=ObjectDB))
choices=lambda: adminutils.get_and_load_typeclasses(parent=ObjectDB),
)
db_lock_storage = forms.CharField( label="Locks",
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. "
@ -92,29 +94,32 @@ class ObjectCreateForm(forms.ModelForm):
label="Location",
required=False,
widget=ForeignKeyRawIdWidget(
ObjectDB._meta.get_field('db_location').remote_field, admin.site),
ObjectDB._meta.get_field("db_location").remote_field, admin.site
),
help_text="The (current) in-game location.<BR>"
"Usually a Room but can be<BR>"
"empty for un-puppeted Characters."
"Usually a Room but can be<BR>"
"empty for un-puppeted Characters.",
)
db_home = forms.ModelChoiceField(
ObjectDB.objects.all(),
label="Home",
required=False,
widget=ForeignKeyRawIdWidget(
ObjectDB._meta.get_field('db_location').remote_field, admin.site),
ObjectDB._meta.get_field("db_location").remote_field, admin.site
),
help_text="Fallback in-game location.<BR>"
"All objects should usually have<BR>"
"a home location."
)
"All objects should usually have<BR>"
"a home location.",
)
db_destination = forms.ModelChoiceField(
ObjectDB.objects.all(),
label="Destination",
required=False,
widget=ForeignKeyRawIdWidget(
ObjectDB._meta.get_field('db_destination').remote_field, admin.site),
help_text="Only used by Exits."
)
ObjectDB._meta.get_field("db_destination").remote_field, admin.site
),
help_text="Only used by Exits.",
)
def __init__(self, *args, **kwargs):
"""
@ -157,9 +162,10 @@ class ObjectEditForm(ObjectCreateForm):
label="Puppeting Account",
required=False,
widget=ForeignKeyRawIdWidget(
ObjectDB._meta.get_field('db_account').remote_field, admin.site),
ObjectDB._meta.get_field("db_account").remote_field, admin.site
),
help_text="An Account puppeting this Object (if any).<BR>Note that when a user logs "
"off/unpuppets, this<BR>field will be empty again. This is normal."
"off/unpuppets, this<BR>field will be empty again. This is normal.",
)
@ -171,10 +177,24 @@ class ObjectAdmin(admin.ModelAdmin):
"""
inlines = [ObjectTagInline, ObjectAttributeInline]
list_display = ("id", "db_key", "db_typeclass_path", "db_location", "db_destination", "db_account", "db_date_created")
list_display = (
"id",
"db_key",
"db_typeclass_path",
"db_location",
"db_destination",
"db_account",
"db_date_created",
)
list_display_links = ("id", "db_key")
ordering = ["-db_date_created", "-id"]
search_fields = ["=id", "^db_key", "db_typeclass_path", "^db_account__db_key", "^db_location__db_key"]
search_fields = [
"=id",
"^db_key",
"db_typeclass_path",
"^db_account__db_key",
"^db_location__db_key",
]
raw_id_fields = ("db_destination", "db_location", "db_home", "db_account")
readonly_fields = ("serialized_string", "link_button")
@ -197,7 +217,7 @@ class ObjectAdmin(admin.ModelAdmin):
("db_account", "link_button"),
"db_cmdset_storage",
"db_lock_storage",
"serialized_string"
"serialized_string",
)
},
),
@ -223,6 +243,7 @@ class ObjectAdmin(admin.ModelAdmin):
"""
from evennia.utils import dbserialize
return str(dbserialize.pack_dbobj(obj))
serialized_string.help_text = (
@ -268,7 +289,7 @@ class ObjectAdmin(admin.ModelAdmin):
path(
"account-object-link/<int:pk>",
self.admin_site.admin_view(self.link_object_to_account),
name="object-account-link"
name="object-account-link",
)
]
return custom_urls + urls
@ -276,8 +297,9 @@ class ObjectAdmin(admin.ModelAdmin):
def link_button(self, obj):
return format_html(
'<a class="button" href="{}">Link to Account</a>&nbsp;',
reverse("admin:object-account-link", args=[obj.pk])
reverse("admin:object-account-link", args=[obj.pk]),
)
link_button.short_description = "Create attrs/locks for puppeting"
link_button.allow_tags = True
@ -305,21 +327,24 @@ class ObjectAdmin(admin.ModelAdmin):
lock = obj.locks.get("puppet")
lock += f" or pid({account.id})"
obj.locks.add(lock)
self.message_user(request,
"Did the following (where possible): "
f"Set Account.db._last_puppet = {obj}, "
f"Added {obj} to Account.db._playable_characters list, "
f"Added 'puppet:pid({account.id})' lock to {obj}.")
self.message_user(
request,
"Did the following (where possible): "
f"Set Account.db._last_puppet = {obj}, "
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 for this action "
"(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]))
def save_model(self, request, obj, form, change):
"""
Model-save hook.

View file

@ -15,8 +15,7 @@ from . import utils as adminutils
class ScriptForm(forms.ModelForm):
db_key = forms.CharField(
label = "Name/Key",
help_text="Script identifier, shown in listings etc."
label="Name/Key", help_text="Script identifier, shown in listings etc."
)
db_typeclass_path = forms.ChoiceField(
@ -24,10 +23,12 @@ class ScriptForm(forms.ModelForm):
help_text="This is the Python-path to the class implementing the actual script functionality. "
"<BR>If your custom class is not found here, it may not be imported into Evennia yet.",
choices=lambda: adminutils.get_and_load_typeclasses(
parent=ScriptDB, excluded_parents=["evennia.prototypes.prototypes.DbPrototype"])
parent=ScriptDB, excluded_parents=["evennia.prototypes.prototypes.DbPrototype"]
),
)
db_lock_storage = forms.CharField( label="Locks",
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. "
@ -38,18 +39,14 @@ class ScriptForm(forms.ModelForm):
db_interval = forms.IntegerField(
label="Repeat Interval",
help_text="Optional timer component.<BR>How often to call the Script's<BR>`at_repeat` hook, in seconds."
"<BR>Set to 0 to disable."
"<BR>Set to 0 to disable.",
)
db_repeats = forms.IntegerField(
help_text="Only repeat this many times."
"<BR>Set to 0 to run indefinitely."
)
db_start_delay = forms.BooleanField(
help_text="Wait <B>Interval</B> seconds before first call."
help_text="Only repeat this many times." "<BR>Set to 0 to run indefinitely."
)
db_start_delay = forms.BooleanField(help_text="Wait <B>Interval</B> seconds before first call.")
db_persistent = forms.BooleanField(
label = "Survives reboot",
help_text="If unset, a server reboot will remove the timer."
label="Survives reboot", help_text="If unset, a server reboot will remove the timer."
)
@ -68,6 +65,7 @@ class ScriptAttributeInline(AttributeInline):
Inline attribute tags.
"""
model = ScriptDB.db_attributes.through
related_field = "scriptdb"
@ -108,8 +106,8 @@ class ScriptAdmin(admin.ModelAdmin):
("db_key", "db_typeclass_path"),
("db_interval", "db_repeats", "db_start_delay", "db_persistent"),
"db_obj",
"db_lock_storage",
"serialized_string"
"db_lock_storage",
"serialized_string",
)
},
),
@ -122,13 +120,13 @@ class ScriptAdmin(admin.ModelAdmin):
"""
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 this script there."
)
def get_form(self, request, obj=None, **kwargs):
"""
Overrides help texts.

View file

@ -20,9 +20,7 @@ class TagForm(forms.ModelForm):
"""
db_key = forms.CharField(
label="Key/Name", required=True, help_text="The main key identifier"
)
db_key = forms.CharField(label="Key/Name", required=True, help_text="The main key identifier")
db_category = forms.CharField(
label="Category",
help_text="Used for grouping tags. Unset (default) gives a category of None",
@ -32,15 +30,22 @@ class TagForm(forms.ModelForm):
label="Type",
choices=[(None, "-"), ("alias", "alias"), ("permission", "permission")],
help_text="Tags are used for different things. Unset for regular tags.",
required=False
required=False,
)
db_model = forms.ChoiceField(
label="Model" ,
label="Model",
required=False,
help_text = "Each Tag can only 'attach' to one type of entity.",
choices=([("objectdb", "objectdb"), ("accountdb", "accountdb"),
("scriptdb", "scriptdb"), ("channeldb", "channeldb"),
("helpentry", "helpentry"), ("msg", "msg")])
help_text="Each Tag can only 'attach' to one type of entity.",
choices=(
[
("objectdb", "objectdb"),
("accountdb", "accountdb"),
("scriptdb", "scriptdb"),
("channeldb", "channeldb"),
("helpentry", "helpentry"),
("msg", "msg"),
]
),
)
db_data = forms.CharField(
label="Data",
@ -77,7 +82,7 @@ class InlineTagForm(forms.ModelForm):
label="Type",
choices=[(None, "-"), ("alias", "alias"), ("permission", "permission")],
help_text="Tags are used for different things. Unset for regular tags.",
required=False
required=False,
)
tag_data = forms.CharField(
label="Data",
@ -91,10 +96,10 @@ class InlineTagForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
"""
If we have a tag, then we'll prepopulate our instance with the fields we'd expect it
to have based on the tag. tag_key, tag_category, tag_type, and tag_data all refer to
the corresponding tag fields. The initial data of the form fields will similarly be
populated.
If we have a tag, then we'll prepopulate our instance with the fields we'd expect it
to have based on the tag. tag_key, tag_category, tag_type, and tag_data all refer to
the corresponding tag fields. The initial data of the form fields will similarly be
populated.
"""
super().__init__(*args, **kwargs)
tagkey = None
@ -142,6 +147,7 @@ class TagFormSet(forms.BaseInlineFormSet):
Object, where the handler is an AliasHandler, PermissionsHandler, or TagHandler, based on the
type of tag.
"""
verbose_name = "Tag"
verbose_name_plural = "Tags"
@ -222,13 +228,6 @@ class TagAdmin(admin.ModelAdmin):
fieldsets = (
(
None,
{
"fields": (
("db_key", "db_category"),
("db_tagtype", "db_model"),
"db_data"
)
},
{"fields": (("db_key", "db_category"), ("db_tagtype", "db_model"), "db_data")},
),
)

View file

@ -28,6 +28,4 @@ if settings.EVENNIA_ADMIN:
]
else:
# Just include the normal Django admin.
urlpatterns += [
path("", admin.site.urls)
]
urlpatterns += [path("", admin.site.urls)]

View file

@ -26,6 +26,7 @@ def get_and_load_typeclasses(parent=None, excluded_parents=None):
# this is necessary in order to have typeclasses imported and accessible
# in the inheritance tree.
import evennia
evennia._init()
# this return a dict (path: class}
@ -33,18 +34,27 @@ def get_and_load_typeclasses(parent=None, excluded_parents=None):
# filter out any excludes
excluded_parents = excluded_parents or []
tpaths = [path for path, tclass in tmap.items()
if not any(inherits_from(tclass, excl) for excl in excluded_parents)]
tpaths = [
path
for path, tclass in tmap.items()
if not any(inherits_from(tclass, excl) for excl in excluded_parents)
]
# sort so we get custom paths (not in evennia repo) first
tpaths = sorted(tpaths, key=lambda k: (1 if k.startswith("evennia.") else 0, k))
# the base models are not typeclasses so we filter them out
tpaths = [path for path in tpaths if path not in
("evennia.objects.models.ObjectDB",
"evennia.accounts.models.AccountDB",
"evennia.scripts.models.ScriptDB",
"evennia.comms.models.ChannelDB",)]
tpaths = [
path
for path in tpaths
if path
not in (
"evennia.objects.models.ObjectDB",
"evennia.accounts.models.AccountDB",
"evennia.scripts.models.ScriptDB",
"evennia.comms.models.ChannelDB",
)
]
# return on form excepted by ChoiceField
return [(path, path) for path in tpaths if path]
@ -66,6 +76,7 @@ def get_and_load_cmdsets(parent=None, excluded_parents=None):
"""
# we must do this to have cmdsets imported and accessible in the inheritance tree.
import evennia
evennia._init()
cmap = get_all_cmdsets(parent)