From ccf078b5c83c0ac1a542fa0658d9acc9b329b564 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Sun, 15 Jun 2008 17:30:42 +0000 Subject: [PATCH] Getting rid of functions_help in favor of the new manager. Removed an un-needed import from commands/general. --- apps/helpsys/managers/helpentry.py | 28 +++++++++++++++++++++++++++- commands/comsys.py | 4 ++-- commands/general.py | 15 ++++++++------- functions_help.py | 29 ----------------------------- 4 files changed, 37 insertions(+), 39 deletions(-) delete mode 100644 functions_help.py diff --git a/apps/helpsys/managers/helpentry.py b/apps/helpsys/managers/helpentry.py index f5e9fbcf0..7054f45ce 100644 --- a/apps/helpsys/managers/helpentry.py +++ b/apps/helpsys/managers/helpentry.py @@ -4,5 +4,31 @@ Custom manager for HelpEntry objects. from django.db import models class HelpEntryManager(models.Manager): - pass + def find_topicmatch(self, pobject, topicstr): + """ + Searches for matching topics based on player's input. + """ + is_staff = pobject.is_staff() + + if topicstr.isdigit(): + t_query = self.filter(id=topicstr) + else: + t_query = self.filter(topicname__istartswith=topicstr) + + if not is_staff: + return t_query.exclude(staff_only=1) + + return t_query + + def find_topicsuggestions(self, pobject, topicstr): + """ + Do a fuzzier "contains" match. + """ + is_staff = pobject.is_staff() + t_query = self.filter(topicname__icontains=topicstr) + + if not is_staff: + return t_query.exclude(staff_only=1) + + return t_query diff --git a/commands/comsys.py b/commands/comsys.py index 60e3513b6..7a59e4e87 100644 --- a/commands/comsys.py +++ b/commands/comsys.py @@ -1,9 +1,9 @@ import time -import settings +from django.conf import settings + import functions_general import functions_db -import functions_help import functions_comsys import defines_global import ansi diff --git a/commands/general.py b/commands/general.py index 5ea399cda..1f0262e3b 100644 --- a/commands/general.py +++ b/commands/general.py @@ -1,18 +1,19 @@ +""" +Generic command module. Pretty much every command should go here for +now. +""" import time from django.conf import settings from apps.config.models import ConfigValue +from apps.helpsys.models import HelpEntry import functions_general import functions_db -import functions_help import defines_global import session_mgr import ansi -""" -Generic command module. Pretty much every command should go here for -now. -""" + def cmd_password(cdat): """ Changes your own password. @@ -515,11 +516,11 @@ def cmd_help(cdat): session.msg("Your search query is too short. It must be at least three letters long.") return - topics = functions_help.find_topicmatch(pobject, topicstr) + topics = HelpEntry.objects.find_topicmatch(pobject, topicstr) if len(topics) == 0: session.msg("No matching topics found, please refine your search.") - suggestions = functions_help.find_topicsuggestions(pobject, topicstr) + suggestions = HelpEntry.objects.find_topicsuggestions(pobject, topicstr) if len(suggestions) > 0: session.msg("Matching similarly named topics:") for result in suggestions: diff --git a/functions_help.py b/functions_help.py deleted file mode 100644 index acffb128c..000000000 --- a/functions_help.py +++ /dev/null @@ -1,29 +0,0 @@ -from apps.helpsys.models import HelpEntry -""" -Help system functions. -""" -def find_topicmatch(pobject, topicstr): - """ - Searches for matching topics based on player's input. - """ - is_staff = pobject.is_staff() - if topicstr.isdigit(): - if is_staff: - return HelpEntry.objects.filter(id=topicstr) - else: - return HelpEntry.objects.filter(id=topicstr).exclude(staff_only=1) - else: - if is_staff: - return HelpEntry.objects.filter(topicname__istartswith=topicstr) - else: - return HelpEntry.objects.filter(topicname__istartswith=topicstr).exclude(staff_only=1) - -def find_topicsuggestions(pobject, topicstr): - """ - Do a fuzzier "contains" match. - """ - is_staff = pobject.is_staff() - if is_staff: - return HelpEntry.objects.filter(topicname__icontains=topicstr) - else: - return HelpEntry.objects.filter(topicname__icontains=topicstr).exclude(staff_only=1)