10.1.10. Class cerebro.aclasses.Tag

class cerebro.aclasses.Tag(task_id, tag_id)[source]

Bases: cerebro.aclasses.AbstractTag

Task tag class.

Methods

Note

In Cerebro tags are used as additional task attributes. Having been applied to a project, a tag applies automatically to the task. In the process of working with tasks, gradually, tags are being filled with values.

tags = task.tags()
for tag in tаgs:
        print('Task tag', tag.name(), tag.value())                      
set_value(val)[source]

Sets tag value. ‘None’ sets tag value to ‘not set’.

Depending on tag type, different value types may be set:

if tag.type() == tag.TYPE_INTEGER: # integer
        tag.set_value(int)
elif tag.type() == tag.TYPE_ENUM: # enumeration
        tag.set_value(element_id) # enumeration element ID
elif tag.type() == tag.TYPE_REAL: # real number
        tag.set_value(float)
elif tag.type() == tag.TYPE_STRING: # string
        tag.set_value(string)
elif tag.type() == tag.TYPE_MULTI_ENUM: # multi enumeration
        tag.set_value([element_id,]) # a list of enumeration elements IDs

Resetting tag value:

if tag.value() != None:
        tag.set_value(None)             

In case of ‘enumeration’ and ‘multi enumeration’, the IDs to set values are taken from the list of elements elements().

elems = tag.elements()
if len(elems) > 0: # for the 'enumeration' type.
        tag.set_value(elems[0][0]) 
if len(elems) > 1: # for the 'multi enumeration' type. 
        # setting two elements
        elems_to_set = [ elems[0][0], elems[1][0] ]
        tag.set_value(elems_to_set)

See also

value().

task_id()[source]
Returns:task ID.
Return type:int
value()[source]
Returns:tag value. If the value is not set, returns None.

Depending on tag type, different value types are returned:

if tag.type() == tag.TYPE_INTEGER: # integer
        return int
elif tag.type() == tag.TYPE_ENUM: # enumeration
        return (element_id, element_name) # 2-field tuple: enumeration element ID, enumeration name
elif tag.type() == tag.TYPE_REAL: # real number
        return float
elif tag.type() == tag.TYPE_STRING: # string
        return string
elif tag.type() == tag.TYPE_MULTI_ENUM: # multi enumeration
        return [(element_id, element_name),] # list of 2-field tuples: enumeration element ID, enumeration name

See also

set_value().