Reshuffling the Evennia package into the new template paradigm.
This commit is contained in:
parent
2846e64833
commit
2b3a32e447
371 changed files with 17250 additions and 304 deletions
11
lib/help/__init__.py
Normal file
11
lib/help/__init__.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
"""
|
||||
Makes it easier to import by grouping all relevant things already at this level.
|
||||
|
||||
You can henceforth import most things directly from src.help
|
||||
Also, the initiated object manager is available as src.help.manager.
|
||||
|
||||
"""
|
||||
|
||||
#from src.help.models import *
|
||||
#
|
||||
#manager = HelpEntry.objects
|
||||
39
lib/help/admin.py
Normal file
39
lib/help/admin.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"""
|
||||
This defines how to edit help entries in Admin.
|
||||
"""
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
from src.help.models import HelpEntry
|
||||
|
||||
|
||||
|
||||
class HelpEntryForm(forms.ModelForm):
|
||||
"Defines how to display the help entry"
|
||||
class Meta:
|
||||
model = HelpEntry
|
||||
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'}),)
|
||||
|
||||
class HelpEntryAdmin(admin.ModelAdmin):
|
||||
"Sets up the admin manaager for help entries"
|
||||
|
||||
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."}),)
|
||||
|
||||
|
||||
admin.site.register(HelpEntry, HelpEntryAdmin)
|
||||
99
lib/help/manager.py
Normal file
99
lib/help/manager.py
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
"""
|
||||
Custom manager for HelpEntry objects.
|
||||
"""
|
||||
from django.db import models
|
||||
from src.utils import logger, utils
|
||||
__all__ = ("HelpEntryManager",)
|
||||
|
||||
|
||||
class HelpEntryManager(models.Manager):
|
||||
"""
|
||||
This HelpEntryManager implements methods for searching
|
||||
and manipulating HelpEntries directly from the database.
|
||||
|
||||
These methods will all return database objects
|
||||
(or QuerySets) directly.
|
||||
|
||||
Evennia-specific:
|
||||
find_topicmatch
|
||||
find_apropos
|
||||
find_topicsuggestions
|
||||
find_topics_with_category
|
||||
all_to_category
|
||||
search_help (equivalent to ev.search_helpentry)
|
||||
|
||||
"""
|
||||
def find_topicmatch(self, topicstr, exact=False):
|
||||
"""
|
||||
Searches for matching topics based on player's input.
|
||||
"""
|
||||
dbref = utils.dbref(topicstr)
|
||||
if dbref:
|
||||
return self.filter(id=dbref)
|
||||
topics = self.filter(db_key__iexact=topicstr)
|
||||
if not topics and not exact:
|
||||
topics = self.filter(db_key__istartswith=topicstr)
|
||||
if not topics:
|
||||
topics = self.filter(db_key__icontains=topicstr)
|
||||
return topics
|
||||
|
||||
def find_apropos(self, topicstr):
|
||||
"""
|
||||
Do a very loose search, returning all help entries containing
|
||||
the search criterion in their titles.
|
||||
"""
|
||||
return self.filter(db_key__icontains=topicstr)
|
||||
|
||||
def find_topicsuggestions(self, topicstr):
|
||||
"""
|
||||
Do a fuzzy match, preferably within the category of the
|
||||
current topic.
|
||||
"""
|
||||
return self.filter(db_key__icontains=topicstr).exclude(db_key__iexact=topicstr)
|
||||
|
||||
def find_topics_with_category(self, help_category):
|
||||
"""
|
||||
Search topics having a particular category
|
||||
"""
|
||||
return self.filter(db_help_category__iexact=help_category)
|
||||
|
||||
def get_all_topics(self):
|
||||
"""
|
||||
Return all topics.
|
||||
"""
|
||||
return self.all()
|
||||
|
||||
def get_all_categories(self, pobject):
|
||||
"""
|
||||
Return all defined category names with at least one
|
||||
topic in them.
|
||||
"""
|
||||
return list(set(topic.help_category for topic in self.all()))
|
||||
|
||||
def all_to_category(self, default_category):
|
||||
"""
|
||||
Shifts all help entries in database to default_category.
|
||||
This action cannot be reverted. It is used primarily by
|
||||
the engine when importing a default help database, making
|
||||
sure this ends up in one easily separated category.
|
||||
"""
|
||||
topics = self.all()
|
||||
for topic in topics:
|
||||
topic.help_category = default_category
|
||||
topic.save()
|
||||
string = "Help database moved to category %s" % default_category
|
||||
logger.log_infomsg(string)
|
||||
|
||||
def search_help(self, ostring, help_category=None):
|
||||
"""
|
||||
Retrieve a search entry object.
|
||||
|
||||
ostring - the help topic to look for
|
||||
category - limit the search to a particular help topic
|
||||
"""
|
||||
ostring = ostring.strip().lower()
|
||||
if help_category:
|
||||
return self.filter(db_key__iexact=ostring,
|
||||
db_help_category__iexact=help_category)
|
||||
else:
|
||||
return self.filter(db_key__iexact=ostring)
|
||||
31
lib/help/migrations/0001_initial.py
Normal file
31
lib/help/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('typeclasses', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='HelpEntry',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('db_key', models.CharField(help_text=b'key to search for', unique=True, max_length=255, verbose_name=b'help key')),
|
||||
('db_help_category', models.CharField(default=b'General', help_text=b'organizes help entries in lists', max_length=255, verbose_name=b'help category')),
|
||||
('db_entrytext', models.TextField(help_text=b'the main body of help text', verbose_name=b'help entry', blank=True)),
|
||||
('db_lock_storage', models.TextField(help_text=b'normally view:all().', verbose_name=b'locks', blank=True)),
|
||||
('db_staff_only', models.BooleanField(default=False)),
|
||||
('db_tags', models.ManyToManyField(help_text=b'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',
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
||||
1
lib/help/migrations/__init__.py
Normal file
1
lib/help/migrations/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
104
lib/help/models.py
Normal file
104
lib/help/models.py
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
"""
|
||||
Models for the help system.
|
||||
|
||||
The database-tied help system is only half of Evennia's help
|
||||
functionality, the other one being the auto-generated command help
|
||||
that is created on the fly from each command's __doc__ string. The
|
||||
persistent database system defined here is intended for all other
|
||||
forms of help that do not concern commands, like information about the
|
||||
game world, policy info, rules and similar.
|
||||
|
||||
"""
|
||||
from django.db import models
|
||||
from src.utils.idmapper.models import SharedMemoryModel
|
||||
from src.help.manager import HelpEntryManager
|
||||
from src.typeclasses.models import Tag, TagHandler
|
||||
from src.locks.lockhandler import LockHandler
|
||||
from src.utils.utils import lazy_property
|
||||
__all__ = ("HelpEntry",)
|
||||
|
||||
|
||||
#------------------------------------------------------------
|
||||
#
|
||||
# HelpEntry
|
||||
#
|
||||
#------------------------------------------------------------
|
||||
|
||||
class HelpEntry(SharedMemoryModel):
|
||||
"""
|
||||
A generic help entry.
|
||||
|
||||
An HelpEntry object has the following properties defined:
|
||||
key - main name of entry
|
||||
help_category - which category entry belongs to (defaults to General)
|
||||
entrytext - the actual help text
|
||||
permissions - perm strings
|
||||
|
||||
Method:
|
||||
access
|
||||
|
||||
"""
|
||||
|
||||
#
|
||||
# HelpEntry Database Model setup
|
||||
#
|
||||
#
|
||||
# These database fields are all set using their corresponding properties,
|
||||
# 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')
|
||||
# help category
|
||||
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')
|
||||
# lock string storage
|
||||
db_lock_storage = models.TextField('locks', blank=True, help_text='normally view:all().')
|
||||
# tags are primarily used for permissions
|
||||
db_tags = models.ManyToManyField(Tag, null=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)
|
||||
|
||||
# Database manager
|
||||
objects = HelpEntryManager()
|
||||
_is_deleted = False
|
||||
|
||||
# lazy-loaded handlers
|
||||
|
||||
@lazy_property
|
||||
def locks(self):
|
||||
return LockHandler(self)
|
||||
|
||||
@lazy_property
|
||||
def tags(self):
|
||||
return TagHandler(self)
|
||||
|
||||
|
||||
class Meta:
|
||||
"Define Django meta options"
|
||||
verbose_name = "Help Entry"
|
||||
verbose_name_plural = "Help Entries"
|
||||
|
||||
#
|
||||
#
|
||||
# HelpEntry main class methods
|
||||
#
|
||||
#
|
||||
|
||||
def __str__(self):
|
||||
return self.key
|
||||
|
||||
def __unicode__(self):
|
||||
return u'%s' % self.key
|
||||
|
||||
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
|
||||
access_type - type of access sought
|
||||
default - what to return if no lock of access_type was found
|
||||
"""
|
||||
return self.locks.check(accessing_obj, access_type=access_type, default=default)
|
||||
Loading…
Add table
Add a link
Reference in a new issue