当前位置: 首页>>代码示例>>Python>>正文


Python interfaces.IRuleAssignmentManager类代码示例

本文整理汇总了Python中plone.contentrules.engine.interfaces.IRuleAssignmentManager的典型用法代码示例。如果您正苦于以下问题:Python IRuleAssignmentManager类的具体用法?Python IRuleAssignmentManager怎么用?Python IRuleAssignmentManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IRuleAssignmentManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: acquired_rules

    def acquired_rules(self):

        # Short circuit if this is the root of the portal
        if ISiteRoot.providedBy(self.context):
            return []

        in_use = set([r['id'] for r in self.assigned_rules()])

        storage = getUtility(IRuleStorage)
        events = self._events()

        assignments = []
        context = aq_parent(aq_inner(self.context))

        while context is not None:
            assignable = IRuleAssignmentManager(context, None)
            if assignable is not None:
                for key, assignment in assignable.items():
                    if key not in in_use and assignment.bubbles:
                        rule = storage.get(key, None)
                        if rule is not None:
                            assignments.append(dict(id=key,
                                                    title=rule.title,
                                                    description=rule.description,
                                                    trigger=events.get(rule.event, "Unknown"),
                                                    url=context.absolute_url() + '/@@manage-content-rules',
                                                    enabled=(assignment.enabled and rule.enabled), ))
            if ISiteRoot.providedBy(context):
                context = None
            else:
                context = aq_parent(context)

        return assignments
开发者ID:alecghica,项目名称:plone.app.contentrules,代码行数:33,代码来源:assignments.py

示例2: container_moved

def container_moved(container, event):

    if event.oldParent is None or event.newParent is None or \
            event.oldName is None:
        return

    assignable = IRuleAssignmentManager(container, None)
    storage = queryUtility(IRuleStorage)

    if assignable is None or storage is None:
        return

    old_path = '{0}/{1}'.format(
        '/'.join(event.oldParent.getPhysicalPath()),
        event.oldName,
    )
    new_path = '/'.join(container.getPhysicalPath())

    if aq_base(event.object) is not aq_base(container):
        new_path_of_moved = '/'.join(event.object.getPhysicalPath())
        old_path = old_path + new_path[len(new_path_of_moved):]

    for rule_name in assignable.keys():
        rule = storage.get(rule_name, None)
        if rule is not None:
            assignments = get_assignments(rule)
            if old_path in assignments:
                assignments.remove(old_path)
                assignments.insert(new_path)
开发者ID:plone,项目名称:plone.app.contentrules,代码行数:29,代码来源:rule.py

示例3: _activate_rule

def _activate_rule(rule_id, context=None):
    assignable = IRuleAssignmentManager(context)
    assignment = assignable.get(rule_id, None)
    if not assignment:
        assignment = assignable[rule_id] = RuleAssignment(rule_id)
    assignment.enabled = True
    assignment.bubbles = True
    apirules.assign_rule(context, assignment.__name__)
开发者ID:bsuttor,项目名称:blog.policy,代码行数:8,代码来源:setuphandlers.py

示例4: _activate_rule

def _activate_rule(rule_id, context=None):
    storage = component.getUtility(IRuleStorage)
    rule = storage.get(rule_id)
    assignable = IRuleAssignmentManager(context)
    assignment = assignable.get(rule_id, None)
    if not assignment:
        assignment = assignable[rule_id] = RuleAssignment(rule_id)
    assignment.enabled = True
    assignment.bubbles = True
    get_assignments(rule).insert('/'.join(context.getPhysicalPath()))
开发者ID:collective,项目名称:collective.rcse,代码行数:10,代码来源:setuphandler.py

示例5: __call__

    def __call__(self):
        context = aq_inner(self.context)
        request = aq_inner(self.request)
        form = request.form
        status = IStatusMessage(self.request)

        operation = request.get('operation', None)

        if operation == 'move_up':
            assignable = IRuleAssignmentManager(context)
            rule_id = request.get('rule_id')
            keys = list(assignable.keys())
            idx = keys.index(rule_id)
            del keys[idx]
            keys.insert(idx - 1, rule_id)
            assignable.updateOrder(keys)
        elif operation == 'move_down':
            assignable = IRuleAssignmentManager(context)
            rule_id = request.get('rule_id')
            keys = list(assignable.keys())
            idx = keys.index(rule_id)
            del keys[idx]
            keys.insert(idx + 1, rule_id)
            assignable.updateOrder(keys)
        elif 'form.button.AddAssignment' in form:
            rule_id = form.get('rule_id')
            api.assign_rule(self.context, rule_id)
        elif 'form.button.Delete' in form:
            rule_ids = form.get('rule_ids', ())
            for r in rule_ids:
                api.unassign_rule(self.context, r)

            status.addStatusMessage(_(u'Assignments deleted.'), type='info')
        elif 'form.button.Enable' in form:
            rule_ids = form.get('rule_ids', ())
            for r in rule_ids:
                api.edit_rule_assignment(context, r, enabled=True)

            status.addStatusMessage(_(u'Assignments enabled.'), type='info')
        elif 'form.button.Disable' in form:
            rule_ids = form.get('rule_ids', ())
            for r in rule_ids:
                api.edit_rule_assignment(context, r, enabled=False)

            status.addStatusMessage(_(u'Assignments disabled.'), type='info')
        elif 'form.button.Bubble' in form:
            rule_ids = form.get('rule_ids', ())
            for r in rule_ids:
                api.edit_rule_assignment(
                    context, r, bubbles=True, enabled=True)

            status.addStatusMessage(_(u'Changes saved.'), type='info')
        elif 'form.button.NoBubble' in form:
            rule_ids = form.get('rule_ids', ())
            for r in rule_ids:
                api.edit_rule_assignment(context, r, bubbles=False)

            status.addStatusMessage(_(u'Changes saved.'), type='info')

        return self.template()
开发者ID:plone,项目名称:plone.app.contentrules,代码行数:60,代码来源:assignments.py

示例6: container_removed

def container_removed(container, event):

    assignable = IRuleAssignmentManager(container, None)
    storage = queryUtility(IRuleStorage)

    if assignable is None or storage is None:
        return

    path = '/'.join(container.getPhysicalPath())
    for rule_name in assignable.keys():
        rule = storage.get(rule_name, None)
        if rule is not None:
            assignments = get_assignments(rule)
            if path in assignments:
                assignments.remove(path)
开发者ID:plone,项目名称:plone.app.contentrules,代码行数:15,代码来源:rule.py

示例7: setUp

    def setUp(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        login(self.portal, TEST_USER_NAME)
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        self.portal.invokeFactory('Folder', 'f1')
        self.folder = self.portal['f1']
        self.folder.invokeFactory('Document', 'd1')
        self.portal.invokeFactory('Folder', 'target')
        self.folder.invokeFactory('Folder', 'f1')
        self.folder.f1.invokeFactory('Folder', 'f11')
        self.folder.f1.invokeFactory('Folder', 'f12')

        self.storage = getUtility(IRuleStorage)
        self.storage['r1'] = Rule()
        self.storage['r2'] = Rule()
        self.storage['r3'] = Rule()

        self.f11a = IRuleAssignmentManager(self.folder.f1.f11)
        self.f11a['r1'] = RuleAssignment('r1', bubbles=True)
        insert_assignment(self.storage['r1'],
                          '/'.join(self.folder.f1.f11.getPhysicalPath()))

        self.f12a = IRuleAssignmentManager(self.folder.f1.f12)
        self.f12a['r1'] = RuleAssignment('r1', bubbles=True)
        insert_assignment(self.storage['r1'],
                          '/'.join(self.folder.f1.f12.getPhysicalPath()))

        self.f12a['r2'] = RuleAssignment('r2', bubbles=True)
        insert_assignment(self.storage['r2'],
                          '/'.join(self.folder.f1.f12.getPhysicalPath()))
开发者ID:plone,项目名称:plone.app.contentrules,代码行数:31,代码来源:test_rule_assignment_mapping.py

示例8: assignContentRulesToContainer

def assignContentRulesToContainer(container, storage, bubbles):
    '''Assign the standard EDRN content events to the given container.'''
    assignmentManager = IRuleAssignmentManager(container, None)
    if assignmentManager is None:
        # This container doesn't support content rules, so skip it.
        return
    for eventName in _edrnContentEvents:
        assignment = assignmentManager.get(eventName, None)
        if assignment is None:
            # Brand new assignment
            assignment = assignmentManager[eventName] = RuleAssignment(eventName)
        if not assignment.enabled:
            assignment.enabled = True
        if assignment.bubbles != bubbles:
            assignment.bubbles = bubbles
        path = '/'.join(container.getPhysicalPath())
        get_assignments(storage[eventName]).insert(path)
开发者ID:EDRN,项目名称:edrnsite.policy,代码行数:17,代码来源:setuphandlers.py

示例9: apply_rule

def apply_rule(folder, event):
    """ Apply content rule to execute a transition from new to pending
    """
    name = "rule-transition-registration"
    storage = getUtility(IRuleStorage)

    # Assignment
    assignable = IRuleAssignmentManager(folder, None)
    if assignable is None:
        return

    assignment = assignable.get(name, None)
    if assignment is None:
        assignment = assignable[name] = RuleAssignment(name)
    assignment.enabled = True
    assignment.bubbles = False
    path = "/".join(folder.getPhysicalPath())
    get_assignments(storage[name]).insert(path)
开发者ID:pythonbrasil,项目名称:apyb.registration,代码行数:18,代码来源:registrations.py

示例10: assigned_rules

    def assigned_rules(self):
        assignable = IRuleAssignmentManager(self.context)
        storage = getUtility(IRuleStorage)
        events = self._events()

        assignments = []
        for key, assignment in assignable.items():
            rule = storage.get(key, None)
            if rule is not None:
                assignments.append(dict(id=key,
                                        title=rule.title,
                                        description=rule.description,
                                        trigger=events.get(rule.event, "Unknown"),
                                        url=self._rule_url(key),
                                        bubbles=assignment.bubbles,
                                        enabled=assignment.enabled,
                                        global_enabled=rule.enabled, ))
        return assignments
开发者ID:alecghica,项目名称:plone.app.contentrules,代码行数:18,代码来源:assignments.py

示例11: setup_contentrules_registration

def setup_contentrules_registration(registrations):
    assignable = IRuleAssignmentManager(registrations, None)
    if assignable is None:
        return None
    storage = getUtility(IRuleStorage)
    path = '/'.join(registrations.getPhysicalPath())
    names = [
        'registration-rule-transition',
        'registration-new',
        'registration-confirmed',
    ]
    for name in names:
        assignment = assignable.get(name, None)
        if assignment is None:
            assignment = assignable[name] = RuleAssignment(name)
        assignment.enabled = True
        assignment.bubbles = True

        get_assignments(storage[name]).insert(path)
开发者ID:pythonbrasil,项目名称:conference2013,代码行数:19,代码来源:setuphandlers.py

示例12: setup_contentrules_program

def setup_contentrules_program(program):
    assignable = IRuleAssignmentManager(program, None)
    if assignable is None:
        return None
    storage = getUtility(IRuleStorage)
    path = '/'.join(program.getPhysicalPath())
    names = [
        'talk-submited',
        'talk-accepted',
        'training-submited',
        'training-accepted',
    ]
    for name in names:
        assignment = assignable.get(name, None)
        if assignment is None:
            assignment = assignable[name] = RuleAssignment(name)
        assignment.enabled = True
        assignment.bubbles = True

        get_assignments(storage[name]).insert(path)
开发者ID:pythonbrasil,项目名称:conference2013,代码行数:20,代码来源:setuphandlers.py

示例13: __call__

    def __call__(self, event, bubbled=False, rule_filter=None):
        assignments = IRuleAssignmentManager(self.context)
        for rule in assignments.getRules(event, bubbled=bubbled):
            # for each rule assigned in this context - bubbled means rule apply on subfolders
            if rule_filter is None or rule_filter(self.context, rule, event) == True:
                # execute the rule if it is not filtered, for exemple,
                # it has not been executed on the same content but from an other context
                # in the same request

                # we store cascading option in the filter. if true, this will allow
                # rules to be executed because of the actions ran by this rule.
                if rule_filter is not None:
                    cascade_before = getattr(rule_filter, 'cascade', False)
                    rule_filter.cascade = rule.cascading

                executable = getMultiAdapter((self.context, rule, event), IExecutable)
                executable()

                if rule_filter is not None:
                    rule_filter.cascade = cascade_before

                if rule.stop:
                    # stop rule execution if 'Stop rules after' option has been selected
                    raise StopRule(rule)
开发者ID:plone,项目名称:plone.contentrules,代码行数:24,代码来源:executor.py

示例14: testAssignmentOrdering

 def testAssignmentOrdering(self):
     assignable = IRuleAssignmentManager(self.portal.news)
     self.assertEquals([u'test1'], assignable.keys())
开发者ID:Goldmund-Wyldebeast-Wunderliebe,项目名称:collective.contentrules.mail,代码行数:3,代码来源:test_configuration.py

示例15: TestRuleAssignmentMapping

class TestRuleAssignmentMapping(ContentRulesTestCase):

    def afterSetUp(self):
        self.folder.invokeFactory('Folder', 'f1')
        self.folder.f1.invokeFactory('Folder', 'f11')
        self.folder.f1.invokeFactory('Folder', 'f12')

        self.storage = getUtility(IRuleStorage)
        self.storage['r1'] = Rule()
        self.storage['r2'] = Rule()
        self.storage['r3'] = Rule()

        self.f11a = IRuleAssignmentManager(self.folder.f1.f11)
        self.f11a['r1'] = RuleAssignment('r1', bubbles=True)
        insert_assignment(self.storage['r1'],
                          '/'.join(self.folder.f1.f11.getPhysicalPath()))

        self.f12a = IRuleAssignmentManager(self.folder.f1.f12)
        self.f12a['r1'] = RuleAssignment('r1', bubbles=True)
        insert_assignment(self.storage['r1'],
                          '/'.join(self.folder.f1.f12.getPhysicalPath()))

        self.f12a['r2'] = RuleAssignment('r2', bubbles=True)
        insert_assignment(self.storage['r2'],
                          '/'.join(self.folder.f1.f12.getPhysicalPath()))

    def testRuleRemoved(self):
        self.assertTrue('r1' in self.f11a)
        self.assertTrue('r1' in self.f12a)

        del self.storage['r1']

        self.assertFalse('r1' in self.f11a)
        self.assertFalse('r1' in self.f12a)

    def testContainerMoved(self):
        f12path = '/'.join(self.folder.f1.f12.getPhysicalPath())
        self.assertTrue(f12path in get_assignments(self.storage['r1']))
        self.assertTrue(f12path in get_assignments(self.storage['r2']))

        transaction.savepoint(1)
        self.folder.f1.manage_renameObject('f12', 'f12a')
        f12apath = '/'.join(self.folder.f1.f12a.getPhysicalPath())

        self.assertFalse(f12path in get_assignments(self.storage['r1']))
        self.assertFalse(f12path in get_assignments(self.storage['r2']))

        self.assertTrue(f12apath in get_assignments(self.storage['r1']))
        self.assertTrue(f12apath in get_assignments(self.storage['r1']))

    def testParentOfContainerMoved(self):
        f12path = '/'.join(self.folder.f1.f12.getPhysicalPath())
        self.assertTrue(f12path in get_assignments(self.storage['r1']))
        self.assertTrue(f12path in get_assignments(self.storage['r2']))

        transaction.savepoint(1)
        self.folder.manage_renameObject('f1', 'f1a')
        f12apath = '/'.join(self.folder.f1a.f12.getPhysicalPath())

        self.assertFalse(f12path in get_assignments(self.storage['r1']))
        self.assertFalse(f12path in get_assignments(self.storage['r2']))

        self.assertTrue(f12apath in get_assignments(self.storage['r1']))
        self.assertTrue(f12apath in get_assignments(self.storage['r1']))

    def testContainerRemoved(self):
        f12path = '/'.join(self.folder.f1.f12.getPhysicalPath())
        self.assertTrue(f12path in get_assignments(self.storage['r1']))
        self.assertTrue(f12path in get_assignments(self.storage['r2']))

        transaction.savepoint(1)
        self.folder._delObject('f1')

        self.assertFalse(f12path in get_assignments(self.storage['r1']))
        self.assertFalse(f12path in get_assignments(self.storage['r2']))

    def testRuleAssignmentRemovedAPI(self):
        self.assertTrue('r1' in self.f11a)
        self.assertTrue('r1' in self.f12a)

        api.unassign_rule(self.folder.f1.f11, 'r1')

        self.assertFalse('r1' in self.f11a)
        self.assertTrue('r1' in self.f12a)

    def testRuleAssignmentEditedAPI(self):
        self.assertTrue(self.f11a['r1'].bubbles)
        self.assertTrue(self.f11a['r1'].enabled)

        api.edit_rule_assignment(self.folder.f1.f11, 'r1',
                                 bubbles=False, enabled=False)

        self.assertFalse(self.f11a['r1'].bubbles)
        self.assertFalse(self.f11a['r1'].enabled)

        api.edit_rule_assignment(self.folder.f1.f11, 'r1',
                                 bubbles=True, enabled=True)

        self.assertTrue(self.f11a['r1'].bubbles)
        self.assertTrue(self.f11a['r1'].enabled)
#.........这里部分代码省略.........
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:101,代码来源:test_rule_assignment_mapping.py


注:本文中的plone.contentrules.engine.interfaces.IRuleAssignmentManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。