Format code with black. Add makefile to run fmt/tests

This commit is contained in:
Griatch 2019-09-28 18:18:11 +02:00
parent d00bce9288
commit c2c7fa311a
299 changed files with 19037 additions and 11611 deletions

View file

@ -14,32 +14,43 @@ class HelpTagInline(TagInline):
class HelpEntryForm(forms.ModelForm):
"Defines how to display the help entry"
class Meta(object):
model = HelpEntry
fields = '__all__'
fields = "__all__"
db_help_category = forms.CharField(label="Help category", initial='General',
help_text="organizes help entries in lists")
db_lock_storage = forms.CharField(label="Locks", initial='view:all()', required=False,
widget=forms.TextInput(attrs={'size': '40'}),)
db_help_category = forms.CharField(
label="Help category", initial="General", help_text="organizes help entries in lists"
)
db_lock_storage = forms.CharField(
label="Locks",
initial="view:all()",
required=False,
widget=forms.TextInput(attrs={"size": "40"}),
)
class HelpEntryAdmin(admin.ModelAdmin):
"Sets up the admin manaager for help entries"
inlines = [HelpTagInline]
list_display = ('id', 'db_key', 'db_help_category', 'db_lock_storage')
list_display_links = ('id', 'db_key')
search_fields = ['^db_key', 'db_entrytext']
ordering = ['db_help_category', 'db_key']
list_display = ("id", "db_key", "db_help_category", "db_lock_storage")
list_display_links = ("id", "db_key")
search_fields = ["^db_key", "db_entrytext"]
ordering = ["db_help_category", "db_key"]
save_as = True
save_on_top = True
list_select_related = True
form = HelpEntryForm
fieldsets = (
(None, {'fields': (('db_key', 'db_help_category'),
'db_entrytext', 'db_lock_storage'),
'description': "Sets a Help entry. Set lock to <i>view:all()</I> unless you want to restrict it."}),)
(
None,
{
"fields": (("db_key", "db_help_category"), "db_entrytext", "db_lock_storage"),
"description": "Sets a Help entry. Set lock to <i>view:all()</I> unless you want to restrict it.",
},
),
)
admin.site.register(HelpEntry, HelpEntryAdmin)

View file

@ -4,6 +4,7 @@ Custom manager for HelpEntry objects.
from django.db import models
from evennia.utils import logger, utils
from evennia.typeclasses.managers import TypedObjectManager
__all__ = ("HelpEntryManager",)
@ -144,7 +145,6 @@ class HelpEntryManager(TypedObjectManager):
"""
ostring = ostring.strip().lower()
if help_category:
return self.filter(db_key__iexact=ostring,
db_help_category__iexact=help_category)
return self.filter(db_key__iexact=ostring, db_help_category__iexact=help_category)
else:
return self.filter(db_key__iexact=ostring)

View file

@ -6,26 +6,61 @@ from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('typeclasses', '0001_initial'),
]
dependencies = [("typeclasses", "0001_initial")]
operations = [
migrations.CreateModel(
name='HelpEntry',
name="HelpEntry",
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('db_key', models.CharField(help_text='key to search for', unique=True, max_length=255, verbose_name='help key')),
('db_help_category', models.CharField(default='General', help_text='organizes help entries in lists', max_length=255, verbose_name='help category')),
('db_entrytext', models.TextField(help_text='the main body of help text', verbose_name='help entry', blank=True)),
('db_lock_storage', models.TextField(help_text='normally view:all().', verbose_name='locks', blank=True)),
('db_staff_only', models.BooleanField(default=False)),
('db_tags', models.ManyToManyField(help_text='tags on this object. Tags are simple string markers to identify, group and alias objects.', to='typeclasses.Tag', null=True)),
(
"id",
models.AutoField(
verbose_name="ID", serialize=False, auto_created=True, primary_key=True
),
),
(
"db_key",
models.CharField(
help_text="key to search for",
unique=True,
max_length=255,
verbose_name="help key",
),
),
(
"db_help_category",
models.CharField(
default="General",
help_text="organizes help entries in lists",
max_length=255,
verbose_name="help category",
),
),
(
"db_entrytext",
models.TextField(
help_text="the main body of help text",
verbose_name="help entry",
blank=True,
),
),
(
"db_lock_storage",
models.TextField(
help_text="normally view:all().", verbose_name="locks", blank=True
),
),
("db_staff_only", models.BooleanField(default=False)),
(
"db_tags",
models.ManyToManyField(
help_text="tags on this object. Tags are simple string markers to identify, group and alias objects.",
to="typeclasses.Tag",
null=True,
),
),
],
options={
'verbose_name': 'Help Entry',
'verbose_name_plural': 'Help Entries',
},
options={"verbose_name": "Help Entry", "verbose_name_plural": "Help Entries"},
bases=(models.Model,),
),
)
]

View file

@ -7,14 +7,16 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('help', '0001_initial'),
]
dependencies = [("help", "0001_initial")]
operations = [
migrations.AlterField(
model_name='helpentry',
name='db_tags',
field=models.ManyToManyField(blank=True, help_text='tags on this object. Tags are simple string markers to identify, group and alias objects.', to='typeclasses.Tag'),
),
model_name="helpentry",
name="db_tags",
field=models.ManyToManyField(
blank=True,
help_text="tags on this object. Tags are simple string markers to identify, group and alias objects.",
to="typeclasses.Tag",
),
)
]

View file

@ -5,34 +5,47 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('help', '0002_auto_20170606_1731'),
]
dependencies = [("help", "0002_auto_20170606_1731")]
operations = [
migrations.AlterField(
model_name='helpentry',
name='db_entrytext',
field=models.TextField(blank=True, help_text='the main body of help text', verbose_name='help entry'),
model_name="helpentry",
name="db_entrytext",
field=models.TextField(
blank=True, help_text="the main body of help text", verbose_name="help entry"
),
),
migrations.AlterField(
model_name='helpentry',
name='db_help_category',
field=models.CharField(default='General', help_text='organizes help entries in lists', max_length=255, verbose_name='help category'),
model_name="helpentry",
name="db_help_category",
field=models.CharField(
default="General",
help_text="organizes help entries in lists",
max_length=255,
verbose_name="help category",
),
),
migrations.AlterField(
model_name='helpentry',
name='db_key',
field=models.CharField(help_text='key to search for', max_length=255, unique=True, verbose_name='help key'),
model_name="helpentry",
name="db_key",
field=models.CharField(
help_text="key to search for", max_length=255, unique=True, verbose_name="help key"
),
),
migrations.AlterField(
model_name='helpentry',
name='db_lock_storage',
field=models.TextField(blank=True, help_text='normally view:all().', verbose_name='locks'),
model_name="helpentry",
name="db_lock_storage",
field=models.TextField(
blank=True, help_text="normally view:all().", verbose_name="locks"
),
),
migrations.AlterField(
model_name='helpentry',
name='db_tags',
field=models.ManyToManyField(blank=True, help_text='tags on this object. Tags are simple string markers to identify, group and alias objects.', to='typeclasses.Tag'),
model_name="helpentry",
name="db_tags",
field=models.ManyToManyField(
blank=True,
help_text="tags on this object. Tags are simple string markers to identify, group and alias objects.",
to="typeclasses.Tag",
),
),
]

View file

@ -19,14 +19,16 @@ from evennia.help.manager import HelpEntryManager
from evennia.typeclasses.models import Tag, TagHandler, AliasHandler
from evennia.locks.lockhandler import LockHandler
from evennia.utils.utils import lazy_property
__all__ = ("HelpEntry",)
#------------------------------------------------------------
# ------------------------------------------------------------
#
# HelpEntry
#
#------------------------------------------------------------
# ------------------------------------------------------------
class HelpEntry(SharedMemoryModel):
"""
@ -51,17 +53,28 @@ class HelpEntry(SharedMemoryModel):
# named same as the field, but withtout the db_* prefix.
# title of the help entry
db_key = models.CharField('help key', max_length=255, unique=True, help_text='key to search for')
db_key = models.CharField(
"help key", max_length=255, unique=True, help_text="key to search for"
)
# help category
db_help_category = models.CharField("help category", max_length=255, default="General",
help_text='organizes help entries in lists')
db_help_category = models.CharField(
"help category",
max_length=255,
default="General",
help_text="organizes help entries in lists",
)
# the actual help entry text, in any formatting.
db_entrytext = models.TextField('help entry', blank=True, help_text='the main body of help text')
db_entrytext = models.TextField(
"help entry", blank=True, help_text="the main body of help text"
)
# lock string storage
db_lock_storage = models.TextField('locks', blank=True, help_text='normally view:all().')
db_lock_storage = models.TextField("locks", blank=True, help_text="normally view:all().")
# tags are primarily used for permissions
db_tags = models.ManyToManyField(Tag, blank=True,
help_text='tags on this object. Tags are simple string markers to identify, group and alias objects.')
db_tags = models.ManyToManyField(
Tag,
blank=True,
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)
@ -99,9 +112,9 @@ class HelpEntry(SharedMemoryModel):
return self.key
def __repr__(self):
return '%s' % self.key
return "%s" % self.key
def access(self, accessing_obj, access_type='read', default=False):
def access(self, accessing_obj, access_type="read", default=False):
"""
Determines if another object has permission to access.
accessing_obj - object trying to access this one
@ -125,8 +138,9 @@ class HelpEntry(SharedMemoryModel):
"""
content_type = ContentType.objects.get_for_model(self.__class__)
return reverse("admin:%s_%s_change" % (content_type.app_label,
content_type.model), args=(self.id,))
return reverse(
"admin:%s_%s_change" % (content_type.app_label, content_type.model), args=(self.id,)
)
@classmethod
def web_get_create_url(cls):
@ -155,9 +169,9 @@ class HelpEntry(SharedMemoryModel):
"""
try:
return reverse('%s-create' % slugify(cls._meta.verbose_name))
return reverse("%s-create" % slugify(cls._meta.verbose_name))
except:
return '#'
return "#"
def web_get_detail_url(self):
"""
@ -186,14 +200,13 @@ class HelpEntry(SharedMemoryModel):
"""
try:
return reverse('%s-detail' % slugify(self._meta.verbose_name),
kwargs={
'category': slugify(self.db_help_category),
'topic': slugify(self.db_key)})
return reverse(
"%s-detail" % slugify(self._meta.verbose_name),
kwargs={"category": slugify(self.db_help_category), "topic": slugify(self.db_key)},
)
except Exception as e:
print(e)
return '#'
return "#"
def web_get_update_url(self):
"""
@ -222,12 +235,12 @@ class HelpEntry(SharedMemoryModel):
"""
try:
return reverse('%s-update' % slugify(self._meta.verbose_name),
kwargs={
'category': slugify(self.db_help_category),
'topic': slugify(self.db_key)})
return reverse(
"%s-update" % slugify(self._meta.verbose_name),
kwargs={"category": slugify(self.db_help_category), "topic": slugify(self.db_key)},
)
except:
return '#'
return "#"
def web_get_delete_url(self):
"""
@ -255,12 +268,12 @@ class HelpEntry(SharedMemoryModel):
"""
try:
return reverse('%s-delete' % slugify(self._meta.verbose_name),
kwargs={
'category': slugify(self.db_help_category),
'topic': slugify(self.db_key)})
return reverse(
"%s-delete" % slugify(self._meta.verbose_name),
kwargs={"category": slugify(self.db_help_category), "topic": slugify(self.db_key)},
)
except:
return '#'
return "#"
# Used by Django Sites/Admin
get_absolute_url = web_get_detail_url