コード例 #1
0
def update_task_configs_subscriptions(schedule_config, event):
    """
    When the scheduled_contenttype value of a ScheduleConfig is changed,
    we have to unregister all the adapters providing IToTaskConfig
    and register them again for the new selected content type.
    """

    previous_interface = getattr(schedule_config, '_scheduled_interface_', None)
    new_interface = schedule_config.get_scheduled_interface()
    new_interface = interface_to_tuple(new_interface)

    # if there were no previous values, just save it and return
    if not previous_interface:
        setattr(schedule_config, '_scheduled_interface_', new_interface)
        return

    # if the walue did not change, do nothing
    if previous_interface == new_interface:
        return

    for task_config in schedule_config.get_all_task_configs():
        # unregister the IToTaskConfig adapter for the previous interface
        unsubscribe_task_configs_for_content_type(task_config, event)
        # register the new IToTaskConfig adapter for the new interface
        subscribe_task_configs_for_content_type(task_config, event)

    # replace the _schedule_interface_ attribute with the new value
    setattr(schedule_config, '_scheduled_interface_', new_interface)
コード例 #2
0
def update_task_configs_subscriptions(schedule_config, event):
    """
    When the scheduled_contenttype value of a ScheduleConfig is changed,
    we have to unregister all the adapters providing IToTaskConfig
    and register them again for the new selected content type.
    """

    previous_interfaces = getattr(schedule_config, '_scheduled_interface_',
                                  None)
    new_interfaces = schedule_config.get_scheduled_interfaces()
    new_interfaces = tuple([interface_to_tuple(i) for i in new_interfaces])

    # if there were no previous values, just save it and return
    if not previous_interfaces:
        setattr(schedule_config, '_scheduled_interface_', new_interfaces)
        return

    # if the value did not change, do nothing
    if previous_interfaces == new_interfaces:
        return

    for task_config in schedule_config.get_all_task_configs():
        # unregister the IToTaskConfig adapter for the previous interface
        unsubscribe_task_configs_for_content_type(task_config, event)
        # register the new IToTaskConfig adapter for the new interface
        subscribe_task_configs_for_content_type(task_config, event)

    # replace the _schedule_interface_ attribute with the new value
    setattr(schedule_config, '_scheduled_interface_', new_interfaces)
コード例 #3
0
    def test_adapters_update_on_LicenceSchedule_modification(self):
        """
        When an other content type is selected on the field 'scheduled_contenttype'
        of a ScheduleConfig, we have to unregister all the IToTaskConfig adapter of
        each TaskConfig of this ScheduleConfig and register them back for the new
        portal_type.
        """
        schedule_config = self.schedule_config
        task_config = self.task_config
        folder = self.portal.config
        document = api.content.create(type='Document', id='doc', container=self.portal)

        # the adapter should be registered for IATFolder
        adapter = getAdapter(folder, IToTaskConfig, task_config.UID())
        msg = "an adapter providing IToTaskConfig should have been registered for IATFolder"
        self.assertTrue(adapter is not None, msg)

        #... but not for IATDocument
        adapter = queryAdapter(document, IToTaskConfig, task_config.UID())
        msg = "not adapter should have been registered for IATDocument yet..."
        self.assertTrue(adapter is None, msg)

        # modify 'scheduled_contenttype' then manually trigger the modification event
        schedule_config.scheduled_contenttype = ('Document', interface_to_tuple(IATDocument))
        notify(ObjectModifiedEvent(schedule_config))

        # old IToTaskConfig adapter should be unregistered for IATFolder
        adapter = queryAdapter(folder, IToTaskConfig, task_config.UID())
        msg = "the adapter should have been unregistered when modifying the ScheduleConfig"
        self.assertTrue(adapter is None, msg)

        # new IToTaskConfig adapter should be registered for IATDocument
        adapter = queryAdapter(document, IToTaskConfig, task_config.UID())
        msg = "an adapter providing IToTaskConfig should have been registered for IATDocument"
        self.assertTrue(adapter is not None, msg)
コード例 #4
0
 def to_vocabulary_key(self, portal_type, interfaces):
     """
     Return the module path of a class.
     """
     if type(interfaces) not in [list, tuple]:
         interfaces = (interfaces, )
     return (portal_type, tuple([interface_to_tuple(i)
                                 for i in interfaces]))
コード例 #5
0
ファイル: test_utils.py プロジェクト: IMIO/imio.schedule
    def test_interface_to_tuple(self):
        """
        Should turn an Interface class into a tuple:
        ('interface.module.path', 'Interface')
        """
        from imio.schedule.utils import interface_to_tuple

        expected_tuple = ('Products.ATContentTypes.interfaces.folder', 'IATFolder')
        interface_tuple = interface_to_tuple(IATFolder)
        self.assertEqual(interface_tuple, expected_tuple)
コード例 #6
0
    def test_interface_to_tuple(self):
        """
        Should turn an Interface class into a tuple:
        ('interface.module.path', 'Interface')
        """
        from imio.schedule.utils import interface_to_tuple

        expected_tuple = ('Products.ATContentTypes.interfaces.folder',
                          'IATFolder')
        interface_tuple = interface_to_tuple(IATFolder)
        self.assertEqual(interface_tuple, expected_tuple)
コード例 #7
0
    def test_adapters_update_on_LicenceSchedule_modification(self):
        """
        When an other content type is selected on the field 'scheduled_contenttype'
        of a ScheduleConfig, we have to unregister all the IToTaskConfig adapter of
        each TaskConfig of this ScheduleConfig and register them back for the new
        portal_type.
        """
        schedule_config = self.schedule_config
        task_config = self.task_config
        folder = self.portal.config
        document = api.content.create(type='Document',
                                      id='doc',
                                      container=self.portal)

        # the adapter should be registered for IATFolder
        adapter = getAdapter(folder, IToTaskConfig, task_config.UID())
        msg = "an adapter providing IToTaskConfig should have been registered for IATFolder"
        self.assertTrue(adapter is not None, msg)

        #... but not for IATDocument
        adapter = queryAdapter(document, IToTaskConfig, task_config.UID())
        msg = "not adapter should have been registered for IATDocument yet..."
        self.assertTrue(adapter is None, msg)

        # modify 'scheduled_contenttype' then manually trigger the modification event
        schedule_config.scheduled_contenttype = (
            'Document', interface_to_tuple(IATDocument))
        notify(ObjectModifiedEvent(schedule_config))

        # old IToTaskConfig adapter should be unregistered for IATFolder
        adapter = queryAdapter(folder, IToTaskConfig, task_config.UID())
        msg = "the adapter should have been unregistered when modifying the ScheduleConfig"
        self.assertTrue(adapter is None, msg)

        # new IToTaskConfig adapter should be registered for IATDocument
        adapter = queryAdapter(document, IToTaskConfig, task_config.UID())
        msg = "an adapter providing IToTaskConfig should have been registered for IATDocument"
        self.assertTrue(adapter is not None, msg)
コード例 #8
0
def add_schedule_config(context):
    """
    Add dummy ScheduleConfig, TaskConfig.
    """
    site = api.portal.get()

    # create config folder for schedule config
    folder_id = 'config'
    if folder_id not in site.objectIds():
        api.content.create(container=site,
                           type='Folder',
                           id=folder_id,
                           title='Task configs')
    cfg_folder = getattr(site, folder_id)

    # create empty schedule config
    schedule_cfg_id = 'empty_scheduleconfig'
    if schedule_cfg_id not in cfg_folder.objectIds():
        api.content.create(
            container=cfg_folder,
            type='ScheduleConfig',
            id=schedule_cfg_id,
            title='Empty ScheduleConfig',
            scheduled_contenttype=('Folder', (interface_to_tuple(IATFile), )),
        )

    # create schedule config
    schedule_cfg_id = 'test_scheduleconfig'
    if schedule_cfg_id not in cfg_folder.objectIds():
        api.content.create(
            container=cfg_folder,
            type='ScheduleConfig',
            id=schedule_cfg_id,
            title='Test ScheduleConfig',
            scheduled_contenttype=('Folder',
                                   (interface_to_tuple(IATFolder), )),
        )
    schedule_config = getattr(cfg_folder, schedule_cfg_id)

    # create task config
    task_cfg_id = 'test_taskconfig'
    creation_conditions = CreationConditionObject()
    creation_conditions.__dict__ = {
        'condition': u'schedule.test_creation_condition',
        'operator': 'AND',
    }
    start_conditions = StartConditionObject()
    start_conditions.__dict__ = {
        'condition': u'schedule.test_start_condition',
        'operator': 'AND',
    }
    end_conditions = EndConditionObject()
    end_conditions.__dict__ = {
        'condition': u'schedule.test_end_condition',
        'operator': 'AND',
    }
    freeze_conditions = FreezeConditionObject()
    freeze_conditions.__dict__ = {
        'condition': u'schedule.test_freeze_condition',
        'operator': 'AND',
    }
    thaw_conditions = ThawConditionObject()
    thaw_conditions.__dict__ = {
        'condition': u'schedule.test_thaw_condition',
        'operator': 'AND',
    }
    macro_creation_conditions = MacroCreationConditionObject()
    macro_creation_conditions.__dict__ = creation_conditions.__dict__
    macro_start_conditions = MacroStartConditionObject()
    macro_start_conditions.__dict__ = start_conditions.__dict__
    macro_end_conditions = MacroEndConditionObject()
    macro_end_conditions.__dict__ = end_conditions.__dict__

    if task_cfg_id not in schedule_config.objectIds():
        api.content.create(
            container=schedule_config,
            type='TaskConfig',
            id=task_cfg_id,
            title='Test TaskConfig',
            default_assigned_user='******',
            default_assigned_group='schedule.assign_authenticatedusers_group',
            creation_conditions=[creation_conditions],
            start_conditions=[start_conditions],
            end_conditions=[end_conditions],
            freeze_conditions=[freeze_conditions],
            thaw_conditions=[thaw_conditions],
            creation_state='private',
            starting_states=('pending', ),
            ending_states=('published', ),
            start_date='schedule.start_date.creation_date',
            additional_delay=10,
        )

    # create macro task config
    macrotask_cfg_id = 'test_macrotaskconfig'
    if macrotask_cfg_id not in schedule_config.objectIds():
        api.content.create(
            container=schedule_config,
            type='MacroTaskConfig',
            id=macrotask_cfg_id,
            title='Test MacroTaskConfig',
            default_assigned_user='******',
            default_assigned_group='schedule.assign_authenticatedusers_group',
            creation_conditions=[macro_creation_conditions],
            start_conditions=[macro_start_conditions],
            end_conditions=[macro_end_conditions],
            creation_state='private',
            starting_states=('pending', ),
            ending_states=('published', ),
            start_date='schedule.start_date.subtask_highest_due_date',
            additional_delay=17,
        )
    macrotask_config = getattr(schedule_config, macrotask_cfg_id)

    # create sub task config
    subtask_cfg_id = 'test_subtaskconfig'
    if subtask_cfg_id not in macrotask_config.objectIds():
        api.content.create(
            container=macrotask_config,
            type='TaskConfig',
            id=subtask_cfg_id,
            title='Test SubTaskConfig',
            default_assigned_user='******',
            default_assigned_group='schedule.assign_authenticatedusers_group',
            creation_conditions=[creation_conditions],
            start_conditions=[start_conditions],
            end_conditions=[end_conditions],
            creation_state='private',
            starting_states=('pending', ),
            ending_states=('published', ),
            start_date='schedule.start_date.creation_date',
            additional_delay=13,
        )
コード例 #9
0
ファイル: vocabulary.py プロジェクト: IMIO/imio.schedule
 def to_vocabulary_key(self, portal_type, interface):
     """
     Return the module path of a class.
     """
     return (portal_type, interface_to_tuple(interface))
コード例 #10
0
ファイル: setup.py プロジェクト: IMIO/imio.schedule
def add_schedule_config(context):
    """
    Add dummy ScheduleConfig, TaskConfig.
    """
    site = api.portal.get()

    # create config folder for schedule config
    folder_id = 'config'
    if folder_id not in site.objectIds():
        api.content.create(
            container=site,
            type='Folder',
            id=folder_id,
            title='Task configs'
        )
    cfg_folder = getattr(site, folder_id)

    # create schedule config
    schedule_cfg_id = 'test_scheduleconfig'
    if schedule_cfg_id not in cfg_folder.objectIds():
        api.content.create(
            container=cfg_folder,
            type='ScheduleConfig',
            id=schedule_cfg_id,
            title='Test ScheduleConfig',
            scheduled_contenttype=('Folder', interface_to_tuple(IATFolder)),
        )
    schedule_config = getattr(cfg_folder, schedule_cfg_id)

    # create task config
    task_cfg_id = 'test_taskconfig'
    creation_conditions = CreationConditionObject()
    creation_conditions.__dict__ = {
        'condition': u'schedule.test_creation_condition',
        'operator': 'AND',
    }
    start_conditions = StartConditionObject()
    start_conditions.__dict__ = {
        'condition': u'schedule.test_start_condition',
        'operator': 'AND',
    }
    end_conditions = EndConditionObject()
    end_conditions.__dict__ = {
        'condition': u'schedule.test_end_condition',
        'operator': 'AND',
    }
    macro_creation_conditions = MacroCreationConditionObject()
    macro_creation_conditions.__dict__ = creation_conditions.__dict__
    macro_start_conditions = MacroStartConditionObject()
    macro_start_conditions.__dict__ = start_conditions.__dict__
    macro_end_conditions = MacroEndConditionObject()
    macro_end_conditions.__dict__ = end_conditions.__dict__

    if task_cfg_id not in schedule_config.objectIds():
        api.content.create(
            container=schedule_config,
            type='TaskConfig',
            id=task_cfg_id,
            title='Test TaskConfig',
            default_assigned_user='******',
            default_assigned_group='schedule.assign_authenticatedusers_group',
            creation_conditions=[creation_conditions],
            start_conditions=[start_conditions],
            end_conditions=[end_conditions],
            creation_state='private',
            starting_states=('pending',),
            ending_states=('published',),
            start_date='schedule.start_date.creation_date',
            additional_delay=10,
        )

    # create macro task config
    macrotask_cfg_id = 'test_macrotaskconfig'
    if macrotask_cfg_id not in schedule_config.objectIds():
        api.content.create(
            container=schedule_config,
            type='MacroTaskConfig',
            id=macrotask_cfg_id,
            title='Test MacroTaskConfig',
            default_assigned_user='******',
            default_assigned_group='schedule.assign_authenticatedusers_group',
            creation_conditions=[macro_creation_conditions],
            start_conditions=[macro_start_conditions],
            end_conditions=[macro_end_conditions],
            creation_state='private',
            starting_states=('pending',),
            ending_states=('published',),
            start_date='schedule.start_date.subtask_highest_due_date',
            additional_delay=17,
        )
    macrotask_config = getattr(schedule_config, macrotask_cfg_id)

    # create sub task config
    subtask_cfg_id = 'test_subtaskconfig'
    if subtask_cfg_id not in macrotask_config.objectIds():
        api.content.create(
            container=macrotask_config,
            type='TaskConfig',
            id=subtask_cfg_id,
            title='Test SubTaskConfig',
            default_assigned_user='******',
            default_assigned_group='schedule.assign_authenticatedusers_group',
            creation_conditions=[creation_conditions],
            start_conditions=[start_conditions],
            end_conditions=[end_conditions],
            creation_state='private',
            starting_states=('pending',),
            ending_states=('published',),
            start_date='schedule.start_date.creation_date',
            additional_delay=13,
        )