From 16e494f508882846caa2825804f3a0cac2a469f7 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Sat, 24 Jan 2009 03:50:37 +0000 Subject: [PATCH] Fix HelpEntry model search field in the admin to search for topic name and the topic's text. Add missing search types to @search, aside from 'powers', which will need to be added once we figure out how powers will work. --- src/commands/search.py | 29 ++++++++++++++++++++++++++--- src/helpsys/models.py | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/commands/search.py b/src/commands/search.py index 37c3e908b..4e982a7e9 100644 --- a/src/commands/search.py +++ b/src/commands/search.py @@ -104,10 +104,33 @@ def build_query(session, search_query, search_player, search_type, elif search_restriction == "player": search_query = search_query.filter(type=defines_global.OTYPE_PLAYER) else: - session.msg("Invalid class. Must be one of: room, thing, exit, player") + session.msg("Invalid class. See 'help SEARCH CLASSES'.") return None - elif search_type == "object": - search_query = search_query.filter(name__icontains=search_restriction) + elif search_type == "parent": + search_query = search_query.filter(script_parent__iexact=search_restriction) + elif search_type == "object" or search_type == "thing": + search_query = search_query.filter(name__icontains=search_restriction, + type=defines_global.OTYPE_THING) + elif search_type == "rooms": + search_query = search_query.filter(name__icontains=search_restriction, + type=defines_global.OTYPE_ROOM) + elif search_type == "exits": + search_query = search_query.filter(name__icontains=search_restriction, + type=defines_global.OTYPE_EXIT) + elif search_type == "players": + search_query = search_query.filter(name__icontains=search_restriction, + type=defines_global.OTYPE_PLAYER) + elif search_type == "zone": + zone_obj = Object.objects.standard_plr_objsearch(session, + search_restriction) + # Use standard_plr_objsearch to handle duplicate/nonexistant results. + if not zone_obj: + return None + search_query = search_query.filter(zone=zone_obj) + elif search_type == "power": + # TODO: Need this once we have powers implemented. + session.msg("To be implemented...") + return None elif search_type == "flags": flag_list = search_restriction.split() #session.msg("restriction: %s" % flag_list) diff --git a/src/helpsys/models.py b/src/helpsys/models.py index 8b806f77a..5140d007a 100644 --- a/src/helpsys/models.py +++ b/src/helpsys/models.py @@ -39,5 +39,5 @@ class HelpEntryAdmin(admin.ModelAdmin): list_display = ('id', 'topicname', 'staff_only') list_display_links = ('id', 'topicname') list_filter = ('staff_only',) - search_fields = ['entrytext'] + search_fields = ['topicname', 'entrytext'] admin.site.register(HelpEntry, HelpEntryAdmin) \ No newline at end of file