Add single tag fields.

This commit is contained in:
Griatch 2017-05-15 20:59:26 +02:00
parent 2b1a4fc49e
commit de552782a0

View file

@ -364,6 +364,23 @@ class OLCBatchField(OLCField):
return None return None
# setting single Alias
class OLCAliasField(OLCField):
key = "Alias"
required = False
label = "An alternative name for the object"
def from_entity(self, entity, **kwargs):
if "index" in kwargs:
self.value = entity.aliases.all()[int(kwargs)]
def to_prototype(self, prototype):
if is_iter(prototype["aliases"]):
prototype["aliases"].append(self.value)
else:
prototype["aliases"] = [self.value]
# batch-setting aliases # batch-setting aliases
class OLCAliasBatchField(OLCBatchField): class OLCAliasBatchField(OLCBatchField):
""" """
@ -384,26 +401,52 @@ class OLCAliasBatchField(OLCBatchField):
return olc_utils.split_by_comma(value) return olc_utils.split_by_comma(value)
def from_entity(self, entity, **kwargs): def from_entity(self, entity, **kwargs):
self.value = list(entity.db_aliases.all()) self.value = list(entity.aliases.all())
def to_prototype(self, prototype): def to_prototype(self, prototype):
prototype['aliases'] = self.value prototype['aliases'] = self.value
# batch-setting tags # setting single Tag
class OLCTagField(OLCField):
"""
Specify as tagname or tagname:category
Tags are used to identify groups of objects for later quick retrieval.
This is very useful for anything from creating zones of rooms to
easily find all Characters belonging a given group etc. A tag can also
have a category for a second level of grouping.
"""
key = "Tag"
required = False
label = "A single label for the object."
def validate(self, value):
def from_entity(self, entity, **kwargs):
if "index" in kwargs:
self.value = entity.tags.all()[int(kwargs)]
def to_prototype(self, prototype):
if is_iter(prototype["tags"]): prototype["tags"].append(self.value)
else:
prototype["tags"] = [self.value]
# batch-setting Tags
class OLCTagBatchField(OLCBatchField): class OLCTagBatchField(OLCBatchField):
""" """
Specify as a comma-separated list of tagname or tagname:category. Specify as a comma-separated list of tagname or tagname:category.
Aliases are alternate names for an object. An alias is just Tags are used to identify groups of objects for later quick retrieval.
as fast to search for as a key and two objects are assumed This is very useful for anything from creating zones of rooms to
to have the same name is *either* their name or any of their easily find all Characters belonging a given group etc.
aliases match.
""" """
key = 'Aliases' key = 'Tags'
required = False required = False
label = "Alternative ways to refer to this object." label = "Attach labels to objects to group and find them."
def validate(self, value): def validate(self, value):
if isinstance(value, basestring): if isinstance(value, basestring):
@ -426,6 +469,23 @@ class OLCTagBatchField(OLCBatchField):
return '\n'.join(outstr) return '\n'.join(outstr)
# setting single Attribute
class OLCAttributeField(OLCField):
key = "Attribute"
required = False
label = "An alternative name for the object"
def from_entity(self, entity, **kwargs):
if "index" in kwargs:
self.value = entity.attributes.all()[int(kwargs)]
def to_prototype(self, prototype):
if is_iter(prototype["attrs"]):
prototype["attrs"].append(self.value)
else:
prototype["attrs"] = [self.value]
# batch-setting attributes # batch-setting attributes
class OLCAttributeBatchField(OLCBatchField): class OLCAttributeBatchField(OLCBatchField):
""" """
@ -464,6 +524,3 @@ class OLCAttributeBatchField(OLCBatchField):
return '\n'.join(outstr) return '\n'.join(outstr)
# Details - individual attrs/tags/aliases on an object rather than batch-adding