# -*- coding: utf-8 -*-
"""
The cerebro.events module contains descriptions of event classes and types,
which are passed into the functions of :ref:`event handling module<capi-event>`.
The event types are described in the :py:const:`Event event base class <cerebro.events.Event.EVENT_>`.
.. rubric:: Classes
* :py:class:`cerebro.events.AfterEventChangingOfAttachments`
* :py:class:`cerebro.events.AfterEventChangingOfMessage`
* :py:class:`cerebro.events.AfterEventChangingOfMessages`
* :py:class:`cerebro.events.AfterEventChangingOfTasks`
* :py:class:`cerebro.events.AfterEventChangingOfTasksTag`
* :py:class:`cerebro.events.AfterEventCreationOfMessage`
* :py:class:`cerebro.events.AfterEventCreationOfTask`
* :py:class:`cerebro.events.AfterEventMessage`
* :py:class:`cerebro.events.BeforeEventChangingOfAttachments`
* :py:class:`cerebro.events.BeforeEventChangingOfAttachmentsHashtags`
* :py:class:`cerebro.events.BeforeEventChangingOfMessage`
* :py:class:`cerebro.events.BeforeEventChangingOfMessages`
* :py:class:`cerebro.events.BeforeEventChangingOfMessagesHashtags`
* :py:class:`cerebro.events.BeforeEventChangingOfTasks`
* :py:class:`cerebro.events.BeforeEventChangingOfTasksAllocated`
* :py:class:`cerebro.events.BeforeEventChangingOfTasksHashtags`
* :py:class:`cerebro.events.BeforeEventChangingOfTasksTag`
* :py:class:`cerebro.events.BeforeEventCreationOfMessage`
* :py:class:`cerebro.events.BeforeEventCreationOfTask`
* :py:class:`cerebro.events.BeforeEventMessage`
* :py:class:`cerebro.events.Event`
* :py:class:`cerebro.events.EventChangingOfAttachments`
* :py:class:`cerebro.events.EventChangingOfMessages`
* :py:class:`cerebro.events.EventChangingOfTasks`
* :py:class:`cerebro.events.EventError`
* :py:class:`cerebro.events.TestEvent`
"""
import py_cerebro_classes
import cerebro
def get_val_by_type(val_id):
if type(val_id) == list:
return val_id
else:
ids = list()
ids.append(val_id)
return ids
class TypeEvent:
#Event type class. For inner use.
def __init__(self, type, id):
self.type = type
self.id = id
[docs]class Event:
"""
Event base class.
All event classes are inhereited from this one.
.. rubric:: Methods
* :py:meth:`event_type() <cerebro.events.Event.event_type>`
* :py:meth:`type_str() <cerebro.events.Event.type_str>`
"""
EVENT_ = ''
"""
.. rubric:: Event types
"""
EVENT_TEST =0
"""
Test event. It is generated by pressing the :ref:`test event generation <capi_test_btn>` button.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`Event <cerebro.events.Event>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`Event <cerebro.events.Event>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`Event <cerebro.events.Event>`)
"""
EVENT_CREATION_OF_MESSAGE =1
"""
The message creation event. It is generated by pressing the "Send" button in the message creation interface.
.. note::
The event is generated only when a message is being created.
The messages copied (cut) and then being pasted from other forum threads
will call other events, that we're going to develop in future.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventCreationOfMessage <cerebro.events.BeforeEventCreationOfMessage>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventCreationOfMessage <cerebro.events.AfterEventCreationOfMessage>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventCreationOfMessage <cerebro.events.BeforeEventCreationOfMessage>`)
"""
EVENT_CHANGING_OF_MESSAGE =10
"""
The message editing event. It is generated in the message editing interface.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfMessage <cerebro.events.BeforeEventChangingOfMessage>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfMessage <cerebro.events.AfterEventChangingOfMessage>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfMessage <cerebro.events.BeforeEventChangingOfMessage>`)
"""
EVENT_CHANGING_OF_MESSAGE_HASHTAGS =12
"""
The message hashtags editing event. It is generated by editing hashtags of messages in the Forum interface.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfMessagesHashtags <cerebro.events.BeforeEventChangingOfMessageHashtags>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfMessagesHashtags <cerebro.events.BeforeEventChangingOfMessagesHashtags>`)
"""
EVENT_CHANGING_OF_MESSAGE_APPROVED =13
"""
The message approved editing event. It is generated by editing appruved of messages.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfMessages <cerebro.events.BeforeEventChangingOfMessages>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfMessages <cerebro.events.BeforeEventChangingOfMessages>`)
"""
EVENT_CHANGING_OF_MESSAGE_CLIENT_VISIBLE =14
"""
The message client visible event.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfMessages <cerebro.events.BeforeEventChangingOfMessages>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfMessages <cerebro.events.BeforeEventChangingOfMessages>`)
"""
EVENT_CREATION_OF_TASK =100
"""
The new task creation event. It is generated by pressing the "Send" button in the task creation interface.
On creation of a new task, a new message of the "Definition" type is being created,
so the task creation event handles the creation of this message as well.
.. note::
The event is generated only when a new task is being created by pressing the "Send" button.
The tasks being created by other means (duplicated, pasted, created by file(s) drag-n-drop)
will call other events, that we're going to develop in future.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventCreationOfTask <cerebro.events.BeforeEventCreationOfTask>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventCreationOfTask <cerebro.events.AfterEventCreationOfTask>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventCreationOfTask <cerebro.events.BeforeEventCreationOfTask>`)
"""
EVENT_CHANGING_OF_TASKS_NAME =110
"""
The task name changing event. It is generated by changing a task name in the table or in the Task Properties window.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
"""
EVENT_CHANGING_OF_TASKS_ACTIVITY =111
"""
The task activity changing event. It is generated by changing the activity attribute in the table or in the Task Properties window.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
"""
EVENT_CHANGING_OF_TASKS_PRIORITY =112
"""
The task priority changing event. It is generated by changing the task priority in the table or in the Task Properties window.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
"""
EVENT_CHANGING_OF_TASKS_PROGRESS =113
"""
The task progress changing event. It is generated by changing the task progress in the table or in the Task Properties window or by pressing the "Mark the task Done" button.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
"""
EVENT_CHANGING_OF_TASKS_PLANNED_TIME =114
"""
The event of changing of the estimated time to complete a task. It is generated by changing the estimated time in the table or in the Task Properties window.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
"""
EVENT_CHANGING_OF_TASKS_START =115
"""
The event of task starting point change. It is generated by changing the start time in the table or in the Task Properties window, or in the Gantt chart.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
"""
EVENT_CHANGING_OF_TASKS_FINISH =116
"""
The event of task finishing point change. It is generated by changing the finish time in the table or in the Task Properties window, or in the Gantt chart.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
"""
EVENT_CHANGING_OF_TASKS_BUDGET =117
"""
The task budget changing event. It is generated by changing the budget amount in the table or in the Task Properties window.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
"""
EVENT_CHANGING_OF_TASKS_ALLOCATED =118
"""
The event of allocating/dismissing users/resources to/from tasks. It is generated by changing the list of allocated users/resources in the table or in the Task Properties window.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasksAllocated <cerebro.events.BeforeEventChangingOfTasksAllocated>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasksAllocated <cerebro.events.BeforeEventChangingOfTasksAllocated>`)
"""
EVENT_CHANGING_OF_TASKS_FLAG =119
EVENT_CHANGING_OF_TASKS_PAYMENT =120
EVENT_CHANGING_OF_TASKS_TAG =121
"""
The task tag changing event. It is generated by changing tag values in the table or in the Task Properties window.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasksTag <cerebro.events.BeforeEventChangingOfTasksTag>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasksTag <cerebro.events.AfterEventChangingOfTasksTag>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasksTag <cerebro.events.BeforeEventChangingOfTasksTag>`)
"""
EVENT_CHANGING_OF_TASKS_LINK =122
EVENT_CHANGING_OF_TASKS_STATUS =123
"""
The task status changing event. It is generated by changing the task status in the table or in the Task Properties window or in the task forum.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
* def :py:func:`after_event <event.after_event>` (:py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`)
"""
EVENT_CHANGING_OF_TASKS_HASHTAGS =124
"""
The task hashtags changing event. It is generated by changing the task hashtags in the table or in the Task Properties window.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfTasksHashtags <cerebro.events.BeforeEventChangingOfTasksHashtags>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfTasksHashtags <cerebro.events.BeforeEventChangingOfTasksHashtags>`)
"""
EVENT_CHANGING_OF_ATTACHMENT_HASHTAGS =1010
"""
The attachment hashtags changing event. It is generated by changing the attachment hashtags in the table or in the Attachment Edit hashtags window.
The objects being input into the event functions:
* def :py:func:`before_event <event.before_event>` (:py:class:`BeforeEventChangingOfAttachmentsHashtags <cerebro.events.BeforeEventChangingOfAttachmentHashtags>`)
* def :py:func:`error_event <event.error_event>` (:py:class:`EventError <cerebro.events.EventError>`,
:py:class:`BeforeEventChangingOfAttachmentsHashtags <cerebro.events.BeforeEventChangingOfAttachmentsHashtags>`)
"""
EVENT_MANAGE_OF_TASK_REFERENCE =1100
def __init__(self, event_type, event_id):
self.__event = TypeEvent(event_type, event_id)
[docs] def event_type(self):
"""
:returns: :py:const:`event type <cerebro.events.Event.EVENT_>`.
:rtype: int
"""
return self.__event.type;
[docs] def type_str(self):
"""
:returns: string name of the event type.
:rtype: string
"""
if self.__event.type == Event.EVENT_TEST:
return 'EVENT_TEST'
elif self.__event.type == Event.EVENT_CREATION_OF_MESSAGE:
return 'EVENT_CREATION_OF_MESSAGE'
elif self.__event.type == Event.EVENT_CHANGING_OF_MESSAGE:
return 'EVENT_CHANGING_OF_MESSAGE'
elif self.__event.type == Event.EVENT_CHANGING_OF_MESSAGE_APPROVED:
return 'EVENT_CHANGING_OF_MESSAGE_APPROVED'
elif self.__event.type == Event.EVENT_CHANGING_OF_MESSAGE_CLIENT_VISIBLE:
return 'EVENT_CHANGING_OF_MESSAGE_CLIENT_VISIBLE'
elif self.__event.type == Event.EVENT_CREATION_OF_TASK:
return 'EVENT_CREATION_OF_TASK'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_NAME:
return 'EVENT_CHANGING_OF_TASKS_NAME'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_ACTIVITY:
return 'EVENT_CHANGING_OF_TASKS_ACTIVITY'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_PRIORITY:
return 'EVENT_CHANGING_OF_TASKS_PRIORITY'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_PROGRESS:
return 'EVENT_CHANGING_OF_TASKS_PROGRESS'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_PLANNED_TIME:
return 'EVENT_CHANGING_OF_TASKS_PLANNED_TIME'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_START:
return 'EVENT_CHANGING_OF_TASKS_START'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_FINISH:
return 'EVENT_CHANGING_OF_TASKS_FINISH'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_BUDGET:
return 'EVENT_CHANGING_OF_TASKS_BUDGET'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_ALLOCATED:
return 'EVENT_CHANGING_OF_TASKS_ALLOCATED'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_FLAG:
return 'EVENT_CHANGING_OF_TASKS_FLAG'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_PAYMENT:
return 'EVENT_CHANGING_OF_TASKS_PAYMENT'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_TAG:
return 'EVENT_CHANGING_OF_TASKS_TAG'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_LINK:
return 'EVENT_CHANGING_OF_TASKS_LINK'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_STATUS:
return 'EVENT_CHANGING_OF_TASKS_STATUS'
elif self.__event.type == Event.EVENT_CHANGING_OF_MESSAGE_HASHTAGS:
return 'EVENT_CHANGING_OF_MESSAGE_HASHTAGS'
elif self.__event.type == Event.EVENT_CHANGING_OF_TASKS_HASHTAGS:
return 'EVENT_CHANGING_OF_TASKS_HASHTAGS'
elif self.__event.type == Event.EVENT_CHANGING_OF_ATTACHMENT_HASHTAGS:
return 'EVENT_CHANGING_OF_ATTACHMENT_HASHTAGS'
[docs]class EventError:
"""
The event error class.
It has two attributes:
* code (int) - error code
* text (string) - error text
It is input into the "error_event" function of the "event" module.
::
def error_event(error, event):
print(error)
print(error.code)
print(error.text)
"""
def __init__(self, code, text):
self.code = code
self.text = text
def __repr__(self):
return "Error_event({0.text!r}. {0.code!r})".format(self)
def __str__(self):
return "Error code {0.code}: {0.text}".format(self)
[docs]class TestEvent(Event):
"""
The test event class.
.. rubric:: Methods
* :py:class:`base class methods cerebro.events.Event <cerebro.events.Event>`
The test event is called by pressing the :ref:`Call test event <capi_test_btn>` button on the Python debugging panel.
This event is used to check if the event algorythm works properly.
The class object is input into the :py:func:`before_event <event.before_event>`,
:py:func:`after_event <event.after_event>`,
and :py:func:`error_event <event.error_event>` functions
of the :ref:`event <capi-event>` module.
::
def after_event(event):
if event.event_type() == event.EVENT_TEST:
print('Test event is successful')
"""
def __init__(self, event_type, event_id):
Event.__init__(self, event_type, event_id)
[docs]class BeforeEventMessage(Event, cerebro.aclasses.AbstractMessage):
"""
The base class for the message creation/change events.
It grants access to the data of the message being created/changed before the data is written to the database.
.. rubric:: Methods
* :py:meth:`add_attachment() <cerebro.events.BeforeEventMessage.add_attachment>`
* :py:meth:`add_attachment_as_link() <cerebro.events.BeforeEventMessage.add_attachment_as_link>`
* :py:meth:`new_attachments() <cerebro.events.BeforeEventMessage.new_attachments>`
* :py:meth:`new_task_status() <cerebro.events.BeforeEventMessage.new_task_status>`
* :py:meth:`resources() <cerebro.events.BeforeEventMessage.resources>`
* :py:meth:`set_approved() <cerebro.events.BeforeEventMessage.set_approved>`
* :py:meth:`set_client_visible() <cerebro.events.BeforeEventMessage.set_client_visible>`
* :py:meth:`set_html_text() <cerebro.events.BeforeEventMessage.set_html_text>`
* :py:meth:`set_new_task_status() <cerebro.events.BeforeEventMessage.set_new_task_status>`
* :py:meth:`set_work_time() <cerebro.events.BeforeEventMessage.set_work_time>`
* :py:class:`Methods of the base class cerebro.aclasses.AbstractMessage <cerebro.aclasses.AbstractMessage>`
* :py:class:`Methods of the base class cerebro.events.Event <cerebro.events.Event>`
.. seealso:: :py:class:`AfterEventMessage <cerebro.events.AfterEventMessage>`.
"""
def __init__(self, event_type, event_id):
Event.__init__(self, event_type, event_id)
cerebro.aclasses.AbstractMessage.__init__(self, event_id, -2)
[docs] def resources(self):
"""
:returns: the list of resources being reported for.
:rtype: list(tuple,) - [(resource_id, resource_name),] - a list of tuples consisting of two fields: a resource ID and a resource name.
Resources are available in the :py:const:`"Resource Report" type <cerebro.aclasses.AbstractMessage.TYPE_RESOURCE_REPORT>` only.
If the :py:const:`message type <cerebro.aclasses.AbstractMessage.TYPE_>` is not the "Resource Report", "None" is being returned.
::
if event.type() == event.TYPE_RESOURCE_REPORT:
print('resources()', event.resources())
"""
return py_cerebro_classes.message_resources(self._Event__event.id)
[docs] def new_attachments(self):
"""
:returns: a list of new attchments to the message.
:rtype: list(:py:class:`cerebro.aclasses.NewAttachment`,)
"""
attachs = list()
ids = py_cerebro_classes.message_attach_ids(self._Event__event.id, self._AbstractMessage__message_id)
if ids != None:
for id in ids:
attachs.append(cerebro.aclasses.NewAttachment(self._Event__event.id, self._AbstractMessage__message_id, id))
return attachs
[docs] def add_attachment(self, file_path, comment = '', name= '', hashtags = None):
"""
:param string file_path: file path.
:param string comment: text comment.
:param string name: attachment name. If the name is not specified, the file name is taken.
: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 the attachment to the message.
::
def before_event(event):
evtype = event.event_type()
if evtype == event.EVENT_CREATION_OF_MESSAGE or evtype == event.EVENT_CHANGING_OF_MESSAGE:
file_path = cerebro.core.python_api_dir() + '/examples/icon.png'
event.add_attachment(file_path, 'Added with Cerebro Python API')
.. seealso:: :py:meth:`add_attachment_as_link() <cerebro.events.BeforeEventMessage.add_attachment_as_link>`.
"""
py_cerebro_classes.message_add_attach(self._Event__event.id, False, file_path, name, comment, get_val_by_type(hashtags))
[docs] def add_attachment_as_link(self, file_path, comment = '', hashtags = None):
"""
:param string file_path: file path.
:param string comment: text comment.
: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, )
It adds an attachment as a link. The attachment itself is not being copied to the Cargador file storage.
The file_path stands for the attachment name in this case.
.. seealso:: :py:meth:`add_attachment() <cerebro.events.BeforeEventMessage.add_attachment>`.
"""
py_cerebro_classes.message_add_attach(self._Event__event.id, True, file_path, str(), comment, get_val_by_type(hashtags))
[docs] def set_html_text(self, text):
"""
:param string text: html-formatted or unformatted text.
Sets a new message text.
"""
py_cerebro_classes.message_set_html_text(self._Event__event.id, text)
[docs] def set_client_visible(self, is_visible):
"""
:param bool is_visible: If the value is True, the message is marked as visible for clients, otherwise it is invisible for clients.
Defines if the message may be seen or not by the clients.
::
def before_event(event):
evtype = event.event_type()
if evtype == event.EVENT_CREATION_OF_MESSAGE:
event.set_client_visible(True)
"""
py_cerebro_classes.message_set_client_visible(self._Event__event.id, is_visible)
[docs] def set_work_time(self, minutes):
"""
:param float minutes: time (minutes).
Sets the amount of the working time, signed off by the message, to be indicated to clients.
If the type of the message is :py:const:`"Report" <cerebro.aclasses.AbstractMessage.TYPE_REPORT>`
or :py:const:`"Resource Report" <cerebro.aclasses.AbstractMessage.TYPE_RESOURCE_REPORT>`,
it indicates the time signed off (declared by the current message author).
If the type of the message is :py:const:`"Review" <cerebro.aclasses.AbstractMessage.TYPE_REVIEW>`,
it indicates the time signed off and approved for the previous Report.
For all the rest of the message types it is absurd to set working time.
::
if event.type() == event.TYPE_REPORT:
if event.work_time() > 60000: # if a user tries to sign off more than 1000 hours for the Report
raise Exception('This is too much, isn't it?') # an exception is being raised (the user will be displayed this message)
else event.work_time() < 60: # if the user tries to sign off less than 1 hour
event.set_work_time(60) # we're setting 1 hour (60 minutes) anyway
"""
py_cerebro_classes.message_set_work_time(self._Event__event.id, minutes)
[docs] def set_approved(self, is_approved):
"""
:param bool is_approved: If its value is True, the Report is being marked 'Approved', otherwise the 'Approved' is cleared.
Sets the 'Approved' flag for a Report.
The 'Approved' flag means that, the declared working time to sign off is approved. The GUI marks the message with a green check mark.
This flag makes sense only for the :py:const:`"Report" <cerebro.aclasses.AbstractMessage.TYPE_REPORT>`
or :py:const:`"Resource Report" <cerebro.aclasses.AbstractMessage.TYPE_RESOURCE_REPORT>` message types.
::
if event.type() == event.TYPE_RESOURCE_REPORT:
event.set_approved(True)
"""
py_cerebro_classes.message_set_approved(self._Event__event.id, is_approved)
[docs] def new_task_status(self):
"""
:returns: the new status of the task, which the user sets when creating / editing a message.
'(0, '')' means, that the user sets the task status into 'No Status'.
:rtype: tuple(status_id, status_name) - a list of tuples consisting of two fields: a status ID and a status name.
In the graphical interface of creating / editing the message, you can choose the status in which the task will go after the message is sent.
If the user does not change the status, the new status will be equal to :py:meth:'the current task status <cerebro.aclasses.Task.status>'.
.. seealso:: :py:meth:`set_new_task_status() <cerebro.events.BeforeEventMessage.set_new_task_status>`.
"""
mdata = py_cerebro_classes.message_data(self._AbstractMessage__event_id, self._AbstractMessage__message_id)
return (mdata[cerebro.aclasses.AbstractMessage.DATA_STATUS_ID], mdata[cerebro.aclasses.AbstractMessage.DATA_STATUS_NAME])
[docs] def set_new_task_status(self, status_id):
"""
:param int status_id: status ID.
Sets a new status, in which the task will go after the message is sent. '0’ translates the task status into' No Status'.
::
# If a report is written and the new status is not equal to 'pending review',
# then setting this status
if event.type() == event.TYPE_REPORT and event.new_task_status()[1] != 'pending review':
task = cerebro.core.task(event.task_id())
possible_statuses = task.possible_statuses()
for status in possible_statuses:
if status[cerebro.aclasses.Statuses.DATA_NAME] == 'pending review': # Verify that the user can switch to the status
event.set_new_task_status(status[cerebro.aclasses.Statuses.DATA_ID])
break
.. seealso:: :py:meth:`new_task_status() <cerebro.events.BeforeEventMessage.new_task_status>`.
"""
return py_cerebro_classes.message_set_new_status(self._Event__event.id, status_id)
[docs]class AfterEventMessage(Event, cerebro.aclasses.Message):
"""
The base class for the task creation/change event.
It grants access to the data of a created/modified message after it is written into the database.
.. rubric:: Methods
* :py:meth:`new_attachments() <cerebro.events.AfterEventMessage.new_attachments>`
* :py:meth:`resources() <cerebro.events.AfterEventMessage.resources>`
* :py:class:`methods of the base class cerebro.aclasses.Message <cerebro.aclasses.Message>`
* :py:class:`methods of the base class cerebro.events.Event <cerebro.events.Event>`
.. seealso:: :py:class:`BeforeEventMessage <cerebro.events.BeforeEventMessage>`.
"""
def __init__(self, event_type, event_id):
Event.__init__(self, event_type, event_id)
cerebro.aclasses.Message.__init__(self, py_cerebro_classes.event_message_id(event_id))
[docs] def resources(self):
"""
:returns: a list of resources being reported for.
:rtype: list(tuple,) - [(resource_id, resource_name),] - a list of tuples consisting of two fields: a resource ID and a resource name.
Resources are available in the :py:const:`"Resource Report" type <cerebro.aclasses.AbstractMessage.TYPE_RESOURCE_REPORT>` only.
If the :py:const:`message type <cerebro.aclasses.AbstractMessage.TYPE_>` is not the "Resource Report", "None" is being returned.
::
if event.type() == event.TYPE_RESOURCE_REPORT:
print('resources()', event.resources())
"""
return py_cerebro_classes.message_resources(self._Event__event.id)
[docs] def new_attachments(self):
"""
:returns: a list of new attachments to the message.
:rtype: list(:py:class:`cerebro.aclasses.AbstractAttachment`,)
"""
attachs = list()
ids = py_cerebro_classes.message_attach_ids(self._Event__event.id, -2)
if ids != None:
for id in ids:
attachs.append(cerebro.aclasses.AbstractAttachment(self._Event__event.id, -2, id))
return attachs
[docs]class BeforeEventCreationOfMessage(BeforeEventMessage):
"""
The class for the task creation event.
Grants access to the data of a newly created message before it is written into the database.
.. rubric:: Methods
* :py:meth:`add_hashtags() <cerebro.events.BeforeEventCreationOfMessage.add_hashtags>`
* :py:meth:`remove_hashtags() <cerebro.events.BeforeEventCreationOfMessage.remove_hashtags>`
* :py:class:`methods of the base class cerebro.events.BeforeEventMessage <cerebro.events.BeforeEventMessage>`
The class object is input into the :py:func:`before_event <event.before_event>`
and :py:func:`error_event <event.error_event>` (in case of error) functions
of the :ref:`event <capi-event>` module.
::
def before_event(event):
if event.event_type() == event.EVENT_CREATION_OF_MESSAGE:
...
.. seealso:: :py:class:`AfterEventCreationOfMessage <cerebro.events.AfterEventCreationOfMessage>`.
"""
def __init__(self, event_type, event_id):
BeforeEventMessage.__init__(self, event_type, event_id)
[docs]class AfterEventCreationOfMessage(AfterEventMessage):
"""
The class for the task creation event.
Grants access to the data of a newly created message after it is written into the database.
.. rubric:: Methods
* :py:class:`methods of the base class cerebro.events.AfterEventMessage <cerebro.events.AfterEventMessage>`
The class object is input into the following function: :py:func:`after_event <event.after_event>`
of the module :ref:`event <capi-event>`.
::
def after_event(event):
if event.event_type() == event.EVENT_CREATION_OF_MESSAGE:
...
.. seealso:: :py:class:`BeforeEventCreationOfMessage <cerebro.events.BeforeEventCreationOfMessage>`.
"""
def __init__(self, event_type, event_id):
AfterEventMessage.__init__(self, event_type, event_id)
[docs]class BeforeEventChangingOfMessage(BeforeEventMessage):
"""
The class for the message editing event.
It grants access to the data of the message being modified before writing it into the database.
.. rubric:: Methods
* :py:meth:`existing_attachments() <cerebro.events.BeforeEventChangingOfMessage.existing_attachments>`
* :py:meth:`original_message() <cerebro.events.BeforeEventChangingOfMessage.original_message>`
* :py:class:`methods of the base class cerebro.events.BeforeEventMessage <cerebro.events.BeforeEventMessage>`
The class object is input into the functions :py:func:`before_event <event.before_event>`
and :py:func:`error_event <event.error_event>` (in case of error)
of the module :ref:`event <capi-event>`.
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_MESSAGE:
...
.. seealso:: :py:class:`AfterEventChangingOfMessage <cerebro.events.AfterEventChangingOfMessage>`.
"""
def __init__(self, event_type, event_id):
BeforeEventMessage.__init__(self, event_type, event_id)
[docs] def existing_attachments(self):
"""
:returns: the list of actual attachments that were added to the message before.
:rtype: list(:py:class:`cerebro.aclasses.AbstractAttachment`,)
"""
attachs = list()
ids = py_cerebro_classes.existing_attach_ids(self._Event__event.id)
if ids != None:
for id in ids:
attachs.append(cerebro.aclasses.AbstractAttachment(self._Event__event.id, -2, id))
return attachs
[docs] def original_message(self):
"""
:returns: the message in its previous state (before undergoing current modifications).
:rtype: :py:class:`cerebro.aclasses.Message`
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_MESSAGE:
orig_message = event.original_message()
# Comparing the current (after a message modification) working time value and its original (before the modification) value
if event.work_time() != orig_message.work_time():
raise Exception('You can't change the working time!')
"""
return cerebro.aclasses.Message(py_cerebro_classes.event_message_id(self._Event__event.id))
[docs]class AfterEventChangingOfMessage(AfterEventMessage):
"""
The class for the message editing event.
It grants access to the data of the modified message after writing it into the database.
.. rubric:: Methods
* :py:class:`methods of the base class cerebro.events.AfterEventMessage <cerebro.events.AfterEventMessage>`
The class object is input into the following function: :py:func:`after_event <event.after_event>`
of the module :ref:`event <capi-event>`.
::
def after_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_MESSAGE:
...
.. seealso:: :py:class:`BeforeEventChangingOfMessage <cerebro.events.BeforeEventChangingOfMessage>`.
"""
def __init__(self, event_type, event_id):
AfterEventMessage.__init__(self, event_type, event_id)
[docs]class EventChangingOfMessages(Event):
"""
The base class for the message properties change event (as for a single message so for several messages at once).
It grants access to the data of the modified messages before writing it into the database.
.. note:: Several messages may undergo one and the same properties change, and in this case only one event is generated.
.. rubric:: Methods
* :py:meth:`messages() <cerebro.events.EventChangingOfMessages.messages>`
* :py:class:`methods of the base class cerebro.events.Event <cerebro.events.Event>`
"""
def __init__(self, event_type, event_id):
Event.__init__(self, event_type, event_id)
[docs] def messages(self):
"""
:returns: a list of the messages being modified by the user.
:rtype: list(:py:class:`cerebro.aclasses.Message`,)
"""
messages = list()
ids = py_cerebro_classes.event_message_ids(self._Event__event.id);
if ids != None:
for id in ids:
messages.append(cerebro.core.message(id))
return messages
[docs]class BeforeEventCreationOfTask(Event, cerebro.aclasses.Task):
"""
The class for the task creation event.
It grants access to the data of the new task before writing it into the database.
.. rubric:: Methods
* :py:meth:`definition() <cerebro.events.BeforeEventCreationOfTask.definition>`
* :py:class:`methods of the base class cerebro.aclasses.Task <cerebro.aclasses.Task>`
* :py:class:`methods of the base class cerebro.events.Event <cerebro.events.Event>`
The class object is input into the functions :py:func:`before_event <event.before_event>`
and :py:func:`error_event <event.error_event>` (in case of error)
of the module :ref:`event <capi-event>`.
::
def before_event(event):
if event.event_type() == event.EVENT_CREATION_OF_TASK:
...
.. seealso:: :py:class:`AfterEventCreationOfTask <cerebro.events.AfterEventCreationOfTask>`.
"""
def __init__(self, event_type, event_id):
Event.__init__(self, event_type, event_id)
uids = py_cerebro_classes.event_task_ids(event_id);
cerebro.aclasses.Task.__init__(self, uids[0])
self.__event_message = BeforeEventCreationOfMessage(event_type, event_id)
[docs] def definition(self):
"""
:returns: a new message of the :py:const:`"Definition" type <cerebro.aclasses.AbstractMessage.TYPE_DEFINITION>`.
:rtype: :py:class:`cerebro.events.BeforeEventCreationOfMessage`
Alongside with creation of a new task, a new Definition message is being created also,
that's why the task creation event handles the Definition creation as well.
::
if event.event_type() == event.EVENT_CREATION_OF_TASK:
message = event.definition()
...
"""
return self.__event_message
[docs]class AfterEventCreationOfTask(Event, cerebro.aclasses.Task):
"""
The class for the task creation event.
It grants access to the data of the new task after writing it into the database.
.. rubric:: Methods
* :py:meth:`definition() <cerebro.events.BeforeEventCreationOfTask.definition>`
* :py:class:`methods of the base class cerebro.aclasses.Task <cerebro.aclasses.Task>`
* :py:class:`methods of the base class cerebro.events.Event <cerebro.events.Event>`
The class object is input into the following function: :py:func:`after_event <event.after_event>`
of the module :ref:`event <capi-event>`.
::
def after_event(event):
if event.event_type() == event.EVENT_CREATION_OF_TASK:
...
.. seealso:: :py:class:`BeforeEventCreationOfTask <cerebro.events.BeforeEventCreationOfTask>`.
"""
def __init__(self, event_type, event_id):
Event.__init__(self, event_type, event_id)
uids = py_cerebro_classes.event_task_ids(event_id);
cerebro.aclasses.Task.__init__(self, uids[0])
self.__event_message = AfterEventCreationOfMessage(event_type, event_id)
[docs] def definition(self):
"""
:returns: a new message of the :py:const:`"Definition" type <cerebro.aclasses.AbstractMessage.TYPE_DEFINITION>`.
:rtype: :py:class:`cerebro.events.AfterEventCreationOfMessage`
Alongside with creation of a new task, a new Definition message is being created also,
that's why the event handles the Definition creation as well.
::
if event.event_type() == event.EVENT_CREATION_OF_TASK:
message = event.definition()
...
"""
return self.__event_message
class EventManageOfTasks(Event):
def __init__(self, event_type, event_id):
Event.__init__(self, event_type, event_id)
def tasks(self):
tasks = list()
ids = py_cerebro_classes.event_task_ids(self._Event__event.id);
if ids != None:
for id in ids:
tasks.append(cerebro.core.task(id))
return tasks
def destination(self):
tasks = list()
ids = py_cerebro_classes.event_to_task_ids(self._Event__event.id);
if ids != None:
for id in ids:
tasks.append(cerebro.core.task(id))
return tasks
[docs]class EventChangingOfTasks(Event):
"""
The base class for the task properties change event (as for a single task so for several tasks at once).
It grants access to the data of the modified tasks before writing it into the database.
.. note:: Several tasks may undergo one and the same properties change, and in this case only one event is generated.
.. rubric:: Methods
* :py:meth:`tasks() <cerebro.events.EventChangingOfTasks.tasks>`
* :py:class:`methods of the base class cerebro.events.Event <cerebro.events.Event>`
"""
def __init__(self, event_type, event_id):
Event.__init__(self, event_type, event_id)
[docs] def tasks(self):
"""
:returns: a list of the tasks being modified by the user.
:rtype: list(:py:class:`cerebro.aclasses.Task`,)
"""
tasks = list()
ids = py_cerebro_classes.event_task_ids(self._Event__event.id);
if ids != None:
for id in ids:
tasks.append(cerebro.core.task(id))
return tasks
[docs]class EventChangingOfAttachments(Event):
"""
The base class for the attachment properties change event (as for a single attachment so for several attachments at once).
It grants access to the data of the modified attachments before writing it into the database.
.. note:: Several attachments may undergo one and the same properties change, and in this case only one event is generated.
.. rubric:: Methods
* :py:meth:`attachments() <cerebro.events.EventChangingOfAttachments.attachments>`
* :py:class:`methods of the base class cerebro.events.Event <cerebro.events.Event>`
"""
def __init__(self, event_type, event_id):
Event.__init__(self, event_type, event_id)
[docs] def attachments(self):
"""
:returns: a list of the attachments being modified by the user.
:rtype: list((attach_id, :py:class:`cerebro.aclasses.Message`),)
"""
attachments = list()
ids = py_cerebro_classes.event_attach_ids(self._Event__event.id);
if ids != None:
for id in ids:
attachments.append([id[1], cerebro.core.message(id[0])])
return attachments
[docs]class BeforeEventChangingOfTasks(EventChangingOfTasks):
"""
The class for task properties change - for a single task or several tasks at once.
It grants access to the data of the modified tasks before writing it into the database.
.. rubric:: Methods
* :py:meth:`new_value() <cerebro.events.BeforeEventChangingOfTasks.new_value>`
* :py:meth:`set_new_value() <cerebro.events.BeforeEventChangingOfTasks.set_new_value>`
* :py:class:`methods of the base class cerebro.events.EventChangingOfTasks <cerebro.events.EventChangingOfTasks>`
.. warning:: this class is used to handle the changes of most part of the properties, but not all of them.
In order to handle, for example, tag modifying, some other classes should be used.
:py:mod:`See the complete list of event classes <cerebro.events>`.
The class object is input into the functions :py:func:`before_event <event.before_event>`
and :py:func:`error_event <event.error_event>` (in case of error)
of the module :ref:`event <capi-event>`.
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_TASKS_PROGRESS:
...
.. seealso:: :py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`.
"""
def __init__(self, event_type, event_id):
EventChangingOfTasks.__init__(self, event_type, event_id)
[docs] def new_value(self):
"""
:returns: a new value of the property undergoing changing.
The type of the returning value depends on the Property being changed.
Check the methods on getting the values of similar properties of the :py:class:`cerebro.aclasses.Task` class to define the type.
.. note:: Use the :py:class:`corresponding methods <cerebro.aclasses.Task>` of the tasks being edited
:py:meth:`tasks() <cerebro.events.EventChangingOfTasks.tasks>` to find out the current values.
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_TASKS_ACTIVITY: # activity type is being changed
tasks = event.tasks()
for task in tasks:
print('Task name', task.name())
print('<Previous activity type', task.activity())
print('New activity type', event.new_value())
"""
return py_cerebro_classes.task_new_value(self._Event__event.id)
[docs] def set_new_value(self, val):
"""
:param val: parameter value.
Sets a new value of the property being changed.
The type of the new value depends on the property being changed.
Check the methods of setting up similar properties of the :py:class:`cerebro.aclasses.Task` class to define the type.
::
if event.type() == event.EVENT_CHANGING_OF_TASKS_NAME:
task_name = event.new_value()
if task_name.isupper() == False:
new_name = task_name.upper() # changing the symbols to the upper register
event.set_new_value(new_name) # substituting the value entered by user for the new one
"""
py_cerebro_classes.task_set_new_value(self._Event__event.id, val)
[docs]class AfterEventChangingOfTasks(EventChangingOfTasks):
"""
The class for the property change event - for a single task or several tasks at once.
It grants access to the data of the modified tasks after writing it into the database.
.. warning:: this class is used to handle the changes of most part of the properties, but not all of them.
In order to handle, for example, tag modifying, some other classes should be used.
:py:mod:`See the complete list of event classes <cerebro.events>`.
.. rubric:: Methods
* :py:class:`methods of the base class cerebro.events.EventChangingOfTasks <cerebro.events.EventChangingOfTasks>`
The class object is input into the following function: :py:func:`after_event <event.after_event>`
of the module :ref:`event <capi-event>`.
::
def after_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_TASKS_PROGRESS:
...
.. seealso:: :py:class:`BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`.
"""
def __init__(self, event_type, event_id):
EventChangingOfTasks.__init__(self, event_type, event_id)
[docs]class AfterEventChangingOfMessages(EventChangingOfMessages):
"""
The class for the property change event - for a single message or several messages at once.
It grants access to the data of the modified messages after writing it into the database.
.. warning:: this class is used to handle the changes of most part of the properties, but not all of them.
In order to handle, for example, tag modifying, some other classes should be used.
:py:mod:`See the complete list of event classes <cerebro.events>`.
.. rubric:: Methods
* :py:class:`methods of the base class cerebro.events.EventChangingOfMessages <cerebro.events.EventChangingOfMessages>`
The class object is input into the following function: :py:func:`after_event <event.after_event>`
of the module :ref:`event <capi-event>`.
::
def after_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_MESSAGE_FLAGS:
...
.. seealso:: :py:class:`BeforeEventChangingOfMessages <cerebro.events.BeforeEventChangingOfMessages>`.
"""
def __init__(self, event_type, event_id):
EventChangingOfMessages.__init__(self, event_type, event_id)
[docs]class AfterEventChangingOfAttachments(EventChangingOfAttachments):
"""
The class for the property change event - for a single attachment or several attachments at once.
It grants access to the data of the modified attachments after writing it into the database.
.. warning:: this class is used to handle the changes of most part of the properties, but not all of them.
In order to handle, for example, tag modifying, some other classes should be used.
:py:mod:`See the complete list of event classes <cerebro.events>`.
.. rubric:: Methods
* :py:class:`methods of the base class cerebro.events.EventChangingOfMessages <cerebro.events.EventChangingOfMessages>`
The class object is input into the following function: :py:func:`after_event <event.after_event>`
of the module :ref:`event <capi-event>`.
::
def after_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_ATTACHMENT_HASHTAGS:
...
.. seealso:: :py:class:`BeforeEventChangingOfAttachments <cerebro.events.BeforeEventChangingOfAttachments>`.
"""
def __init__(self, event_type, event_id):
EventChangingOfAttachments.__init__(self, event_type, event_id)
[docs]class BeforeEventChangingOfTasksAllocated(BeforeEventChangingOfTasks):
"""
The class for the allocating/dismissing users/resources to/from a single or multiple task(s).
It grants access to the data of the modified tasks before writing it into the database.
.. rubric:: Methods
* :py:meth:`is_added() <cerebro.events.BeforeEventChangingOfTasksAllocated.is_added>`
* :py:class:`methods of the base class cerebro.events.BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`
The class object is input into the functions :py:func:`before_event <event.before_event>`
and :py:func:`error_event <event.error_event>` (in case of error)
of the module :ref:`event <capi-event>`.
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_TASKS_ALLOCATED:
...
.. seealso:: :py:class:`AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`.
"""
def __init__(self, event_type, event_id):
BeforeEventChangingOfTasks.__init__(self, event_type, event_id)
[docs] def is_added(self):
"""
:returns: True, if users/resources are being allocated to task(s). False, is being dismissed.
:rtype: bool
In case of allocating users/resources the method
:py:meth:`new_value() <cerebro.events.BeforeEventChangingOfTasks.new_value>`
returns a list of users/resources being allocated. Otherwise, it returns a list of users being dismissed.
In order to change the list of users being allocated/dismissed use the method
:py:meth:`set_new_value() <cerebro.events.BeforeEventChangingOfTasks.set_new_value>`.
The input argument for this method - list(user_id,), the list of user/resource IDs
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_TASKS_ALLOCATED: # the tasks allocated is being changed
if event.is_added() == False: # the users are being dismissed
# asking the user if he/she is sure to do it
q = 'Are you sure you want to dismiss the users from the task?'
if cerebro.gui.question_box('User list change', q) == False: # if the user is not sure
raise Exception('')
# The users will remain allocated to the task
"""
return py_cerebro_classes.task_event_flag(self._Event__event.id)!=0
[docs]class BeforeEventChangingOfTasksTag(BeforeEventChangingOfTasks):
"""
The class for the tag value altering event - for a single or for multiple task(s).
It grants access to the data of the modified tasks before writing it into the database.
.. note:: Tags in Cerebro are used as additional task properties.
A tag, being allocated to a project, becomes a task property automatically.
The tags aquire values in the process of working on the tasks.
.. rubric:: Methods
* :py:meth:`is_added_elements() <cerebro.events.BeforeEventChangingOfTasksTag.is_added_elements>`
* :py:meth:`tag() <cerebro.events.BeforeEventChangingOfTasksTag.tag>`
* :py:class:`methods of the base class cerebro.events.BeforeEventChangingOfTasks <cerebro.events.BeforeEventChangingOfTasks>`
The class object is input into the functions :py:func:`before_event <event.before_event>`
and :py:func:`error_event <event.error_event>` (in case of error)
of the module :ref:`event <capi-event>`.
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_TASKS_TAG:
...
.. seealso:: :py:class:`AfterEventChangingOfTasksTag <cerebro.events.AfterEventChangingOfTasksTag>`.
"""
def __init__(self, event_type, event_id):
BeforeEventChangingOfTasks.__init__(self, event_type, event_id)
[docs] def is_added_elements(self):
"""
:returns: True, if the tag type is :py:const:`"multi enum" <cerebro.aclasses.AbstractTag.TYPE_MULTI_ENUM>` and the elements are being added to the tag value. Otherwise it is False.
:rtype: bool
In case of adding elements to the tag value the method
:py:meth:`new_value() <cerebro.events.BeforeEventChangingOfTasks.new_value>`
returns a list of the elements being added. Otherwise, it returns a list of elements being removed.
In order to change the list of elements being added/removed, use the method
:py:meth:`set_new_value() <cerebro.events.BeforeEventChangingOfTasks.set_new_value>`.
The input argument type for this method - list(tag_element_id,), a list of the tag element IDs.
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_TASKS_TAG: # changing the activity type
if event.tag().type() == event.tag().TYPE_MULTI_ENUM and event.is_added_elements():
print('The tag elements being added', event.new_value())
"""
return py_cerebro_classes.task_event_flag(self._Event__event.id)!=0
[docs] def tag(self):
"""
:returns: the tag undergoing modification.
:rtype: :py:class:`cerebro.aclasses.AbstractTag`
"""
return cerebro.aclasses.AbstractTag(py_cerebro_classes.task_event_tag(self._Event__event.id))
[docs]class AfterEventChangingOfTasksTag(AfterEventChangingOfTasks):
"""
The class for the tag value altering event - for a single or for multiple task(s).
It grants access to the data of the modified tasks after writing it into the database.
.. rubric:: Methods
* :py:meth:`tag() <cerebro.events.AfterEventChangingOfTasksTag.tag>`
* :py:class:`methods of the base class cerebro.events.AfterEventChangingOfTasks <cerebro.events.AfterEventChangingOfTasks>`
The class object is input into the following function: :py:func:`after_event <event.after_event>`
of the module :ref:`event <capi-event>`.
::
def after_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_TASKS_TAG:
...
.. seealso:: :py:class:`BeforeEventChangingOfTasksTag <cerebro.events.BeforeEventChangingOfTasksTag>`.
"""
def __init__(self, event_type, event_id):
AfterEventChangingOfTasks.__init__(self, event_type, event_id)
[docs] def tag(self):
"""
:returns: the changed tag.
:rtype: :py:class:`cerebro.aclasses.AbstractTag`
"""
return cerebro.aclasses.AbstractTag(py_cerebro_classes.task_event_tag(self._Event__event.id))
[docs]class BeforeEventChangingOfMessages(EventChangingOfMessages):
"""
The class for message properties change - for a single message or several messages at once.
It grants access to the data of the modified messages before writing it into the database.
.. rubric:: Methods
* :py:meth:`new_value() <cerebro.events.BeforeEventChangingOfMessages.new_value>`
* :py:meth:`set_new_value() <cerebro.events.BeforeEventChangingOfMessages.set_new_value>`
* :py:class:`methods of the base class cerebro.events.EventChangingOfMessages <cerebro.events.EventChangingOfMessages>`
.. warning:: this class is used to handle the changes of most part of the properties, but not all of them.
In order to handle, for example, tag modifying, some other classes should be used.
:py:mod:`See the complete list of event classes <cerebro.events>`.
The class object is input into the functions :py:func:`before_event <event.before_event>`
and :py:func:`error_event <event.error_event>` (in case of error)
of the module :ref:`event <capi-event>`.
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_MESSAGE_APPROVED:
...
.. seealso:: :py:class:`AfterEventChangingOfMessages <cerebro.events.AfterEventChangingOfMessages>`.
"""
def __init__(self, event_type, event_id):
EventChangingOfMessages.__init__(self, event_type, event_id)
[docs] def new_value(self):
"""
:returns: a new value of the property undergoing changing.
The type of the returning value depends on the Property being changed.
Check the methods on getting the values of similar properties of the :py:class:`cerebro.aclasses.Message` class to define the type.
.. note:: Use the :py:class:`corresponding methods <cerebro.aclasses.Message>` of the tasks being edited
:py:meth:`messages() <cerebro.events.EventChangingOfMessages.messages>` to find out the current values.
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_MESSAGE_HASHTAGS: # activity type is being changed
messages = event.messages()
for message in messages:
print('Message name', message.name())
print('<Previous activity type', message.activity())
print('New activity type', event.new_value())
"""
return py_cerebro_classes.message_new_value(self._Event__event.id)
[docs] def set_new_value(self, val):
"""
:param val: parameter value.
Sets a new value of the property being changed.
The type of the new value depends on the property being changed.
Check the methods of setting up similar properties of the :py:class:`cerebro.aclasses.Message` class to define the type.
::
if event.type() == event.EVENT_CHANGING_OF_MESSAGE_HASHTAGS:
message_name = event.new_value()
if task_name.isupper() == False:
new_name = task_name.upper() # changing the symbols to the upper register
event.set_new_value(new_name) # substituting the value entered by user for the new one
"""
py_cerebro_classes.message_set_new_value(self._Event__event.id, val)
[docs]class BeforeEventChangingOfAttachments(EventChangingOfAttachments):
"""
The class for attachment properties change - for a single attachment or several attachments at once.
It grants access to the data of the modified attachment before writing it into the database.
.. rubric:: Methods
* :py:meth:`new_value() <cerebro.events.BeforeEventChangingOfAttachments.new_value>`
* :py:meth:`set_new_value() <cerebro.events.BeforeEventChangingOfAttachments.set_new_value>`
* :py:class:`methods of the base class cerebro.events.EventChangingOfAttachments <cerebro.events.EventChangingOfAttachments>`
.. warning:: this class is used to handle the changes of most part of the properties, but not all of them.
In order to handle, for example, tag modifying, some other classes should be used.
:py:mod:`See the complete list of event classes <cerebro.events>`.
The class object is input into the functions :py:func:`before_event <event.before_event>`
and :py:func:`error_event <event.error_event>` (in case of error)
of the module :ref:`event <capi-event>`.
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_ATTACHMENT_HASHTAGS:
...
.. seealso:: :py:class:`AfterEventChangingOfAttachments <cerebro.events.AfterEventChangingOfAttachments>`.
"""
def __init__(self, event_type, event_id):
EventChangingOfAttachments.__init__(self, event_type, event_id)
[docs] def new_value(self):
"""
:returns: a new value of the property undergoing changing.
The type of the returning value depends on the Property being changed.
Check the methods on getting the values of similar properties of the :py:class:`cerebro.aclasses.Message` class to define the type.
.. note:: Use the :py:class:`corresponding methods <cerebro.aclasses.Attachment>` of the tasks being edited
:py:meth:`messages() <cerebro.events.EventChangingOfAttachments.attachments>` to find out the current values.
::
def before_event(event):
if event.event_type() == event.EVENT_CHANGING_OF_MESSAGE_HASHTAGS: # activity type is being changed
tasks = event.messages()
for message in messages:
print('Message name', message.name())
print('<Previous activity type', message.activity())
print('New activity type', event.new_value())
"""
return py_cerebro_classes.attach_new_value(self._Event__event.id)
[docs] def set_new_value(self, val):
"""
:param val: parameter value.
Sets a new value of the property being changed.
The type of the new value depends on the property being changed.
Check the methods of setting up similar properties of the :py:class:`cerebro.aclasses.Attachment` class to define the type.
::
if event.type() == event.EVENT_CHANGING_OF_ATTACHMENT_HASHTAGS:
attachment_name = event.new_value()
if attachment_name.isupper() == False:
new_name = attachment_name.upper() # changing the symbols to the upper register
event.set_new_value(new_name) # substituting the value entered by user for the new one
"""
py_cerebro_classes.attach_set_new_value(self._Event__event.id, val)