Make scripts/objects lists use EvMore. Change EvMore to not justify by default.
This commit is contained in:
parent
b5aee2c41e
commit
69d85bd184
221 changed files with 2190 additions and 6810 deletions
|
|
@ -87,9 +87,9 @@ class ObjectDBManager(TypedObjectManager):
|
|||
or Q()
|
||||
)
|
||||
if exact:
|
||||
return self.filter(
|
||||
cand_restriction & Q(db_account__username__iexact=ostring)
|
||||
).order_by("id")
|
||||
return self.filter(cand_restriction & Q(db_account__username__iexact=ostring)).order_by(
|
||||
"id"
|
||||
)
|
||||
else: # fuzzy matching
|
||||
obj_cands = self.select_related().filter(
|
||||
cand_restriction & Q(db_account__username__istartswith=ostring)
|
||||
|
|
@ -121,8 +121,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
or Q()
|
||||
)
|
||||
return self.filter(
|
||||
cand_restriction
|
||||
& Q(db_key__iexact=oname, db_typeclass_path__exact=otypeclass_path)
|
||||
cand_restriction & Q(db_key__iexact=oname, db_typeclass_path__exact=otypeclass_path)
|
||||
).order_by("id")
|
||||
|
||||
# attr/property related
|
||||
|
|
@ -143,9 +142,9 @@ class ObjectDBManager(TypedObjectManager):
|
|||
cand_restriction = (
|
||||
candidates is not None and Q(id__in=[obj.id for obj in candidates]) or Q()
|
||||
)
|
||||
return self.filter(
|
||||
cand_restriction & Q(db_attributes__db_key=attribute_name)
|
||||
).order_by("id")
|
||||
return self.filter(cand_restriction & Q(db_attributes__db_key=attribute_name)).order_by(
|
||||
"id"
|
||||
)
|
||||
|
||||
def get_objs_with_attr_value(
|
||||
self, attribute_name, attribute_value, candidates=None, typeclasses=None
|
||||
|
|
@ -174,9 +173,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
and Q(pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj])
|
||||
or Q()
|
||||
)
|
||||
type_restriction = (
|
||||
typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q()
|
||||
)
|
||||
type_restriction = typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q()
|
||||
|
||||
# This doesn't work if attribute_value is an object. Workaround below
|
||||
|
||||
|
|
@ -184,10 +181,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
return self.filter(
|
||||
cand_restriction
|
||||
& type_restriction
|
||||
& Q(
|
||||
db_attributes__db_key=attribute_name,
|
||||
db_attributes__db_value=attribute_value,
|
||||
)
|
||||
& Q(db_attributes__db_key=attribute_name, db_attributes__db_value=attribute_value)
|
||||
).order_by("id")
|
||||
else:
|
||||
# We must loop for safety since the referenced lookup gives deepcopy error if attribute value is an object.
|
||||
|
|
@ -196,9 +190,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
from evennia.typeclasses.models import Attribute as _ATTR
|
||||
cands = list(
|
||||
self.filter(
|
||||
cand_restriction
|
||||
& type_restriction
|
||||
& Q(db_attributes__db_key=attribute_name)
|
||||
cand_restriction & type_restriction & Q(db_attributes__db_key=attribute_name)
|
||||
)
|
||||
)
|
||||
results = [
|
||||
|
|
@ -229,9 +221,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
)
|
||||
querykwargs = {property_name: None}
|
||||
try:
|
||||
return list(
|
||||
self.filter(cand_restriction).exclude(Q(**querykwargs)).order_by("id")
|
||||
)
|
||||
return list(self.filter(cand_restriction).exclude(Q(**querykwargs)).order_by("id"))
|
||||
except exceptions.FieldError:
|
||||
return []
|
||||
|
||||
|
|
@ -257,14 +247,10 @@ class ObjectDBManager(TypedObjectManager):
|
|||
and Q(pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj])
|
||||
or Q()
|
||||
)
|
||||
type_restriction = (
|
||||
typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q()
|
||||
)
|
||||
type_restriction = typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q()
|
||||
try:
|
||||
return list(
|
||||
self.filter(
|
||||
cand_restriction & type_restriction & Q(**querykwargs)
|
||||
).order_by("id")
|
||||
self.filter(cand_restriction & type_restriction & Q(**querykwargs)).order_by("id")
|
||||
)
|
||||
except exceptions.FieldError:
|
||||
return []
|
||||
|
|
@ -290,19 +276,11 @@ class ObjectDBManager(TypedObjectManager):
|
|||
contents (list): Matching contents, without excludeobj, if given.
|
||||
"""
|
||||
exclude_restriction = (
|
||||
Q(pk__in=[_GA(obj, "id") for obj in make_iter(excludeobj)])
|
||||
if excludeobj
|
||||
else Q()
|
||||
)
|
||||
return (
|
||||
self.filter(db_location=location)
|
||||
.exclude(exclude_restriction)
|
||||
.order_by("id")
|
||||
Q(pk__in=[_GA(obj, "id") for obj in make_iter(excludeobj)]) if excludeobj else Q()
|
||||
)
|
||||
return self.filter(db_location=location).exclude(exclude_restriction).order_by("id")
|
||||
|
||||
def get_objs_with_key_or_alias(
|
||||
self, ostring, exact=True, candidates=None, typeclasses=None
|
||||
):
|
||||
def get_objs_with_key_or_alias(self, ostring, exact=True, candidates=None, typeclasses=None):
|
||||
"""
|
||||
Args:
|
||||
ostring (str): A search criterion.
|
||||
|
|
@ -328,9 +306,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
# build query objects
|
||||
candidates_id = [_GA(obj, "id") for obj in make_iter(candidates) if obj]
|
||||
cand_restriction = candidates is not None and Q(pk__in=candidates_id) or Q()
|
||||
type_restriction = (
|
||||
typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q()
|
||||
)
|
||||
type_restriction = typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q()
|
||||
if exact:
|
||||
# exact match - do direct search
|
||||
return (
|
||||
|
|
@ -351,19 +327,14 @@ class ObjectDBManager(TypedObjectManager):
|
|||
elif candidates:
|
||||
# fuzzy with candidates
|
||||
search_candidates = (
|
||||
self.filter(cand_restriction & type_restriction)
|
||||
.distinct()
|
||||
.order_by("id")
|
||||
self.filter(cand_restriction & type_restriction).distinct().order_by("id")
|
||||
)
|
||||
else:
|
||||
# fuzzy without supplied candidates - we select our own candidates
|
||||
search_candidates = (
|
||||
self.filter(
|
||||
type_restriction
|
||||
& (
|
||||
Q(db_key__istartswith=ostring)
|
||||
| Q(db_tags__db_key__istartswith=ostring)
|
||||
)
|
||||
& (Q(db_key__istartswith=ostring) | Q(db_tags__db_key__istartswith=ostring))
|
||||
)
|
||||
.distinct()
|
||||
.order_by("id")
|
||||
|
|
@ -374,9 +345,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
index_matches = string_partial_matching(key_strings, ostring, ret_index=True)
|
||||
if index_matches:
|
||||
# a match by key
|
||||
return [
|
||||
obj for ind, obj in enumerate(search_candidates) if ind in index_matches
|
||||
]
|
||||
return [obj for ind, obj in enumerate(search_candidates) if ind in index_matches]
|
||||
else:
|
||||
# match by alias rather than by key
|
||||
search_candidates = search_candidates.filter(
|
||||
|
|
@ -389,9 +358,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
for alias in candidate.aliases.all():
|
||||
alias_strings.append(alias)
|
||||
alias_candidates.append(candidate)
|
||||
index_matches = string_partial_matching(
|
||||
alias_strings, ostring, ret_index=True
|
||||
)
|
||||
index_matches = string_partial_matching(alias_strings, ostring, ret_index=True)
|
||||
if index_matches:
|
||||
# it's possible to have multiple matches to the same Object, we must weed those out
|
||||
return list({alias_candidates[ind] for ind in index_matches})
|
||||
|
|
@ -456,26 +423,17 @@ class ObjectDBManager(TypedObjectManager):
|
|||
if attribute_name:
|
||||
# attribute/property search (always exact).
|
||||
matches = self.get_objs_with_db_property_value(
|
||||
attribute_name,
|
||||
searchdata,
|
||||
candidates=candidates,
|
||||
typeclasses=typeclass,
|
||||
attribute_name, searchdata, candidates=candidates, typeclasses=typeclass
|
||||
)
|
||||
if matches:
|
||||
return matches
|
||||
return self.get_objs_with_attr_value(
|
||||
attribute_name,
|
||||
searchdata,
|
||||
candidates=candidates,
|
||||
typeclasses=typeclass,
|
||||
attribute_name, searchdata, candidates=candidates, typeclasses=typeclass
|
||||
)
|
||||
else:
|
||||
# normal key/alias search
|
||||
return self.get_objs_with_key_or_alias(
|
||||
searchdata,
|
||||
exact=exact,
|
||||
candidates=candidates,
|
||||
typeclasses=typeclass,
|
||||
searchdata, exact=exact, candidates=candidates, typeclasses=typeclass
|
||||
)
|
||||
|
||||
if not searchdata and searchdata != 0:
|
||||
|
|
@ -486,10 +444,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
typeclasses = make_iter(typeclass)
|
||||
for i, typeclass in enumerate(make_iter(typeclasses)):
|
||||
if callable(typeclass):
|
||||
typeclasses[i] = "%s.%s" % (
|
||||
typeclass.__module__,
|
||||
typeclass.__name__,
|
||||
)
|
||||
typeclasses[i] = "%s.%s" % (typeclass.__module__, typeclass.__name__)
|
||||
else:
|
||||
typeclasses[i] = "%s" % typeclass
|
||||
typeclass = typeclasses
|
||||
|
|
@ -502,9 +457,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
candidates = [cand for cand in make_iter(candidates) if cand]
|
||||
if typeclass:
|
||||
candidates = [
|
||||
cand
|
||||
for cand in candidates
|
||||
if _GA(cand, "db_typeclass_path") in typeclass
|
||||
cand for cand in candidates if _GA(cand, "db_typeclass_path") in typeclass
|
||||
]
|
||||
|
||||
dbref = not attribute_name and exact and use_dbref and self.dbref(searchdata)
|
||||
|
|
@ -623,8 +576,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
|
||||
# copy over all attributes from old to new.
|
||||
attrs = (
|
||||
(a.key, a.value, a.category, a.lock_storage)
|
||||
for a in original_object.attributes.all()
|
||||
(a.key, a.value, a.category, a.lock_storage) for a in original_object.attributes.all()
|
||||
)
|
||||
new_object.attributes.batch_add(*attrs)
|
||||
|
||||
|
|
@ -641,8 +593,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
|
||||
# copy over all tags, if any
|
||||
tags = (
|
||||
(t.db_key, t.db_category, t.db_data)
|
||||
for t in original_object.tags.all(return_objs=True)
|
||||
(t.db_key, t.db_category, t.db_data) for t in original_object.tags.all(return_objs=True)
|
||||
)
|
||||
new_object.tags.batch_add(*tags)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue