Fixed silly bug in previous commit.

This commit is contained in:
Griatch 2013-12-09 09:13:51 +01:00
parent 8b462b4934
commit 81ce6a1827
4 changed files with 26 additions and 13 deletions

View file

@ -25,7 +25,7 @@ class BodyFunctions(Script):
self.interval = 20 # seconds self.interval = 20 # seconds
#self.repeats = 5 # repeat only a certain number of times #self.repeats = 5 # repeat only a certain number of times
self.start_delay = True # wait self.interval until first call self.start_delay = True # wait self.interval until first call
#self.persistent = True self.persistent = True
def at_repeat(self): def at_repeat(self):
""" """

View file

@ -2134,10 +2134,12 @@ class CmdTag(MuxCommand):
# search by tag # search by tag
tag = self.args tag = self.args
category = None category = None
search_category = None
if ":" in tag: if ":" in tag:
tag, category = [part.strip() for part in tag.split(":", 1)] tag, category = [part.strip() for part in tag.split(":", 1)]
category = "object_%s" % category search_category = "object_%s" % category
objs = search.search_tag(tag, category=category) print "tag search:", tag, search_category
objs = search.search_tag(tag, category=search_category)
nobjs = len(objs) nobjs = len(objs)
if nobjs > 0: if nobjs > 0:
string = "Found %i object%s with tag '%s'%s:\n %s" % (nobjs, string = "Found %i object%s with tag '%s'%s:\n %s" % (nobjs,
@ -2192,10 +2194,10 @@ class CmdTag(MuxCommand):
obj = self.caller.search(self.args, global_search=True) obj = self.caller.search(self.args, global_search=True)
if not obj: if not obj:
return return
tags = obj.db_tags.all() tagtuples = obj.tags.all(return_key_and_category=True)
ntags = len(tags) ntags = len(tagtuples)
categories = [tag.db_category.split("_", 1)[1] for tag in tags] tags = [tup[0] for tup in tagtuples]
categories = [" (category: %s)" % cater if cater else "" for cater in categories] categories = [" (category: %s)" % tup[1] if tup[1] else "" for tup in tagtuples]
if ntags: if ntags:
string = "Tag%s on %s: %s" % ("s" if ntags > 1 else "", obj, string = "Tag%s on %s: %s" % ("s" if ntags > 1 else "", obj,
", ".join("'%s'%s" % (tags[i], categories[i]) for i in range(ntags))) ", ".join("'%s'%s" % (tags[i], categories[i]) for i in range(ntags)))

View file

@ -8,12 +8,12 @@ by game/evennia.py).
""" """
import sys
import os
if os.name == 'nt': if os.name == 'nt':
# For Windows batchfile we need an extra path insertion here. # For Windows batchfile we need an extra path insertion here.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname( sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(
os.path.dirname(os.path.abspath(__file__)))))) os.path.dirname(os.path.abspath(__file__))))))
import sys
import os
from src.server.webserver import EvenniaReverseProxyResource from src.server.webserver import EvenniaReverseProxyResource
from twisted.application import internet, service from twisted.application import internet, service
from twisted.internet import protocol, reactor from twisted.internet import protocol, reactor

View file

@ -493,7 +493,7 @@ class TagHandler(object):
using the category <category_prefix><tag_category> using the category <category_prefix><tag_category>
""" """
self.obj = obj self.obj = obj
self.prefix = "%s%s" % (category_prefix.strip().lower() self.prefix = "%s%s" % (category_prefix.strip(" _").lower()
if category_prefix else "", self._base_category) if category_prefix else "", self._base_category)
self._cache = None self._cache = None
@ -555,8 +555,14 @@ class TagHandler(object):
_GA(self.obj, self._m2m_fieldname).remove(tag) _GA(self.obj, self._m2m_fieldname).remove(tag)
self._recache() self._recache()
def all(self, category=None): def all(self, category=None, return_key_and_category=False):
"Get all tags in this handler" """
Get all tags in this handler.
If category is given, return only Tags with this category. If
return_keys_and_categories is set, return a list of tuples [(key, category), ...]
where the category is stripped of the category prefix (this is ignored
if category keyword is given).
"""
if self._cache is None or not _TYPECLASS_AGGRESSIVE_CACHE: if self._cache is None or not _TYPECLASS_AGGRESSIVE_CACHE:
self._recache() self._recache()
if category: if category:
@ -564,7 +570,12 @@ class TagHandler(object):
if category is not None else "") if category is not None else "")
return [to_str(p[0]) for p in _GA(self.obj, self._m2m_fieldname).filter( return [to_str(p[0]) for p in _GA(self.obj, self._m2m_fieldname).filter(
db_category=category).values_list("db_key") if p[0]] db_category=category).values_list("db_key") if p[0]]
elif return_key_and_category:
# return tuple (key, category)
return [(to_str(p.db_key), to_str(p.db_category).lstrip(self.prefix)) for p in self._cache.values()]
else:
return self._cache.keys() return self._cache.keys()
#return [to_str(p[0]) for p in _GA(self.obj, self._m2m_fieldname).filter(db_category__startswith=self.prefix).values_list("db_key") if p[0]] #return [to_str(p[0]) for p in _GA(self.obj, self._m2m_fieldname).filter(db_category__startswith=self.prefix).values_list("db_key") if p[0]]
def __str__(self): def __str__(self):