Exemplo n.º 1
0
def end_tasks(task_container, event):
    """
    Automatically end tasks matching end conditions of a given
    task container.
    """

    # This handler can be triggered for archetypes containers by the
    # workflow modification event but we want to create tasks only if
    # the container really exists (more than just created in portal_factory...)
    if hasattr(aq_base(task_container), 'checkCreationFlag'):
        if task_container.checkCreationFlag():
            return

    task_configs = get_task_configs(task_container)

    if not task_configs:
        return

    with api.env.adopt_roles(['Manager']):
        for config in task_configs:
            task = config.get_open_task(task_container)
            if task and config.should_end_task(task_container, task):
                # delegate the closure action to the config so different behaviors
                # can be easily configured
                config.end_task(task)
Exemplo n.º 2
0
def start_tasks(task_container, event):
    """
    Automatically start tasks matching start conditions of a given
    task container.
    """

    # This handler can be triggered for archetypes containers by the
    # workflow modification event but we want to create tasks only if
    # the container really exists (more than just created in portal_factory...)
    if hasattr(aq_base(task_container), 'checkCreationFlag'):
        if task_container.checkCreationFlag():
            return

    task_configs = get_task_configs(task_container)

    if not task_configs:
        return

    with api.env.adopt_roles(['Manager']):
        for config in task_configs:
            task = config.get_created_task(task_container)
            if task and config.should_start_task(task_container, task):
                # delegate the starting action to the config so different behaviors
                # can be easily configured
                config.start_task(task)

                # update due date after the task has started, because some date
                # computation can rely on the task starting date
                task.due_date = config.compute_due_date(task_container, task)
                task.reindexObject(idxs=('due_date',))
Exemplo n.º 3
0
    def test_get_task_configs(self):
        """
        Test the method get_task_configs.
        """
        from imio.schedule.utils import get_task_configs

        expected_UIDS = [task_config.UID() for task_config in self.schedule_config.get_all_task_configs()]
        folder = self.portal.config
        task_configs = get_task_configs(folder)
        task_config_UIDS = [task_config.UID() for task_config in task_configs]
        self.assertEqual(set(task_config_UIDS), set(expected_UIDS))
Exemplo n.º 4
0
    def __init__(self, task_container, event):
        self.container = task_container
        self.event = event

        if self.is_created is False:
            return

        self.task_configs = get_task_configs(self.container)
        if not self.task_configs:
            return

        with api.env.adopt_roles(['Manager']):
            self.handle()
Exemplo n.º 5
0
    def test_get_task_configs(self):
        """
        Test the method get_task_configs.
        """
        from imio.schedule.utils import get_task_configs

        expected_UIDS = [
            task_config.UID()
            for task_config in self.schedule_config.get_all_task_configs()
        ]
        folder = self.portal.config
        task_configs = get_task_configs(folder)
        task_config_UIDS = [task_config.UID() for task_config in task_configs]
        self.assertEqual(set(task_config_UIDS), set(expected_UIDS))
Exemplo n.º 6
0
def create_new_tasks(task_container, event):
    """
    For each task config associated to this task container content type
    check the task config creations conditions and create the task if
    we can.
    """

    # This handler can be triggered for archetypes containers by the
    # workflow modification event but we want to create tasks only if
    # the container really exists (more than just created in portal_factory...)
    if hasattr(aq_base(task_container), 'checkCreationFlag'):
        if task_container.checkCreationFlag():
            return

    # descending=True <= it's important to create to macro tasks first
    task_configs = get_task_configs(task_container, descending=True)

    if not task_configs:
        return

    with api.env.adopt_roles(['Manager']):
        for config in task_configs:
            if config.is_main_taskconfig():
                if config.should_create_task(task_container):
                    try:
                        config.create_task(task_container)
                    except TaskAlreadyExists:
                        continue
            # case of a sub-task creation, the parent should have been created first
            else:
                macro_config = config.getParentNode()
                parent_task = macro_config.get_open_task(task_container)
                if parent_task and config.should_create_task(
                        task_container, parent_container=parent_task):
                    config.create_task(task_container,
                                       creation_place=parent_task)
Exemplo n.º 7
0
def update_due_date(task_container, event):
    """
    If the task_container has been modified, compute
    the due date again and update it on the task.
    """

    # This handler can be triggered for archetypes containers by the
    # workflow modification event but we want to create tasks only if
    # the container really exists (more than just created in portal_factory...)
    if hasattr(aq_base(task_container), 'checkCreationFlag'):
        if task_container.checkCreationFlag():
            return

    task_configs = get_task_configs(task_container)

    if not task_configs:
        return

    with api.env.adopt_roles(['Manager']):
        for config in task_configs:
            task = config.get_open_task(task_container)
            if task:
                task.due_date = config.compute_due_date(task_container, task)
                task.reindexObject(idxs=('due_date',))