mirror of
https://github.com/evennia/evennia.git
synced 2026-03-29 20:17:16 +02:00
Removed LiteAttributes, made Nicks use Attributes. Added category and strvalue fields to Attribute. Made Attributes accessible through an AttributeHandler, like most other advanced properties.
This commit is contained in:
parent
befe6a6db0
commit
2f5c895f76
9 changed files with 609 additions and 420 deletions
|
|
@ -50,7 +50,7 @@ class AttributeManager(models.Manager):
|
|||
def exists(self,*args, **kwargs):
|
||||
return super(AttributeManager, self).exists(*args, **kwargs)
|
||||
|
||||
def get_attrs_on_obj(self, searchstr, obj, exact_match=True):
|
||||
def get_attrs_on_obj(self, searchstr, obj, category=None, exact_match=True):
|
||||
"""
|
||||
Searches the object's attributes for attribute key matches.
|
||||
|
||||
|
|
@ -58,10 +58,11 @@ class AttributeManager(models.Manager):
|
|||
"""
|
||||
# Retrieve the list of attributes for this object.
|
||||
|
||||
category_cond = Q(db_category__iexact=category) if category else Q()
|
||||
if exact_match:
|
||||
return _GA("obj", "db_attributes").filter(db_key__iexact=searchstr)
|
||||
return _GA("obj", "db_attributes").filter(db_key__iexact=searchstr & category_cond)
|
||||
else:
|
||||
return _GA("obj", "db_attributes").filter(db_key__icontains=searchstr)
|
||||
return _GA("obj", "db_attributes").filter(db_key__icontains=searchstr & category_cond)
|
||||
|
||||
def attr_namesearch(self, *args, **kwargs):
|
||||
"alias wrapper for backwards compatability"
|
||||
|
|
@ -86,62 +87,6 @@ class AttributeManager(models.Manager):
|
|||
"alias wrapper for backwards compatability"
|
||||
return self.get_attr_by_value(self, *args, **kwargs)
|
||||
|
||||
#
|
||||
# LiteAttributeManager
|
||||
#
|
||||
|
||||
class LiteAttributeManager(models.Manager):
|
||||
"""
|
||||
Manager methods for LiteAttributes
|
||||
"""
|
||||
def get_lattrs_on_obj(self, obj, search_key=None, category=None):
|
||||
"""
|
||||
Get all lattrs on obj, optionally limited by key and/or category
|
||||
"""
|
||||
if search_key or category:
|
||||
key_cands = Q(db_key__iexact=search_key.lower().strip()) if search_key!=None else Q()
|
||||
cat_cands = Q(db_category__iexact=category.lower.strip()) if search_key!=None else Q()
|
||||
return _GA(obj, "db_liteattributes").filter(cat_cands & key_cands)
|
||||
else:
|
||||
return list(_GA(obj, "db_liteattributes").all())
|
||||
|
||||
def get_lattr(self, search_key=None, category=None):
|
||||
"""
|
||||
Search and return all liteattrs matching any combination of
|
||||
the search criteria.
|
||||
search_key (string) - the lattr identifier
|
||||
category (string) - the lattr category
|
||||
"""
|
||||
key_cands = Q(db_key__iexact=search_key.lower().strip()) if search_key!=None else Q()
|
||||
cat_cands = Q(db_category__iexact=category.lower.strip()) if search_key!=None else Q()
|
||||
return list(self.filter(key_cands & cat_cands))
|
||||
|
||||
def get_lattr_data(self, obj=None, search_key=None, category=None):
|
||||
"""
|
||||
Retrieve data from found lattrs in an efficient way. Returns a list of data
|
||||
matching the search criterions
|
||||
"""
|
||||
key_cands = Q(db_key__iexact=search_key.lower().strip()) if search_key!=None else Q()
|
||||
cat_cands = Q(db_category__iexact=category.lower.strip()) if search_key!=None else Q()
|
||||
if obj:
|
||||
query = _GA(obj, "db_liteattributes").filter(key_cands & cat_cands).prefetch_related("db_data")
|
||||
else:
|
||||
query = self.filter(key_cands & cat_cands).prefetch_related("db_data")
|
||||
return [q.db_data for q in query]
|
||||
|
||||
def create_lattr(self, key, category=None, data=None, obj=None):
|
||||
"""
|
||||
Create a LiteAttribute. This makes sure the create case-insensitive keys.
|
||||
"""
|
||||
|
||||
lattr = self.objects.create(db_key=key.lower().strip(),
|
||||
db_category=category.lower().strip() if category!=None else None,
|
||||
db_data=str(data) if data!=None else None)
|
||||
lattr.save()
|
||||
if obj:
|
||||
obj.db_liteattributes.add(lattr)
|
||||
return lattr
|
||||
|
||||
#
|
||||
# TagManager
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue