本文整理汇总了Python中plone.contentrules.engine.interfaces.IRuleAssignmentManager.keys方法的典型用法代码示例。如果您正苦于以下问题:Python IRuleAssignmentManager.keys方法的具体用法?Python IRuleAssignmentManager.keys怎么用?Python IRuleAssignmentManager.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.contentrules.engine.interfaces.IRuleAssignmentManager
的用法示例。
在下文中一共展示了IRuleAssignmentManager.keys方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from plone.contentrules.engine.interfaces import IRuleAssignmentManager [as 别名]
# 或者: from plone.contentrules.engine.interfaces.IRuleAssignmentManager import keys [as 别名]
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()
示例2: container_moved
# 需要导入模块: from plone.contentrules.engine.interfaces import IRuleAssignmentManager [as 别名]
# 或者: from plone.contentrules.engine.interfaces.IRuleAssignmentManager import keys [as 别名]
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)
示例3: container_removed
# 需要导入模块: from plone.contentrules.engine.interfaces import IRuleAssignmentManager [as 别名]
# 或者: from plone.contentrules.engine.interfaces.IRuleAssignmentManager import keys [as 别名]
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)
示例4: testAssignmentOrdering
# 需要导入模块: from plone.contentrules.engine.interfaces import IRuleAssignmentManager [as 别名]
# 或者: from plone.contentrules.engine.interfaces.IRuleAssignmentManager import keys [as 别名]
def testAssignmentOrdering(self):
assignable = IRuleAssignmentManager(self.portal.news)
self.assertEquals([u'test1'], assignable.keys())
开发者ID:Goldmund-Wyldebeast-Wunderliebe,项目名称:collective.contentrules.mail,代码行数:5,代码来源:test_configuration.py
示例5: TestRuleAssignmentMapping
# 需要导入模块: from plone.contentrules.engine.interfaces import IRuleAssignmentManager [as 别名]
# 或者: from plone.contentrules.engine.interfaces.IRuleAssignmentManager import keys [as 别名]
#.........这里部分代码省略.........
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)
def testRuleAssignmentAddedAPI(self):
api.assign_rule(self.folder.f1.f11, 'r2', enabled=True, bubbles=True)
self.assertTrue('r2' in self.f11a)
self.assertTrue(self.f11a['r2'].enabled)
self.assertTrue(self.f11a['r2'].bubbles)
api.assign_rule(self.folder.f1.f11, 'r3', enabled=True, bubbles=False,
insert_before='r2')
self.assertTrue('r3' in self.f11a)
self.assertTrue(self.f11a['r3'].enabled)
self.assertFalse(self.f11a['r3'].bubbles)
self.assertEqual(self.f11a.keys(), ['r1', 'r3', 'r2'])
示例6: TestRuleAssignmentMapping
# 需要导入模块: from plone.contentrules.engine.interfaces import IRuleAssignmentManager [as 别名]
# 或者: from plone.contentrules.engine.interfaces.IRuleAssignmentManager import keys [as 别名]
#.........这里部分代码省略.........
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)
def testRuleAssignmentAddedAPI(self):
api.assign_rule(self.folder.f1.f11, 'r2', enabled=True, bubbles=True)
self.assertTrue('r2' in self.f11a)
self.assertTrue(self.f11a['r2'].enabled)
self.assertTrue(self.f11a['r2'].bubbles)
api.assign_rule(self.folder.f1.f11, 'r3', enabled=True, bubbles=False,
insert_before='r2')
self.assertTrue('r3' in self.f11a)
self.assertTrue(self.f11a['r3'].enabled)
self.assertFalse(self.f11a['r3'].bubbles)
self.assertEqual(self.f11a.keys(), ['r1', 'r3', 'r2'])
示例7: _initRules
# 需要导入模块: from plone.contentrules.engine.interfaces import IRuleAssignmentManager [as 别名]
# 或者: from plone.contentrules.engine.interfaces.IRuleAssignmentManager import keys [as 别名]
#.........这里部分代码省略.........
else:
# Clear out conditions and actions since we're expecting new ones
del rule.conditions[:]
del rule.actions[:]
rule.title = child.getAttribute('title')
rule.description = child.getAttribute('description')
event_name = child.getAttribute('event')
rule.event = _resolveDottedName(event_name)
if not rule.event:
raise ImportError("Can not import %s" % event_name)
rule.enabled = as_bool(child.getAttribute('enabled'), True)
rule.stop = as_bool(child.getAttribute('stop-after'))
# Aq-wrap to enable complex setters for elements below
# to work
rule = rule.__of__(site)
for rule_config_node in child.childNodes:
if rule_config_node.nodeName == 'conditions':
for condition_node in rule_config_node.childNodes:
if not condition_node.nodeName == 'condition':
continue
type_ = condition_node.getAttribute('type')
element_type = getUtility(IRuleCondition, name=type_)
if element_type.factory is None:
continue
condition = element_type.factory()
# Aq-wrap in case of complex setters
condition = condition.__of__(rule)
handler = IRuleElementExportImportHandler(condition)
handler.import_element(condition_node)
rule.conditions.append(aq_base(condition))
elif rule_config_node.nodeName == 'actions':
for action_node in rule_config_node.childNodes:
if not action_node.nodeName == 'action':
continue
type_ = action_node.getAttribute('type')
element_type = getUtility(IRuleAction, name=type_)
if element_type.factory is None:
continue
action = element_type.factory()
# Aq-wrap in case of complex setters
action = action.__of__(rule)
handler = IRuleElementExportImportHandler(action)
handler.import_element(action_node)
rule.actions.append(aq_base(action))
elif child.nodeName == 'assignment':
location = child.getAttribute('location')
if location.startswith("/"):
location = location[1:]
try:
container = site.unrestrictedTraverse(str(location))
except KeyError:
continue
assignable = IRuleAssignmentManager(container, None)
if assignable is None:
continue
name = child.getAttribute('name')
assignment = assignable.get(name, None)
if assignment is None:
assignment = assignable[name] = RuleAssignment(name)
assignment.enabled = as_bool(child.getAttribute('enabled'))
assignment.bubbles = as_bool(child.getAttribute('bubbles'))
insert_before = child.getAttribute('insert-before')
if insert_before:
position = None
keys = list(assignable.keys())
if insert_before == "*":
position = 0
elif insert_before in keys:
position = keys.index(insert_before)
if position is not None:
keys.remove(name)
keys.insert(position, name)
assignable.updateOrder(keys)
path = '/'.join(container.getPhysicalPath())
get_assignments(storage[name]).insert(path)
示例8: testAssignmentOrdering
# 需要导入模块: from plone.contentrules.engine.interfaces import IRuleAssignmentManager [as 别名]
# 或者: from plone.contentrules.engine.interfaces.IRuleAssignmentManager import keys [as 别名]
def testAssignmentOrdering(self):
assignable = IRuleAssignmentManager(self.portal.news)
self.assertEqual(set([u'test3', u'test2', u'test1']), set(assignable.keys()))
示例9: __call__
# 需要导入模块: from plone.contentrules.engine.interfaces import IRuleAssignmentManager [as 别名]
# 或者: from plone.contentrules.engine.interfaces.IRuleAssignmentManager import keys [as 别名]
def __call__(self):
context = aq_inner(self.context)
request = aq_inner(self.request)
form = request.form
path = '/'.join(context.getPhysicalPath())
status = IStatusMessage(self.request)
assignable = IRuleAssignmentManager(context)
storage = getUtility(IRuleStorage)
operation = request.get('operation', None)
if operation == 'move_up':
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':
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')
assignable[rule_id] = RuleAssignment(rule_id)
get_assignments(storage[rule_id]).insert(path)
elif 'form.button.Delete' in form:
rule_ids = form.get('rule_ids', ())
for r in rule_ids:
del assignable[r]
get_assignments(storage[r]).remove(path)
status.addStatusMessage(_(u"Assignments deleted."), type='info')
elif 'form.button.Enable' in form:
rule_ids = form.get('rule_ids', ())
for r in rule_ids:
assignment = assignable.get(r, None)
if assignment is not None:
assignment.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:
assignment = assignable.get(r, None)
if assignment is not None:
assignment.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:
assignment = assignable.get(r, None)
if assignment is not None:
assignment.bubbles = 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:
assignment = assignable.get(r, None)
if assignment is not None:
assignment.bubbles = False
status.addStatusMessage(_(u"Changes saved."), type='info')
return self.template()