Source code for cerebro.aclasses

# -*- coding: utf-8 -*-
"""
Module "aclasses" contains descriptions of data types (classes), used in Cerebro Python API.

.. rubric:: Classes	

* :py:class:`cerebro.aclasses.AbstractAttachment`
* :py:class:`cerebro.aclasses.AbstractMessage`
* :py:class:`cerebro.aclasses.AbstractTag`
* :py:class:`cerebro.aclasses.Activities`
* :py:class:`cerebro.aclasses.Attachment`
* :py:class:`cerebro.aclasses.Message`
* :py:class:`cerebro.aclasses.NewAttachment`
* :py:class:`cerebro.aclasses.Perm`
* :py:class:`cerebro.aclasses.Statuses`
* :py:class:`cerebro.aclasses.Tag`
* :py:class:`cerebro.aclasses.Task`
* :py:class:`cerebro.aclasses.Users`
"""

import cerebro
import py_cerebro_classes

def get_val_by_type(val_id):
		if type(val_id) == list:
			return val_id
		else:
			ids = list()             
			ids.append(val_id)
			return ids

[docs]class AbstractAttachment: """ Basic class of attachment. Provides basic functions to access attachment properties .. rubric:: Methods * :py:meth:`comment() <cerebro.aclasses.AbstractAttachment.comment>` * :py:meth:`file_path() <cerebro.aclasses.AbstractAttachment.file_path>` * :py:meth:`file_size() <cerebro.aclasses.AbstractAttachment.file_size>` * :py:meth:`has_review() <cerebro.aclasses.AbstractAttachment.has_review>` * :py:meth:`hashtags() <cerebro.aclasses.AbstractAttachment.hashtags>` * :py:meth:`is_link() <cerebro.aclasses.AbstractAttachment.is_link>` * :py:meth:`name() <cerebro.aclasses.AbstractAttachment.name>` * :py:meth:`review_path() <cerebro.aclasses.AbstractAttachment.review_path>` """ DATA_ = '' """ .. rubric:: Tuple fields of attacment """ DATA_MTM = 0 """Data modification time. Type - datetime.""" DATA_EVENT_ID = 1 """Message ID. Type - int.""" DATA_GROUP_ID = 2 """Attachment ID. Type - int.""" DATA_IS_LINK = 3 """Attachment type: 0 - file, 1 - link.""" DATA_HAS_REVIEW = 4 """A mediafile has a review. 0 - no, 1 - yes.""" DATA_FILE_SIZE = 5 """Attachment filesize, bytes. Type - int.""" DATA_NAME = 6 """Attachment name. Type - string.""" DATA_COMMENT = 7 """Text comment. Type - string.""" DATA_FILE_PATH = 8 """File path to attachment. Type - string.""" DATA_REVIEW_PATH = 9 """File path to review. Type - string.""" DATA_FILE_HASH = 10 """Attachment file hash sum. Type - string.""" DATA_REVIEW_HASH = 11 """Review file hash sum. Type - string.""" DATA_THUMB1_HASH = 12 """First thumbnail hash sum. Type - string.""" DATA_THUMB2_HASH = 13 """Second thumbnail hash sum. Type - string.""" DATA_THUMB3_HASH = 14 """Third thumbnail hash sum. Type - string.""" def __init__(self, event_id, message_id, attach_id): self.__event_id = event_id self.__message_id = message_id self.__attach_id = attach_id
[docs] def name(self): """ :returns: attachment filename. If the attachment is a link to a file, returns full path to the file. :rtype: string """ return py_cerebro_classes.attach_data(self.__event_id, self.__message_id, self.__attach_id)[AbstractAttachment.DATA_NAME]
[docs] def comment(self): """ :returns: text comment to the attachment. :rtype: string """ return py_cerebro_classes.attach_data(self.__event_id, self.__message_id, self.__attach_id)[AbstractAttachment.DATA_COMMENT]
[docs] def has_review(self): """ :returns: True, If the attachment has audiovisual review. :rtype: bool """ return py_cerebro_classes.attach_data(self.__event_id, self.__message_id, self.__attach_id)[AbstractAttachment.DATA_HAS_REVIEW] != 0
[docs] def file_size(self): """ :returns: the attachment's filesize in bytes. In case the attachment is a link, returns 0. :rtype: int """ return py_cerebro_classes.attach_data(self.__event_id, self.__message_id, self.__attach_id)[AbstractAttachment.DATA_FILE_SIZE]
[docs] def file_path(self): """ :returns: the path to the file. May be absent if there is no file in the file storage. In thise case, an empty string is returned. :rtype: string """ return py_cerebro_classes.attach_data(self.__event_id, self.__message_id, self.__attach_id)[AbstractAttachment.DATA_FILE_PATH]
[docs] def review_path(self): """ :returns: the path to the review file (overlayed audiovisual comments over the source media file). May be absent if there is no file in the file storage. In thise case, an empty string is returned. :rtype: string """ return py_cerebro_classes.attach_data(self.__event_id, self.__message_id, self.__attach_id)[AbstractAttachment.DATA_REVIEW_PATH]
[docs] def hashtags(self): """ :returns: Returns list of hashtags. :rtype: list(string, ) """ return py_cerebro_classes.attach_hashtags(self.__event_id, self.__message_id, self.__attach_id)
[docs]class AbstractMessage: """ Basic class of message. Provides basic functions to access message properties .. rubric:: Methods * :py:meth:`approved_time() <cerebro.aclasses.AbstractMessage.approved_time>` * :py:meth:`hashtags() <cerebro.aclasses.AbstractMessage.hashtags>` * :py:meth:`is_approved() <cerebro.aclasses.AbstractMessage.is_approved>` * :py:meth:`is_client_visible() <cerebro.aclasses.AbstractMessage.is_client_visible>` * :py:meth:`parent_message_id() <cerebro.aclasses.AbstractMessage.parent_message_id>` * :py:meth:`posted_time() <cerebro.aclasses.AbstractMessage.posted_time>` * :py:meth:`task_id() <cerebro.aclasses.AbstractMessage.task_id>` * :py:meth:`text_as_html() <cerebro.aclasses.AbstractMessage.text_as_html>` * :py:meth:`text_as_plain() <cerebro.aclasses.AbstractMessage.text_as_plain>` * :py:meth:`type() <cerebro.aclasses.AbstractMessage.type>` * :py:meth:`work_time() <cerebro.aclasses.AbstractMessage.work_time>` """ TYPE_ = '' """ .. rubric:: Message types """ TYPE_DEFINITION =0 """Definition.""" TYPE_REVIEW =1 """Review.""" TYPE_REPORT =2 """Report.""" TYPE_NOTE =3 """Note.""" TYPE_CLIENT_REVIEW =4 """Client Review.""" TYPE_RESOURCE_REPORT =5 """Resource report.""" TYPE_STATUS_CHANGES =6 """Message of change of the status of the task.""" FLAG_ = '' """ .. rubric:: Message flags """ FLAG_CLIENT_VISIBLE = 0 """The message is visible to clients.""" FLAG_APPROVED = 1 """The message is confirmed / approved (applicable to Report).""" DATA_ = '' """ .. rubric:: Message tuple fields """ DATA_MTM = 0 """Time of data modification. Type - datetime.""" DATA_ID = 1 """Message ID.""" DATA_PID = 2 """Parent message ID.""" DATA_TYPE = 3 """:py:const:`Message type <cerebro.aclasses.AbstractMessage.TYPE_>`.""" DATA_CREATOR_NAME = 4 """Message author name.""" DATA_CREATED = 5 """Time of message creation. Type - datetime.""" DATA_WORK_TIME = 6 """Working time, minutes.""" DATA_TEXT = 7 """Message text in html format.""" DATA_APPROVED_TIME = 8 """Approved time to be signed off, minutes.""" DATA_FLAGS = 9 """:py:const:`Message flags <cerebro.aclasses.AbstractMessage.FLAG_>`.""" DATA_MODERATOR_NAME = 10 """Name of the user who modified the message.""" DATA_TID = 11 """ID of the task the message refers to.""" DATA_XMTM = 12 """Real time of data modification. Type - datetime.""" DATA_CREATOR_ID = 13 """ID of the user who created the message.""" DATA_MODERATOR_ID = 14 """ID of the user who modified the message.""" DATA_STATUS_ID = 15 DATA_STATUS_NAME = 16 def __init__(self, event_id, message_id): self.__event_id = event_id self.__message_id = message_id
[docs] def type(self): """ :returns: :py:const:`message type <cerebro.aclasses.AbstractMessage.TYPE_>`. :rtype: int :: if message.type() == message.TYPE_REPORT: print('Signed off working time', message.work_time()) """ return py_cerebro_classes.message_data(self.__event_id, self.__message_id)[AbstractMessage.DATA_TYPE]
[docs] def text_as_html(self): """ :returns: message text in html format. :rtype: string """ return py_cerebro_classes.message_text_html(self.__event_id, self.__message_id)
[docs] def text_as_plain(self): """ :returns: message text in plain text format. :rtype: string """ return py_cerebro_classes.message_text_plain(self.__event_id, self.__message_id)
[docs] def work_time(self): """ :returns: working time signed off in the message, minutes. If the message type is Report or Resource Report, this is a working time declared to sign off. If the message type is Review, this is a working time approved to sign off for the preceding Report or Resource Report. For all the rest message types returns 0. :rtype: int """ return py_cerebro_classes.message_data(self.__event_id, self.__message_id)[AbstractMessage.DATA_WORK_TIME]
[docs] def approved_time(self): """ :returns: working time approved to sign off, minutes. If the message type is Report or Resource Report, this is a working time approved to sign off. For all the rest message types returns 0. :rtype: int """ return py_cerebro_classes.message_data(self.__event_id, self.__message_id)[AbstractMessage.DATA_APPROVED_TIME]
[docs] def posted_time(self): """ :returns: time of message creation. :rtype: datetime """ return py_cerebro_classes.message_data(self.__event_id, self.__message_id)[AbstractMessage.DATA_CREATED]
[docs] def is_client_visible(self): """ :returns: True, if the message is marked as Visible to Clients. :rtype: bool """ flags = py_cerebro_classes.message_data(self.__event_id, self.__message_id)[AbstractMessage.DATA_FLAGS] return cerebro.core.has_flag(flags, AbstractMessage.FLAG_CLIENT_VISIBLE) != 0
[docs] def is_approved(self): """ :returns: True, if message type is Report or Resource Report and it is marked as Approved. Such a Report/Resource Report has approved time equal to declared. :rtype: bool :: if message.is_approved() == True: print('work_time == approved_time', message.work_time() == message.approved_time()) """ flags = py_cerebro_classes.message_data(self.__event_id, self.__message_id)[AbstractMessage.DATA_FLAGS] return cerebro.core.has_flag(flags, AbstractMessage.FLAG_APPROVED) != 0
[docs] def parent_message_id(self): """ :returns: parent message ID (Parent message is the message being replied by the current message). As a rule, message ID of Definitions is 0, it means Definitions have no parent messages. :rtype: int :: if message.type() != message.TYPE_DEFINITION: parent_id = message.parent_message_id() print('Parent message', cerebro.core.message(parent_id).text_as_plain()) """ return py_cerebro_classes.message_data(self.__event_id, self.__message_id)[AbstractMessage.DATA_PID]
[docs] def task_id(self): """ :returns: Returns ID of the task the message refers to. :rtype: int """ return py_cerebro_classes.message_data(self.__event_id, self.__message_id)[AbstractMessage.DATA_TID]
[docs] def hashtags(self): """ :returns: Returns list of hashtags. :rtype: list(string, ) """ return py_cerebro_classes.message_hashtags(self.__event_id, self.__message_id)
[docs]class NewAttachment(AbstractAttachment): """ New attachment class. .. rubric:: Methods * :py:meth:`add_hashtags() <cerebro.aclasses.NewAttachment.add_hashtags>` * :py:meth:`remove_hashtags() <cerebro.aclasses.NewAttachment.remove_hashtags>` * :py:meth:`set_comment() <cerebro.aclasses.NewAttachment.set_comment>` * :py:meth:`set_name() <cerebro.aclasses.NewAttachment.set_name>` * :py:class:`methods of the cerebro.aclasses.AbstractAttachment <cerebro.aclasses.AbstractAttachment>` basic class. The objects of the class are used in the :py:class:`cerebro.events.BeforeEventMessage` event in the :py:meth:`new_attachments() <cerebro.events.BeforeEventMessage.new_attachments>` method. :: def before_event(event): evtype = event.event_type() if evtype == event.EVENT_CREATION_OF_MESSAGE or evtype == event.EVENT_CHANGING_OF_MESSAGE: new_attachs = event.new_attachments() for attach in new_attachs: print(attach.name()) """ def __init__(self, event_id, message_id, attach_id): cerebro.aclasses.AbstractAttachment.__init__(self, event_id, message_id, attach_id)
[docs] def set_name(self, name): """ :param string name: attachment name. Changes the name of the new attachment. :: new_attachs = event.new_attachments() for attach in new_attachs: if attach.is_link() != True: # if the new attachment is a file attach.set_name('Attachment - ' + i.name()) # changing the name """ py_cerebro_classes.attach_set_name(self._AbstractAttachment__event_id, self._AbstractAttachment__attach_id, name)
[docs] def set_comment(self, comment): """ :param string comment: a comment to the attachment. Changes a text comment to the new attachment. :: new_attachs = event.new_attachments() for attach in new_attachs: if attach.is_link() == True: # if the new attachment is a link attach.set_comment(i.comment() + '. It's a link') # adding a comment """ py_cerebro_classes.attach_set_comment(self._AbstractAttachment__event_id, self._AbstractAttachment__attach_id, comment)
[docs] def add_hashtags(self, hashtags): """ :param hashtags: hashtag or array of hashtags (every hashtag should be written in one word without spaces). :type hashtags: string, set(string, ) or list(string, ) Adds hashtags to the attachment. .. seealso:: :py:meth:`remove_hashtags() <cerebro.aclasses.NewAttachment.remove_hashtags>`. """ py_cerebro_classes.attach_add_hashtags(self._AbstractAttachment__event_id, self._AbstractAttachment__message_id, self._AbstractAttachment__attach_id, get_val_by_type(hashtags))
[docs] def remove_hashtags(self, hashtags): """ :param hashtags: hashtag or array of hashtags (every hashtag should be written in one word without spaces). :type hashtags: string, set(string, ) or list(string, ) Remove hashtags from the attachment. .. seealso:: :py:meth:`add_hashtags() <cerebro.aclasses.NewAttachment.add_hashtags>`. """ py_cerebro_classes.attach_remove_hashtags(self._AbstractAttachment__event_id, self._AbstractAttachment__message_id, self._AbstractAttachment__attach_id, get_val_by_type(hashtags))
[docs]class Attachment(AbstractAttachment): """ Attachment class. .. rubric:: Methods * :py:meth:`add_hashtags() <cerebro.aclasses.Attachment.add_hashtags>` * :py:meth:`data() <cerebro.aclasses.Attachment.data>` * :py:meth:`file_hash() <cerebro.aclasses.Attachment.file_hash>` * :py:meth:`id() <cerebro.aclasses.Attachment.id>` * :py:meth:`message_id() <cerebro.aclasses.Attachment.message_id>` * :py:meth:`remove_hashtags() <cerebro.aclasses.Attachment.remove_hashtags>` * :py:meth:`review_hash() <cerebro.aclasses.Attachment.review_hash>` * :py:meth:`set_comment() <cerebro.aclasses.Attachment.set_comment>` * :py:meth:`thumbnail_hashs() <cerebro.aclasses.Attachment.thumbnail_hashs>` * :py:class:`methods of the basic class cerebro.aclasses.AbstractAttachment <cerebro.aclasses.AbstractAttachment>` :: attach = cerebro.core.current_attachment() :: attachs = message.attachments() """ def __init__(self, message_id, attach_id): AbstractAttachment.__init__(self, -2, message_id, attach_id)
[docs] def id(self): """ :returns: attachment ID. :rtype: int """ return self._AbstractAttachment__attach_id
[docs] def message_id(self): """ :returns: the ID of the message the attachment belongs to. :rtype: int """ return self._AbstractAttachment__message_id
[docs] def file_hash(self): """ :returns: file hash sum. :rtype: string File hash sum is used by the Cargador file storage to identify files. If you have a file hash sum, you can get the path to the file or enqueue the file to download if it is absent in your file storage. :: if attach.is_link() != True: # Checking if the attachment is a file, not a link # Downloading the file file_name = cerebro.cargador.file_name_form_hash(attach.file_hash()) # attempting to resolve the file name from the file hash sum if file_name == '' or file_name == None: # if the file is missing in our file storage, attempting to download it cerebro.cargador.download_file(attach.file_hash()) If attachment is a link, it has no hash, as far as the linked files, are not added to Cargador file storage """ return py_cerebro_classes.attach_data(self._AbstractAttachment__event_id, self._AbstractAttachment__message_id, self._AbstractAttachment__attach_id)[AbstractAttachment.DATA_FILE_HASH]
[docs] def review_hash(self): """ :returns: file hash sum of a review file (overlayed audiovisual comments). :rtype: string """ return py_cerebro_classes.attach_data(self._AbstractAttachment__event_id, self._AbstractAttachment__message_id, self._AbstractAttachment__attach_id)[AbstractAttachment.DATA_REVIEW_HASH]
[docs] def thumbnail_hashs(self): """ :returns: list of the hash sums of the file's thumbnails. :rtype: list(string,) """ data = py_cerebro_classes.attach_data(self._AbstractAttachment__event_id, self._AbstractAttachment__message_id, self._AbstractAttachment__attach_id) tumbs = list() tumbs.append(data[AbstractAttachment.DATA_THUMB1_HASH]) tumbs.append(data[AbstractAttachment.DATA_THUMB2_HASH]) tumbs.append(data[AbstractAttachment.DATA_THUMB3_HASH]) return tumbs
[docs] def data(self): """ :returns: :py:const:`tuple <cerebro.aclasses.AbstractAttachment.DATA_>` of the attachment. :rtype: tuple Actually, the most part of the methods of this class are interfaces to this tuple. Therefore, you can use its data directly from the tuple. :: attach.file_hash() == attach.data()[attach.DATA_FILE_HASH] attach.is_link() == (attach.data()[attach.DATA_IS_LINK] != 0) # и так далее """ return py_cerebro_classes.attach_data(self._AbstractAttachment__event_id, self._AbstractAttachment__message_id, self._AbstractAttachment__attach_id)
[docs] def set_comment(self, comment): """ :param string comment: a comment to the attachment. Changes a text comment to the new attachment. :: new_attachs = event.new_attachments() for attach in new_attachs: if attach.is_link() == True: # if the new attachment is a link attach.set_comment(i.comment() + '. It's a link') # adding a comment """ py_cerebro_classes.attach_set_comment(self._AbstractAttachment__event_id, self._AbstractAttachment__message_id, self._AbstractAttachment__attach_id, comment)
[docs] def add_hashtags(self, hashtags): """ :param hashtags: hashtag or array of hashtags (every hashtag should be written in one word without spaces). :type hashtags: string, set(string, ) or list(string, ) Adds hashtags to the attachment. .. seealso:: :py:meth:`remove_hashtags() <cerebro.aclasses.Attachment.remove_hashtags>`. """ py_cerebro_classes.attach_add_hashtags(self._AbstractAttachment__event_id, self._AbstractAttachment__message_id, self._AbstractAttachment__attach_id, get_val_by_type(hashtags))
[docs] def remove_hashtags(self, hashtags): """ :param hashtags: hashtag or array of hashtags (every hashtag should be written in one word without spaces). :type hashtags: string, set(string, ) or list(string, ) Remove hashtags from the attachment. .. seealso:: :py:meth:`add_hashtags() <cerebro.aclasses.Attachment.add_hashtags>`. """ py_cerebro_classes.attach_remove_hashtags(self._AbstractAttachment__event_id, self._AbstractAttachment__message_id, self._AbstractAttachment__attach_id, get_val_by_type(hashtags))
[docs]class Message(AbstractMessage): """ Message class. .. rubric:: Methods * :py:meth:`add_hashtags() <cerebro.aclasses.Message.add_hashtags>` * :py:meth:`attachments() <cerebro.aclasses.Message.attachments>` * :py:meth:`creator_id() <cerebro.aclasses.Message.creator_id>` * :py:meth:`data() <cerebro.aclasses.Message.data>` * :py:meth:`id() <cerebro.aclasses.Message.id>` * :py:meth:`moderator_id() <cerebro.aclasses.Message.moderator_id>` * :py:meth:`modification_time() <cerebro.aclasses.Message.modification_time>` * :py:meth:`remove_hashtags() <cerebro.aclasses.Message.remove_hashtags>` * :py:class:`methods of the basic class cerebro.aclasses.AbstractMessage <cerebro.aclasses.AbstractMessage>` :: message = cerebro.core.current_message() :: message = cerebro.core.message(message_id) """ def __init__(self, message_id): AbstractMessage.__init__(self, -2, message_id)
[docs] def id(self): """ :returns: message ID. :rtype: int """ return self._AbstractMessage__message_id
[docs] def creator_id(self): """ :returns: message author's ID. :rtype: int """ return py_cerebro_classes.message_data(self._AbstractMessage__event_id, self._AbstractMessage__message_id)[AbstractMessage.DATA_CREATOR_ID]
[docs] def moderator_id(self): """ :returns: message moderator's ID. :rtype: int """ return py_cerebro_classes.message_data(self._AbstractMessage__event_id, self._AbstractMessage__message_id)[AbstractMessage.DATA_MODERATOR_ID]
[docs] def modification_time(self): """ :returns: time when the message was changed. :rtype: datetime """ return py_cerebro_classes.message_data(self._AbstractMessage__event_id, self._AbstractMessage__message_id)[AbstractMessage.DATA_MTM]
[docs] def data(self): """ :returns: :py:const:`data tuple <cerebro.aclasses.AbstractMessage.DATA_>` on the message. :rtype: tuple Actually, the most part of the methods of this class are interfaces to this tuple. Therefore, you can use its data directly from the tuple. :: message.creator_id() == message.data()[message.DATA_CREATOR_ID] message.is_client_visible() == cerebro.core.has_flag(message.data()[message.DATA_FLAGS], message.FLAG_CLIENT_VISIBLE) # etc. """ return py_cerebro_classes.message_data(self._AbstractMessage__event_id, self._AbstractMessage__message_id)
[docs] def attachments(self): """ :returns: a list of attachments to the message. :rtype: list(:py:class:`cerebro.aclasses.Attachment`,) """ attachs = list() ids = py_cerebro_classes.message_attach_ids(self._AbstractMessage__event_id, self._AbstractMessage__message_id) if ids != None: for id in ids: attachs.append(Attachment(self._AbstractMessage__message_id, id)) return attachs
[docs] def add_hashtags(self, hashtags): """ :param hashtags: hashtag or array of hashtags (every hashtag should be written in one word without spaces). :type hashtags: string, set(string, ) or list(string, ) Adds hashtags to the message. .. seealso:: :py:meth:`remove_hashtags() <cerebro.aclasses.Message.remove_hashtags>`. """ py_cerebro_classes.message_add_hashtags(self._AbstractMessage__event_id, self._AbstractMessage__message_id, get_val_by_type(hashtags))
[docs] def remove_hashtags(self, hashtags): """ :param hashtags: hashtag or array of hashtags (every hashtag should be written in one word without spaces). :type hashtags: string, set(string, ) or list(string, ) Remove hashtags from the message. .. seealso:: :py:meth:`add_hashtags() <cerebro.aclasses.Message.add_hashtags>`. """ py_cerebro_classes.message_remove_hashtags(self._AbstractMessage__event_id, self._AbstractMessage__message_id, get_val_by_type(hashtags))
[docs]class AbstractTag: """ Basic class of task tag. .. rubric:: Methods * :py:meth:`elements() <cerebro.aclasses.AbstractTag.elements>` * :py:meth:`id() <cerebro.aclasses.AbstractTag.id>` * :py:meth:`name() <cerebro.aclasses.AbstractTag.name>` * :py:meth:`type() <cerebro.aclasses.AbstractTag.type>` .. 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. """ TYPE_ = '' """ .. rubric:: Tag types """ TYPE_INTEGER = 0 """Integer.""" TYPE_ENUM = 1 """Enumeration.""" TYPE_REAL = 2 """Real number.""" TYPE_STRING = 3 """String.""" TYPE_MULTI_ENUM = 4 """Multi enumeration.""" def __init__(self, tag_id): self.__tag_id = tag_id
[docs] def id(self): """ :returns: Tag ID. :rtype: int """ return self.__tag_id
[docs] def name(self): """ :returns: tag name. :rtype: string """ return py_cerebro_classes.tag_name(self.__tag_id)
[docs] def type(self): """ :returns: :py:const:`tag type <cerebro.aclasses.AbstractTag.TYPE_>`. :rtype: int """ return py_cerebro_classes.tag_type(self.__tag_id)
[docs] def elements(self): """ :returns: a list of possible enumeration elements. If tag type is neither Enumeration nor Multi enumeration, None is returned. :rtype: [(element_id, element_name),] - a list of 2-field tuples: enumeration element ID, enumeration name """ return py_cerebro_classes.tag_elements(self.__tag_id)
[docs]class Tag(AbstractTag): """ Task tag class. .. rubric:: Methods * :py:meth:`set_value() <cerebro.aclasses.Tag.set_value>` * :py:meth:`task_id() <cerebro.aclasses.Tag.task_id>` * :py:meth:`value() <cerebro.aclasses.Tag.value>` * :py:class:`methods of the basic class cerebro.aclasses.AbstractTag <cerebro.aclasses.AbstractTag>` .. 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()) """ def __init__(self, task_id, tag_id): AbstractTag.__init__(self, tag_id) self.__task_id = task_id
[docs] def task_id(self): """ :returns: task ID. :rtype: int """ return self.__task_id
[docs] def set_value(self, val): """ 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 Resetying 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 :py:meth:`elements() <cerebro.aclasses.AbstractTag.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) .. seealso:: :py:meth:`value() <cerebro.aclasses.Tag.value>`. """ if val == None: py_cerebro_classes.tag_clear(self._AbstractTag__tag_id, self.__task_id) else: type = py_cerebro_classes.tag_type(self._AbstractTag__tag_id) if type == Tag.TYPE_INTEGER: py_cerebro_classes.tag_set_int(self._AbstractTag__tag_id, self.__task_id, val) elif type == Tag.TYPE_ENUM: py_cerebro_classes.tag_set_enum(self._AbstractTag__tag_id, self.__task_id, val) elif type == Tag.TYPE_REAL: py_cerebro_classes.tag_set_real(self._AbstractTag__tag_id, self.__task_id, val) elif type == Tag.TYPE_STRING: py_cerebro_classes.tag_set_str(self._AbstractTag__tag_id, self.__task_id, val) elif type == Tag.TYPE_MULTI_ENUM: py_cerebro_classes.tag_set_multi_enum(self._AbstractTag__tag_id, self.__task_id, val)
[docs] def value(self): """ :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 .. seealso:: :py:meth:`set_value() <cerebro.aclasses.Tag.set_value>`. """ return py_cerebro_classes.tag_value(self._AbstractTag__tag_id, self.__task_id)
[docs]class Users: """ Users class. .. rubric:: Methods * :py:meth:`data() <cerebro.aclasses.Users.data>` * :py:meth:`is_resource() <cerebro.aclasses.Users.is_resource>` The user list consists of users (Cerebro user accounts) and material resources - items/units which do not have actual user accounts but are involved in production process, for example, an editing post or video camera are material resources. :: users = cerebro.core.users() """ DATA_ = '' """ .. rubric:: Fields of user data tuple """ DATA_ID = 0 """User ID.""" DATA_FULL_NAME = 1 """User full name.""" DATA_FLAGS = 2 """:py:const:`User flags <cerebro.aclasses.Users.FLAG_>`.""" DATA_LOGIN = 3 """User login.""" DATA_FIRST_NAME = 4 """User first name.""" DATA_LAST_NAME = 5 """User last name.""" DATA_EMAIL = 6 """User's E-mail address.""" DATA_PHONE = 7 """User's phone number.""" DATA_ICQ = 8 """User's ICQ/Skype ID.""" FLAG_ = '' """ .. rubric:: User flags """ FLAG_IS_RESOURCE = 1 # """Is a material resource.""" def __init__(self): pass
[docs] def data(self): """ :returns: a list of :py:const:`tuples <cerebro.aclasses.Users.DATA_>` on users. :rtype: list(tuple,) """ return py_cerebro_classes.users()
[docs] def is_resource(user_flags): """ :param int user_flags: user flag values. :returns: True, if :py:const:`flag <cerebro.aclasses.Users.FLAG_>` is set to 'material resource'. :rtype: bool an example of picking material resources out of a general user list:: resources = list() users = cerebro.core.users() for user in users.data(): if cerebro.aclasses.Users.is_resource(user[users.DATA_FLAGS]) == True: resources.append(user) """ return cerebro.core.has_flag(user_flags, Users.FLAG_IS_RESOURCE)
[docs]class Statuses: """ Statuses class. .. rubric:: Methods * :py:meth:`data() <cerebro.aclasses.Statuses.data>` * :py:meth:`inheritable() <cerebro.aclasses.Statuses.inheritable>` * :py:meth:`type() <cerebro.aclasses.Statuses.type>` :: statuses = cerebro.core.statuses() """ DATA_ = '' """ .. rubric:: Fields of status data tuple """ DATA_ID = 0 """Status ID.""" DATA_NAME = 1 """Status name.""" DATA_FLAGS = 2 """:py:const:`Status flags <cerebro.aclasses.Statuses.FLAG_>`.""" DATA_ORDER = 3 """Status order number.""" DATA_DESCRIPTION = 4 """Status description.""" DATA_ICON = 5 """Status icon. XPM format.""" DATA_COLOR = 6 """Status color. RGB format is presented as an integer.""" FLAG_ = '' """ .. rubric:: Status flags """ FLAG_INHERITABLE = 1 """Status is inherited.""" FLAG_WORK_STARTED = 2 FLAG_WORK_STOPPED = 3 TYPE_ = '' """ .. rubric:: Status types """ TYPE_IS_SUSPENDED = 0 """Task is suspended.""" TYPE_IS_IN_PROGRESS = 1 """Task is performed.""" TYPE_IS_STOPPED = 2 """Task is stopped.""" def __init__(self): pass
[docs] def data(self): """ :returns: a list of :py:const:`tuples <cerebro.aclasses.Statuses.DATA_>` on all statuses. :rtype: list(tuple,) . seealso:: :py:meth:`possible_statuses() <cerebro.aclasses.Task.possible_statuses>`. """ return py_cerebro_classes.statuses()
[docs] def type(status_flags): """ :param int status_flags: status flag values. :returns: :py:const:`тип <cerebro.aclasses.Statuses.TYPE_>` статуса. :rtype: int Status type shows the condition of the task, when this status is installed. """ type_status = Statuses.TYPE_IS_SUSPENDED if cerebro.core.has_flag(status_flags, Statuses.FLAG_WORK_STARTED) == True: type_status = Statuses.TYPE_IS_IN_PROGRESS elif cerebro.core.has_flag(status_flags, Statuses.FLAG_WORK_STOPPED) == True: type_status = Statuses.TYPE_IS_STOPPED return type_status
[docs] def inheritable(status_flags): """ :param int status_flags: status flag values. :returns: True, if the :py:const:`flag <cerebro.aclasses.Statuses.FLAG_>` is installed as inherited. :rtype: bool The inherited status under task container installation is inherited by all sub-tasks within the task. Example of sample status, you can set to tasks-containers :: inherit_statuses = list() statuses = cerebro.core.statuses() for status in statuses.data(): if cerebro.aclasses.Statuses.inheritable(status[statuses.DATA_FLAGS]) == True: inherit_statuses.append(status) """ return cerebro.core.has_flag(status_flags, Statuses.FLAG_INHERITABLE)
[docs]class Activities: """ Activity types class. .. rubric:: Methods * :py:meth:`data() <cerebro.aclasses.Activities.data>` :: activities = cerebro.core.activities() """ DATA_ = '' """ .. rubric:: Activity tuple fields """ DATA_ID = 0 """Activity type ID.""" DATA_NAME = 1 """Activity type name.""" DATA_COLOR = 2 """Activity type color. RGB format is presented as an integer.""" def __init__(self): pass
[docs] def data(self): """ :returns: a list of :py:const:`tuples <cerebro.aclasses.Activities.DATA_>` on activity types. :rtype: list(tuple,) """ return py_cerebro_classes.activities()
[docs]class Task: """ Task class. .. rubric:: Methods * :py:meth:`activity() <cerebro.aclasses.Task.activity>` * :py:meth:`add_hashtags() <cerebro.aclasses.Task.add_hashtags>` * :py:meth:`allocated() <cerebro.aclasses.Task.allocated>` * :py:meth:`budget() <cerebro.aclasses.Task.budget>` * :py:meth:`creation_time() <cerebro.aclasses.Task.creation_time>` * :py:meth:`creator_id() <cerebro.aclasses.Task.creator_id>` * :py:meth:`data() <cerebro.aclasses.Task.data>` * :py:meth:`finish() <cerebro.aclasses.Task.finish>` * :py:meth:`flags() <cerebro.aclasses.Task.flags>` * :py:meth:`hashtags() <cerebro.aclasses.Task.hashtags>` * :py:meth:`id() <cerebro.aclasses.Task.id>` * :py:meth:`moderator_id() <cerebro.aclasses.Task.moderator_id>` * :py:meth:`modification_time() <cerebro.aclasses.Task.modification_time>` * :py:meth:`name() <cerebro.aclasses.Task.name>` * :py:meth:`parent_id() <cerebro.aclasses.Task.parent_id>` * :py:meth:`parent_url() <cerebro.aclasses.Task.parent_url>` * :py:meth:`payments() <cerebro.aclasses.Task.payments>` * :py:meth:`planned_time() <cerebro.aclasses.Task.planned_time>` * :py:meth:`possible_statuses() <cerebro.aclasses.Task.possible_statuses>` * :py:meth:`priority() <cerebro.aclasses.Task.priority>` * :py:meth:`progress() <cerebro.aclasses.Task.progress>` * :py:meth:`project_id() <cerebro.aclasses.Task.project_id>` * :py:meth:`remove_allocated() <cerebro.aclasses.Task.remove_allocated>` * :py:meth:`remove_hashtags() <cerebro.aclasses.Task.remove_hashtags>` * :py:meth:`set_activity() <cerebro.aclasses.Task.set_activity>` * :py:meth:`set_allocated() <cerebro.aclasses.Task.set_allocated>` * :py:meth:`set_budget() <cerebro.aclasses.Task.set_budget>` * :py:meth:`set_finish() <cerebro.aclasses.Task.set_finish>` * :py:meth:`set_flag() <cerebro.aclasses.Task.set_flag>` * :py:meth:`set_name() <cerebro.aclasses.Task.set_name>` * :py:meth:`set_planned_time() <cerebro.aclasses.Task.set_planned_time>` * :py:meth:`set_priority() <cerebro.aclasses.Task.set_priority>` * :py:meth:`set_progress() <cerebro.aclasses.Task.set_progress>` * :py:meth:`set_start() <cerebro.aclasses.Task.set_start>` * :py:meth:`set_status() <cerebro.aclasses.Task.set_status>` * :py:meth:`spent() <cerebro.aclasses.Task.spent>` * :py:meth:`start() <cerebro.aclasses.Task.start>` * :py:meth:`status() <cerebro.aclasses.Task.status>` * :py:meth:`tags() <cerebro.aclasses.Task.tags>` :: task = cerebro.core.current_task() :: task = cerebro.core.task(task_id) :: tasks = cerebro.core.selected_tasks(task_id) """ PRIORITY_ = '' """ .. rubric:: Priority values """ PRIORITY_LOW = -2 """Low.""" PRIORITY_BELOW_NORMAL = -1 """Below normal.""" PRIORITY_NORMAL = 0 """Normal.""" PRIORITY_ABOVE_NORMAL = 1 """Above normal.""" PRIORITY_HIGH = 2 """High.""" PRIORITY_CRITICAL = 3 """Critical.""" FLAG_ = '' """ .. rubric:: Task flags """ FLAG_DELETED = 0 """The task has been deleted.""" FLAG_PERM_INHERIT_BLOCK = 1 """Inherited access rights to the task have been reset.""" FLAG_CLOSED = 2 """The task is closed.""" FLAG_TASK_AS_EVENT = 3 """The task is an event.""" FLAG_SUSPENED = 4 """The task suspended (paused).""" FLAG_FORUM_LOCKED = 5 """The task forum has been set read-only.""" FLAG_CLOSED_EFFECTIVE = 30 """The task is closed because an upper-level task is closed.""" FLAG_SUSPENED_EFFECTIVE = 31 """The task is suspended because an upper-level task is suspended.""" FLAG_HAS_CHILD = 32 """The task has subtasks.""" FLAG_HAS_MESSAGES = 33 """The task has messages in the Forum thread.""" FLAG_NEED_ANSWER = 34 """The task is pending reply (according to the access rights of the current user).""" FLAG_HAS_SUB_PERMS = 35 """The task has customized access rights""" FLAG_ASSIGNED = 38 """The current user is allocated to this task.""" FLAG_INTEREST = 39 """The current user follows the task.""" FLAG_LAST_EV_CLIENT_VIS = 44 """The last message in the task Forum is visible for clients.""" FLAG_LAST_EV_APPROVED = 45 """The last message in the task Forum is approved.""" FLAG_HAS_PLANNED = 56 """The task has its own planned time.""" FLAG_HAS_PROGRESS = 59 """The task has its own progress.""" FLAG_IS_REFERENCE = 61 """The task is reference.""" FLAG_HAS_REFERENCE = 62 """The task has reference.""" DATA_ = '' """ .. rubric:: Task tuple fields """ DATA_MTM = 0 """Time of data modification. Type - datetime.""" DATA_ID = 1 """Task ID.""" DATA_PARENT_ID = 2 """Parent task ID.""" DATA_NAME = 3 """Task name.""" DATA_PARENT_URL = 4 """Full path to the parent task. Example: /Test project/Scene 1/.""" DATA_ACTIVITY_NAME = 5 """Activity name.""" DATA_ACTIVITY_ID = 6 """Activity ID.""" DATA_SELF_USERS_DECLARED = 7 """Users' work time declared to sign off, minutes. Type - float.""" DATA_SELF_USERS_APPROVED = 8 """Users' work time confirmed to sign off, minutes. Type - float.""" DATA_CREATED = 9 """Time of the task creation. Type - datetime.""" DATA_PRIORITY = 10 """:py:const:`Priority <cerebro.aclasses.Task.PRIORITY_>`.""" DATA_PROGRESS = 11 """Progress. Type - float от 0.0 до 100.0.""" DATA_PLANNED = 12 """Task planned time, hours. Type - float.""" DATA_USERS_DECLARED = 13 """Users' work time declared to sign off on this task and its subtasks, hours. Type - float.""" DATA_USERS_APPROVED = 14 """Users' work time confirmed to sign off on this task and its subtasks, hours. Type - float.""" DATA_THUMBS = 15 """Hash sums of the file thumbnails. Type - string. The separator is ';'.""" DATA_FLAGS = 16 """:py:const:`Task flags <cerebro.aclasses.Task.FLAG_>`.""" DATA_MODERATOR_ID = 17 """The ID of the user who modified the task.""" DATA_CREATOR_ID = 18 """The ID of the user who created the task.""" DATA_MODIFIED = 19 """The time of data modification. Type - datetime.""" DATA_ALLOCATED = 20 """Users allocated to the task. Type - string. The separator is ';'.""" DATA_OFFSET = 21 """The gap between 01.01.2000 and the calculated task starting date, days. Type - float.""" DATA_DURATION = 22 """The calculated task duration, calendar days. Type - float.""" DATA_PROJECT_ID = 23 """The ID of the project, the task belongs to.""" DATA_PRIVILEGE = 24 """The current user's access rights to the task. Type - int.""" DATA_HUMAN_START = 25 """The gap between 01.01.2000 and the manually set up task starting date, days. Type - float.""" DATA_HUMAN_FINISH = 26 """The gap between 01.01.2000 and the manually set up task finishing date, days. Type - float.""" DATA_SELF_BUDGET = 27 """Amount budgeted for the task.""" DATA_SELF_SPENT = 28 """Amount of budget signed off the task.""" DATA_BUDGET = 29 """Amount budgeted for the task and its subtasks, subtotal.""" DATA_SPENT = 30 """Amount signed off the task and its subtasks, subtotal.""" DATA_RESOURCE_SELF_DECLARED = 31 """Material resource time to sign off - declared, minutes. Type - float.""" DATA_RESOURCE_SELF_APPROVED = 32 """Material resource time to sign off - confirmed, minutes. Type - float.""" DATA_RESOURCE_DECLARED = 33 """Material resource time to sign off, subtotal for the task and its subtasks - declared, hours. Type - float.""" DATA_RESOURCE_APPROVED = 34 """Material resource time to sign off, subtotal for the task and its subtasks - confirmed, hours. Type - float.""" DATA_STATUS_ID = 35 """Status ID.""" PAYMENT_ = '' """ .. rubric:: Payment tuple fields """ PAYMENT_MTM = 0 """Time of data modification. Type - datetime.""" PAYMENT_USER_ID = 1 """The ID of the user who signed the payment off.""" PAYMENT_ID = 2 """Payment ID.""" PAYMENT_TASK_ID = 3 """Task ID.""" PAYMENT_FLAGS = 4 """:py:const:`Payment flags <cerebro.aclasses.Task.PAYMENT__FLAG_>`.""" PAYMENT_MONEY = 5 """Payment amount, abstract currency units.""" PAYMENT_RECORD_TIME = 6 """Payment sign off time. Type - datetime.""" PAYMENT_COMMENT = 7 """Text comment on the payment.""" PAYMENT__FLAG_ = '' """ .. rubric:: Payment flags """ PAYMENT__FLAG_CANCEL = 1 """Payment canceled.""" ALLOCATED_ = '' """ .. rubric:: Allocated user tuple fields """ ALLOCATED_ID = 0 """User ID.""" ALLOCATED_NAME = 1 """User full name.""" ALLOCATED_FLAGS = 2 """User flags. :py:const:`User flags <cerebro.aclasses.Users.FLAG_>` are described in the class :py:class:`cerebro.aclasses.Users`.""" def __init__(self, task_id): self.__task_id = task_id
[docs] def id(self): """ :returns: task ID. :rtype: int (parameter_1, parameter_2) """ return self.__task_id
[docs] def parent_id(self): """ :returns: parent task ID. :rtype: int """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_PARENT_ID]
[docs] def project_id(self): """ :returns: ID of the project, the task belongs to. :rtype: int """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_PROJECT_ID]
[docs] def name(self): """ :returns: task name. :rtype: string .. seealso:: :py:meth:`set_name() <cerebro.aclasses.Task.set_name>`. """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_NAME]
[docs] def parent_url(self): """ :returns: full path to the parent task. Пример: '/Test project/Scene 1/'. :rtype: string """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_PARENT_URL]
[docs] def priority(self): """ :returns: :py:const:`priority <cerebro.aclasses.Task.PRIORITY_>` of the task. :rtype: int :: if task.priority() == task.PRIORITY_CRITICAL: cerebro.core.print_warning('A critical priority task', task.name()) .. seealso:: :py:meth:`set_priority() <cerebro.aclasses.Task.set_priority>`. """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_PRIORITY]
[docs] def activity(self): """ :returns: task activity type. '(0, '')' means that the task activity type is not set. :rtype: tuple(activity_id, activity_name) - a 2-field tuple: Activity ID, activity name. .. seealso:: :py:meth:`set_activity() <cerebro.aclasses.Task.set_activity>`. """ data = py_cerebro_classes.task_data(self.__task_id) act = (data[Task.DATA_ACTIVITY_ID], data[Task.DATA_ACTIVITY_NAME]) return act
[docs] def creation_time(self): """ :returns: time of task creation. :rtype: datetime """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_CREATED]
[docs] def modification_time(self): """ :returns: time of task modification. :rtype: datetime """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_MODIFIED]
[docs] def creator_id(self): """ :returns: task creator's ID. :rtype: int """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_CREATOR_ID]
[docs] def moderator_id(self): """ :returns: task modifier's ID. :rtype: int """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_MODERATOR_ID]
[docs] def flags(self): """ :returns: :py:const:`task flags <cerebro.aclasses.Task.FLAG_>`. :rtype: int :: if cerebro.core.has_flag(task.flags(), task.FLAG_FORUM_LOCKED): # checking if the Forum is locked read-only return .. seealso:: :py:meth:`set_flag() <cerebro.aclasses.Task.set_flag>`. """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_FLAGS]
[docs] def progress(self): """ :returns: task progress value, from 0.0 to 100.0. :rtype: float .. seealso:: :py:meth:`set_progress() <cerebro.aclasses.Task.set_progress>`. """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_PROGRESS]
[docs] def planned_time(self): """ :returns: task planned time, hours. :rtype: float .. seealso:: :py:meth:`set_planned_time() <cerebro.aclasses.Task.set_planned_time>`. """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_PLANNED]
[docs] def start(self): """ :returns: task start time. :rtype: datetime .. seealso:: :py:meth:`set_start() <cerebro.aclasses.Task.set_start>`. """ return py_cerebro_classes.task_start(self.__task_id)
[docs] def finish(self): """ :returns: task finish time. :rtype: datetime .. seealso:: :py:meth:`set_finish() <cerebro.aclasses.Task.set_finish>`. """ return py_cerebro_classes.task_stop(self.__task_id)
[docs] def budget(self): """ :returns: task budget, currency units. :rtype: float .. seealso:: :py:meth:`set_budget() <cerebro.aclasses.Task.set_budget>`. """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_BUDGET]
[docs] def spent(self): """ :returns: total amount of payments signed off the task budget. :rtype: float """ return py_cerebro_classes.task_data(self.__task_id)[Task.DATA_SPENT]
[docs] def payments(self): """ :returns: a list of :py:const:`tuples on payments <cerebro.aclasses.Task.PAYMENT_>` on the task. :rtype: list(tuple,) Example: checking if a payment was canceled:: for pay in task.payments(): if pay[task.PAYMENT_MONEY] > 1000 and cerebro.core.has_flag(pay[task.PAYMENT_FLAGS], task.PAYMENT__FLAG_CANCEL)==True: cerebro.core.print_warning('Payment of more than 1000 was canceled', task.name()) """ return py_cerebro_classes.task_payments(self.__task_id)
[docs] def allocated(self): """ :returns: a list of :py:const:`tuples on users<cerebro.aclasses.Task.ALLOCATED_>` allocated to the task. :rtype: list(tuple,) Example: defining if a material resource was allocated to the task:: for user in task.allocated(): if cerebro.aclasses.Users.is_resource(user[task.ALLOCATED_FLAGS]) == True: print('The resource was allocated to the task:', user[task.ALLOCATED_NAME]) .. seealso:: :py:meth:`set_allocated() <cerebro.aclasses.Task.set_allocated>`, :py:meth:`remove_allocated() <cerebro.aclasses.Task.remove_allocated>`. """ return py_cerebro_classes.task_allocated(self.__task_id)
[docs] def status(self): """ :returns: Task status. '(0,'')' means that task status is not set. :rtype: tuple(status_id, status_name) - a 2-field tuple: status ID, status name. .. seealso:: :py:meth:`set_status() <cerebro.aclasses.Task.set_status>`, :py:meth:`possible_statuses() <cerebro.aclasses.Task.possible_statuses>`. """ return py_cerebro_classes.task_status(self.__task_id)
[docs] def hashtags(self): """ :returns: a list of hashtags to the task. :rtype: list(string,) Example: printing hashtags:: for ht in task.hashtags(): print('Hashtag:', ht) .. seealso:: :py:meth:`add_hashtags() <cerebro.aclasses.Task.add_hashtags>`, :py:meth:`remove_hashtags() <cerebro.aclasses.Task.remove_hashtags>`. """ return py_cerebro_classes.task_hashtags(self.__task_id)
[docs] def set_status(self, status_id): """ :param int status_id: status ID. Sets a task status. '0' sets the task status to 'No status'. Example: setting 'closed' status:: statuses = cerebro.core.statuses() for status in statuses.data(): if status[statuses.DATA_NAME] == 'closed': task.set_status(status[statuses.DATA_ID]) break .. seealso:: :py:meth:`status() <cerebro.aclasses.Task.status>`, :py:meth:`possible_statuses() <cerebro.aclasses.Task.possible_statuses>`. """ py_cerebro_classes.task_set_status(self.__task_id, status_id)
[docs] def possible_statuses(self): """ :returns: a list of :py:const:`tuples on statuses <cerebro.aclasses.Statuses.DATA_>`, which can be set for the task. :rtype: list(tuple,) In the Cerebro system for each status, permissions for switching each status are set. In addition, each status has a flag of inheritance. On the task-containers you can set only the statuses that have this flag enabled. Therefore, the list of possible statuses depends on user rights, the current status, as well as the presence / lack of sub-tasks in the task. Example of determining the possibility to set 'completed' status for the task:: possible_statuses = task.possible_statuses() for status in possible_statuses: if status[cerebro.aclasses.Statuses.DATA_NAME] == 'completed': task.set_status(status[cerebro.aclasses.Statuses.DATA_ID]) break .. seealso:: :py:meth:`status() <cerebro.aclasses.Task.status>`, :py:meth:`set_status() <cerebro.aclasses.Task.set_status>`, :py:class:`cerebro.aclasses.Statuses`. """ return py_cerebro_classes.task_possible_statuses(self.__task_id)
[docs] def tags(self): """ :returns: task tag list. :rtype: list(:py:class:`cerebro.aclasses.Tag`,) """ tgs = list() ids = py_cerebro_classes.task_tag_ids(self.__task_id) if ids != None: for id in ids: tgs.append(Tag(self.__task_id, id)) return tgs
[docs] def data(self): """ :returns: :py:const:`tuple on the task <cerebro.aclasses.Task.DATA_>`. :rtype: tuple Actually, the most part of the methods of this class are interfaces to this tuple. Therefore, you can use its data directly from the tuple. :: task.creator_id() == task.data()[task.DATA_CREATOR_ID] task.priority() == task.data()[task.DATA_PRIORITY] # и так далее """ return py_cerebro_classes.task_data(self.__task_id)
[docs] def set_name(self, name): """ :param string name: task name. Sets a new name for a task. .. warning:: Task name MAY NOT contain the following symbols: \ / # : ? & ' " , + | .. seealso:: :py:meth:`name() <cerebro.aclasses.Task.name>`. """ py_cerebro_classes.task_set_name(self.__task_id, name)
[docs] def set_activity(self, activity_id): """ :param int activity_id: Activity type ID. Sets an activity type for a task. '0' sets the task activity type to 'No activity'. Example: setting 'animation' activity type:: activities = cerebro.core.activities() for activity in activities.data(): if activity[activities.DATA_NAME] == 'animation': task.set_activity(activity[activities.DATA_ID]) break .. seealso:: :py:meth:`activity() <cerebro.aclasses.Task.activity>`. """ py_cerebro_classes.task_set_activity(self.__task_id, activity_id)
[docs] def set_priority(self, prior): """ :param int prior: task priority. Sets :py:const:`task priority <cerebro.aclasses.Task.PRIORITY_>`. :: task.set_priority(task.PRIORITY_HIGHT) .. seealso:: :py:meth:`priority() <cerebro.aclasses.Task.priority>`. """ py_cerebro_classes.task_set_priority(self.__task_id, prior)
[docs] def set_flag(self, flag, is_set): """ :param int flag: :py:const:`task flag <cerebro.aclasses.Task.FLAG_>`. :param bool is_set: selection of an action. Sets :py:const:`task flag <cerebro.aclasses.Task.FLAG_>`. If 'is_set' is True, the flag sets on, otherwise - sets off. :: # Setting a 'Closed' status to a task task.set_flag(task.FLAG_CLOSED, True) .. seealso:: :py:meth:`flags() <cerebro.aclasses.Task.flags>`. """ py_cerebro_classes.task_set_flag(self.__task_id, flag, is_set)
[docs] def set_progress(self, progress): """ :param float progress: task progress value, from 0.0 to 100.0. Sets task progress value. If set to 100, the task is considered fulfilled(Done). 'None' value resets the user-defined task progress value. After that the task progress starts to derive from the subtasks' progress values. .. seealso:: :py:meth:`progress() <cerebro.aclasses.Task.progress>`. """ if progress == None: py_cerebro_classes.task_set_progress(self.__task_id, -2) else: py_cerebro_classes.task_set_progress(self.__task_id, progress)
[docs] def set_planned_time(self, hours): """ :param float hours: task planned work hours. Sets the planned time for a task, hours. 'None' value resets the user-defined planned time. After that the planned time starts to derive from the task start/finish dates and a working schedule. .. seealso:: :py:meth:`planned_time() <cerebro.aclasses.Task.planned_time>`. """ if hours == None: py_cerebro_classes.task_set_planned_time(self.__task_id, -2) else: py_cerebro_classes.task_set_planned_time(self.__task_id, hours)
[docs] def set_start(self, time): """ :param float time: time period from 01.01.2000, days. Sets the task start time, days from 01.01.2000, UTC. :: task.set_start(4506.375) # start time is May 03, 2012 9:00 UTC 'None' value resets the user-defined task start time. After that the start time is derived from the task's predecessors' start time and the actual working time schedule. Example: setting task start time equal to the current time:: import datetime datetime_now = datetime.datetime.utcnow() datetime_2000 = datetime.datetime(2000, 1, 1) timedelta = datetime_now - datetime_2000 days = timedelta.total_seconds()/(24*60*60) task.set_start(days) .. seealso:: :py:meth:`start() <cerebro.aclasses.Task.start>`. """ if time == None: py_cerebro_classes.task_set_start(self.__task_id, -2) else: py_cerebro_classes.task_set_start(self.__task_id, time)
[docs] def set_finish(self, time): """ :param float time: time period from 01.01.2000, days. Sets task finish time, days from 01.01.2000, UTC. :: task.set_finish(4506.75) # task finish time is May 03, 2012 18:00 UTC 'None' value resets the user-defined task finish time. After that the task finish time derives from the task planned time and the actual working time schedule. Example: setting task finish time 3 days later from the actual moment:: import datetime datetime_now = datetime.datetime.utcnow() datetime_2000 = datetime.datetime(2000, 1, 1) timedelta = datetime_now - datetime_2000 days = timedelta.total_seconds()/(24*60*60) + 3 task.set_finish(days) .. seealso:: :py:meth:`finish() <cerebro.aclasses.Task.finish>`. """ if time == None: py_cerebro_classes.task_set_finish(self.__task_id, -2) else: py_cerebro_classes.task_set_finish(self.__task_id, time)
[docs] def set_budget(self, budget): """ :param float budget: in currency units. Sets the task budget amount. 'None' resets the user-defined budget amount. After that the task budget sets equal to the total amounts of its subtasks. .. seealso:: :py:meth:`budget() <cerebro.aclasses.Task.budget>`. """ if budget == None: py_cerebro_classes.task_drop_budget(self.__task_id) else: py_cerebro_classes.task_set_budget(self.__task_id, budget)
[docs] def set_allocated(self, user_id): """ :param int user_id: user ID. Allocates a user to the task. Example: allocating all workforce (users except material resources) to the task:: users = cerebro.core.users() for user in users.data(): if cerebro.aclasses.Users.is_resource(user[users.DATA_FLAGS]) != True: task.set_allocated(user[users.DATA_ID]) .. seealso:: :py:meth:`allocated() <cerebro.aclasses.Task.allocated>`, :py:meth:`remove_allocated() <cerebro.aclasses.Task.remove_allocated>`. """ py_cerebro_classes.task_set_allocated(self.__task_id, user_id)
[docs] def remove_allocated(self, user_id): """ :param int user_id: user ID. Dismisses a user from the task. Example: getting material resources off the task:: allocated = task.allocated() for user in allocated: if cerebro.aclasses.Users.is_resource(user[task.ALLOCATED_FLAGS]) == True: task.remove_allocated(user[task.ALLOCATED_ID]) .. seealso:: :py:meth:`set_allocated() <cerebro.aclasses.Task.set_allocated>`, :py:meth:`allocated() <cerebro.aclasses.Task.allocated>`. """ py_cerebro_classes.task_remove_allocated(self.__task_id, user_id)
[docs] def add_hashtags(self, hashtags): """ :param hashtags: hashtag or array of hashtags (every hashtag should be written in one word without spaces). :type hashtags: string, set(string, ) or list(string, ) Adds hashtags to the task. .. seealso:: :py:meth:`hashtags() <cerebro.aclasses.Task.hashtags>`, :py:meth:`remove_hashtags() <cerebro.aclasses.Task.remove_hashtags>`. """ py_cerebro_classes.task_add_hashtags(self.__task_id, get_val_by_type(hashtags))
[docs] def remove_hashtags(self, hashtags): """ :param hashtags: hashtag or array of hashtags (every hashtag should be written in one word without spaces). :type hashtags: string, set(string, ) or list(string, ) Remove hashtags from the task. .. seealso:: :py:meth:`hashtags() <cerebro.aclasses.Task.hashtags>`, :py:meth:`add_hashtags() <cerebro.aclasses.Task.add_hashtags>`. """ py_cerebro_classes.task_remove_hashtags(self.__task_id, get_val_by_type(hashtags))
[docs]class Perm: """ Access rights class. Some actions with Cerebro objects, whether it is creating, modifying task/message properties or creating projects/users, require appropriate permissions. The action types that require permissions are described below. Use the functions of the :py:mod:`cerebro.core` module to check the permissions: * :py:func:`cerebro.core.has_perm_global` * :py:func:`cerebro.core.has_perm_message` * :py:func:`cerebro.core.has_perm_task` """ PERM_TASK_ = '' """ .. rubric:: Access rights to the task """ PERM_TASK_MANAGMENT = 6 """Task management. Allows to create/delete tasks.""" PERM_TASK_PROPERTIES = 8 """Task properties change. Allows to edit almost all task properties except tags and budget.""" PERM_TASK_TAG = 14 """Task tags edit. Allows to edit task tags.""" PERM_TASK_BUDGET = 30 """Task budget edit. Allows to edit task budget.""" PERM_TASK_PROGRESS = 32 """Task progress edit. Allows to alter task progress, except setting it to 100%.""" PERM_TASK_CREATE_DEFINITION = 18 """Defifnitions creation. Allows to create messages of the 'Definition' type.""" PERM_TASK_CREATE_REVIEW = 22 """Reviews creation. Allows to create messages of the 'Review' type.""" PERM_TASK_CREATE_REPORT = 20 """Reports creation. Allows to create messages of the 'Report' and 'Resource Report' types.""" PERM_TASK_CREATE_NOTE = 24 """Notes creation. Allows to create messages of the 'Note' type.""" PERM_TASK_CREATE_CLIENT_REVIEW = 26 """Client reviews creation. Allows to create messages of the 'Client review' type.""" PERM_TASK_MESSAGES_PROPERTIES = 16 """Message properties edit. Allows to edit such message properties as 'Visible for clients' and 'Report approved'.""" PERM_TASK_LAST_MESSAGE = 34 """Last message edit. Allows to edit unreplied messages by other users.""" PERM_TASK_ANY_MESSAGE = 10 """Any message edit. Allows to edit all messages.""" PERM_MESSAGE_ = '' """ .. rubric:: Access rights to the message """ PERM_MESSAGE_EDITABLE = 3 """Allows to edit message text and attachments. Also, allows to delete the message.""" PERM_MESSAGE_PROPERTIES = 16 """Allows to edit such message properties as 'Visible for clients' and 'Report approved'.""" PERM_GLOBAL_ = '' """ .. rubric:: Global access rights """ PERM_GLOBAL_USERS = 62 """User account management. Allows to create users, groups, roles and adjust the 'Who sees whom' settings.""" PERM_GLOBAL_MATERIAL_RESOURCES = 56 """Material resource management. Allows to create/delete material resources.""" PERM_GLOBAL_SALARIES_AND_WORKING_SCHEDULES = 59 """Schedule and salary management. Allows to set users' man hour rates and working time schedules.""" PERM_GLOBAL_TAGS_AND_ACTIVITIES = 61 """Tags and activities management. Allows to create/delete tags and activity types.""" PERM_GLOBAL_FILE_STORAGES = 60 """File storage management. Allows to allocate available file storages for project data.""" def __init__(self): pass