mirror of
https://github.com/evennia/evennia.git
synced 2026-03-29 12:07:17 +02:00
ListView category grouping fix
This commit is contained in:
parent
6d7755976e
commit
2e351b7fab
2 changed files with 53 additions and 39 deletions
|
|
@ -18,12 +18,12 @@
|
|||
</ol>
|
||||
<hr />
|
||||
<div class="row">
|
||||
{% regroup object_list by help_category as category_list %}
|
||||
|
||||
{% regroup object_list by web_help_category as category_list %}
|
||||
|
||||
{% if category_list %}
|
||||
<!-- left column -->
|
||||
<div class="col-lg-9 col-sm-12">
|
||||
|
||||
|
||||
<!-- intro -->
|
||||
<div class="card border-light">
|
||||
<div class="card-body">
|
||||
|
|
@ -33,23 +33,23 @@
|
|||
</div>
|
||||
<hr />
|
||||
<!-- end intro -->
|
||||
|
||||
|
||||
<!-- index list -->
|
||||
<div class="mx-3">
|
||||
{% for help_category in category_list %}
|
||||
<h5><a id="{{ help_category.grouper }}"></a>{{ help_category.grouper|title }}</h5>
|
||||
{% for web_help_category in category_list %}
|
||||
<h5><a id="{{ web_help_category.grouper }}"></a>{{ web_help_category.grouper|title }}</h5>
|
||||
<ul>
|
||||
{% for object in help_category.list %}
|
||||
{% for object in web_help_category.list %}
|
||||
<li><a href="{{ object.web_get_detail_url }}">{{ object|title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
<!-- end index list -->
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- end left column -->
|
||||
|
||||
|
||||
<!-- right column (index) -->
|
||||
<div class="col-lg-3 col-sm-12">
|
||||
{% if user.is_staff %}
|
||||
|
|
@ -58,16 +58,16 @@
|
|||
<!-- end admin button -->
|
||||
<hr />
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">Category Index</div>
|
||||
|
||||
|
||||
<ul class="list-group list-group-flush">
|
||||
{% for category in category_list %}
|
||||
<a href="#{{ category.grouper }}" class="list-group-item">{{ category.grouper|title }}</a>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- end right column -->
|
||||
|
|
@ -81,14 +81,14 @@
|
|||
<p>You're missing out on an opportunity to attract visitors (and potentially new players) to {{ game_name }}!</p>
|
||||
<p>Use Evennia's <a href="https://github.com/evennia/evennia/wiki/Help-System#database-help-entries" class="alert-link" target="_blank">Help System</a> to tell the world about the universe you've created, its lore and legends, its people and creatures, and their customs and conflicts!</p>
|
||||
<p>You don't even need coding skills-- writing Help Entries is no more complicated than writing an email or blog post. Once you publish your first entry, these ugly boxes go away and this page will turn into an index of everything you've written about {{ game_name }}.</p>
|
||||
<p>The documentation you write is eventually picked up by search engines, so the more you write about how {{ game_name }} works, the larger your web presence will be-- and the more traffic you'll attract.
|
||||
<p>The documentation you write is eventually picked up by search engines, so the more you write about how {{ game_name }} works, the larger your web presence will be-- and the more traffic you'll attract.
|
||||
<p>Everything you write can be viewed either on this site or within the game itself, using the in-game help commands.</p>
|
||||
<hr>
|
||||
<p class="mb-0"><a href="/admin/help/helpentry/add/" class="alert-link">Click here</a> to start writing about {{ game_name }}!</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div class="col-lg-12 col-sm-12">
|
||||
<div class="alert alert-secondary" role="alert">
|
||||
<h4 class="alert-heading">Under Construction!</h4>
|
||||
|
|
@ -99,7 +99,7 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
</div>
|
||||
<hr />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -2,30 +2,38 @@
|
|||
Views to manipulate help entries.
|
||||
|
||||
"""
|
||||
from dataclasses import dataclass
|
||||
from django.utils.text import slugify
|
||||
from django.conf import settings
|
||||
from evennia.utils.utils import inherits_from
|
||||
from django.views.generic import ListView
|
||||
from django.views.generic import ListView, DetailView
|
||||
from django.http import HttpResponseBadRequest
|
||||
from django.db.models.functions import Lower
|
||||
from evennia.help.models import HelpEntry
|
||||
from evennia.help.filehelp import FILE_HELP_ENTRIES
|
||||
from .mixins import TypeclassMixin, EvenniaDetailView
|
||||
from django.views.generic import DetailView
|
||||
from .mixins import TypeclassMixin
|
||||
from evennia.utils.logger import log_info
|
||||
|
||||
DEFAULT_HELP_CATEGORY = settings.DEFAULT_HELP_CATEGORY
|
||||
|
||||
def get_help_category(help_entry):
|
||||
if hasattr(help_entry, 'help_category'):
|
||||
return help_entry.help_category
|
||||
elif hasattr(help_entry, 'category'):
|
||||
return help_entry.category
|
||||
elif hasattr(help_entry, 'db_help_category'):
|
||||
return help_entry.db_help_category
|
||||
else:
|
||||
return 'unsorted'
|
||||
|
||||
def get_help_category(help_entry, slugify_cat=True):
|
||||
"""Returns help category.
|
||||
|
||||
Args:
|
||||
help_entry (HelpEntry, FileHelpEntry or Command): Help entry instance.
|
||||
slugify_cat (bool): If true the return string is slugified. Default is True.
|
||||
|
||||
Notes:
|
||||
If the entry does not have attribute 'web_help_entries'. One is created with
|
||||
a slugified copy of the attribute help_category.
|
||||
This attribute is used for sorting the entries for the help index (ListView) page.
|
||||
|
||||
Returns:
|
||||
help_category (str): The category for the help entry.
|
||||
"""
|
||||
if not hasattr(help_entry, 'web_help_category'):
|
||||
setattr(help_entry, 'web_help_category', slugify(help_entry.help_category))
|
||||
return slugify(help_entry.help_category) if slugify_cat else help_entry.help_category
|
||||
|
||||
|
||||
def get_help_topic(help_entry):
|
||||
topic = getattr(help_entry, 'key', False)
|
||||
|
|
@ -34,6 +42,7 @@ def get_help_topic(help_entry):
|
|||
# log_info(f'get_help_topic returning: {topic}')
|
||||
return topic
|
||||
|
||||
|
||||
def can_read_topic(cmd_or_topic, caller):
|
||||
"""
|
||||
Helper method. If this return True, the given help topic
|
||||
|
|
@ -54,6 +63,7 @@ def can_read_topic(cmd_or_topic, caller):
|
|||
else:
|
||||
return cmd_or_topic.access(caller, 'read', default=True)
|
||||
|
||||
|
||||
def can_list_topic(cmd_or_topic, caller):
|
||||
"""
|
||||
Should the specified command appear in the help table?
|
||||
|
|
@ -85,6 +95,7 @@ def can_list_topic(cmd_or_topic, caller):
|
|||
# no explicit 'view' lock - use the 'read' lock
|
||||
return cmd_or_topic.access(caller, 'read', default=True)
|
||||
|
||||
|
||||
def collect_topics(caller, mode='list'):
|
||||
"""
|
||||
Collect help topics from all sources (cmd/db/file).
|
||||
|
|
@ -149,6 +160,7 @@ def collect_topics(caller, mode='list'):
|
|||
|
||||
return cmd_help_topics, db_help_topics, file_help_topics
|
||||
|
||||
|
||||
class HelpMixin(TypeclassMixin):
|
||||
"""
|
||||
This is a "mixin", a modifier of sorts.
|
||||
|
|
@ -180,11 +192,13 @@ class HelpMixin(TypeclassMixin):
|
|||
# collect all help entries
|
||||
cmd_help_topics, db_help_topics, file_help_topics = \
|
||||
collect_topics(account.db._playable_characters[0], mode='query')
|
||||
# combine and sort all the help entries
|
||||
# merge the entries
|
||||
file_db_help_topics = {**file_help_topics, **db_help_topics}
|
||||
all_topics = {**file_db_help_topics, **cmd_help_topics}
|
||||
all_entries = list(all_topics.values())
|
||||
all_entries.sort(key=get_help_category)
|
||||
# sort the entries
|
||||
all_entries = sorted(all_entries, key=get_help_topic) # sort alphabetically
|
||||
all_entries.sort(key=get_help_category) # group by categories
|
||||
# log_info(f'{all_entries}')
|
||||
log_info('get_queryset success')
|
||||
return all_entries
|
||||
|
|
@ -254,18 +268,18 @@ class HelpDetailView(HelpMixin, DetailView):
|
|||
|
||||
# Get queryset and filter out non-related categories
|
||||
full_set = self.get_queryset()
|
||||
obj_topic = get_help_category(obj)
|
||||
topic_set = []
|
||||
obj_category = get_help_category(obj)
|
||||
category_set = []
|
||||
for entry in full_set:
|
||||
entry_topic = get_help_category(entry)
|
||||
if entry_topic.lower() == obj_topic.lower():
|
||||
topic_set.append(entry)
|
||||
context["topic_list"] = topic_set
|
||||
entry_category = get_help_category(entry)
|
||||
if entry_category.lower() == obj_category.lower():
|
||||
category_set.append(entry)
|
||||
context["topic_list"] = category_set
|
||||
|
||||
# log_info(f'topic_set: {topic_set}')
|
||||
# log_info(f'category_set: {category_set}')
|
||||
|
||||
# Find the index position of the given obj in the queryset
|
||||
objs = list(topic_set)
|
||||
objs = list(category_set)
|
||||
for i, x in enumerate(objs):
|
||||
if obj is x:
|
||||
break
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue