本文整理汇总了Python中Products.CMFPlone.interfaces.ISelectableConstrainTypes类的典型用法代码示例。如果您正苦于以下问题:Python ISelectableConstrainTypes类的具体用法?Python ISelectableConstrainTypes怎么用?Python ISelectableConstrainTypes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ISelectableConstrainTypes类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_isMixedIn
def test_isMixedIn(self):
self.assertTrue(
isinstance(self.af, constraintypes.ConstrainTypesMixin),
"ConstrainTypesMixin was not mixed in to ATFolder")
self.assertTrue(
ISelectableConstrainTypes.providedBy(self.af),
"ISelectableConstrainTypes not implemented by ATFolder instance")
示例2: test_isMixedIn
def test_isMixedIn(self):
self.failUnless(isinstance(self.af,
constraintypes.ConstrainTypesMixin),
"ConstrainTypesMixin was not mixed in to ATFolder")
self.failUnless(ZopeTwoISelectableConstrainTypes.isImplementedBy(self.af),
"ISelectableConstrainTypes not implemented by ATFolder instance")
self.failUnless(ISelectableConstrainTypes.providedBy(self.af),
"ISelectableConstrainTypes not implemented by ATFolder instance")
示例3: FormContentAdapter
class FormContentAdapter(object):
def __init__(self, context):
self.context = ISelectableConstrainTypes(context)
@property
def constrain_types_mode(self):
return self.context.getConstrainTypesMode()
@property
def allowed_types(self):
return self.context.getLocallyAllowedTypes()
@property
def secondary_types(self):
immediately_addable = self.context.getImmediatelyAddableTypes()
return [t for t in self.context.getLocallyAllowedTypes()
if t not in immediately_addable]
示例4: testNonStructualFolderShowsParent
def testNonStructualFolderShowsParent(self):
self.folder.invokeFactory('Folder', 'folder1')
directlyProvides(self.folder.folder1, INonStructuralFolder)
constraints = ISelectableConstrainTypes(self.folder.folder1)
constraints.setConstrainTypesMode(1)
constraints.setLocallyAllowedTypes(('Document',))
constraints.setImmediatelyAddableTypes(('Document',))
actions = self.menu.getMenuItems(self.folder.folder1, self.request)
self.assertEqual(len(actions), 0)
示例5: testMoreNotIncludedWhenNotNecessary
def testMoreNotIncludedWhenNotNecessary(self):
constraints = ISelectableConstrainTypes(self.folder)
constraints.setConstrainTypesMode(1)
constraints.setLocallyAllowedTypes(('Document',))
constraints.setImmediatelyAddableTypes(('Document',))
actions = self.menu.getMenuItems(self.folder, self.request)
self.assertEqual(len(actions), 2)
self.assertEqual(actions[0]['extra']['id'], 'document')
self.assertEqual(actions[1]['extra']['id'], 'settings')
示例6: testMoreIncluded
def testMoreIncluded(self):
constraints = ISelectableConstrainTypes(self.folder)
constraints.setConstrainTypesMode(1)
constraints.setLocallyAllowedTypes(('Document', 'Image',))
constraints.setImmediatelyAddableTypes(('Document',))
actions = self.menu.getMenuItems(self.folder, self.request)
self.failIf('image' in [a['extra']['id'] for a in actions])
self.failUnless('document' in [a['extra']['id'] for a in actions])
self.failUnless('more' in [a['extra']['id'] for a in actions])
self.failUnless('settings' in [a['extra']['id'] for a in actions])
示例7: testAddMenuWithNothingToAddButWithAvailableMorePage
def testAddMenuWithNothingToAddButWithAvailableMorePage(self):
constraints = ISelectableConstrainTypes(self.folder)
constraints.setConstrainTypesMode(1)
constraints.setLocallyAllowedTypes(('Document',))
constraints.setImmediatelyAddableTypes(())
self.folder.manage_permission('Modify constrain types', ('Manager',))
setRoles(self.portal, TEST_USER_ID, ['Contributor'])
items = self.menu.getMenuItems(self.folder, self.request)
factoriesMenuItem = [i for i in items if
i['extra']['id'] == 'plone-contentmenu-factories'][0]
self.assertEqual(len(factoriesMenuItem['submenu']), 1)
self.assertEqual(factoriesMenuItem['submenu'][0]['extra']['id'],
'plone-contentmenu-more')
示例8: handleSave
def handleSave(self, action):
data, errors = self.extractData()
if errors:
return
immediately_addable_types = [t for t in data['current_prefer']
if t not in data['current_allow']]
locally_allowed_types = data['current_prefer']
aspect = ISelectableConstrainTypes(self.context)
aspect.setConstrainTypesMode(data['constrain_types_mode'])
aspect.setLocallyAllowedTypes(locally_allowed_types)
aspect.setImmediatelyAddableTypes(immediately_addable_types)
示例9: __call__
def __call__(self):
if hasattr(self.context.aq_base, CAROUSEL_ID):
carousel = getattr(self.context, CAROUSEL_ID)
else:
pt = getToolByName(self.context, 'portal_types')
newid = pt.constructContent(
type_name='Folder',
container=self.context,
id='carousel',
title='Carousel Banners'
)
carousel = getattr(self.context, newid)
# exclude the (Archetypes or Dexterity) folder from navigation
if hasattr(aq_base(carousel), 'setExcludeFromNav'):
carousel.setExcludeFromNav(True)
elif hasattr(aq_base(carousel), 'exclude_from_nav'):
carousel.exclude_from_nav = True
# mark the new folder as a Carousel folder
alsoProvides(carousel, ICarouselFolder)
# make sure Carousel banners are addable within the new folder
addPermissionsForRole(carousel, 'Manager',
('Carousel: Add Carousel Banner',))
addPermissionsForRole(carousel, 'Site Administrator',
('Carousel: Add Carousel Banner',))
addPermissionsForRole(carousel, 'Owner',
('Carousel: Add Carousel Banner',))
addPermissionsForRole(carousel, 'Contributor',
('Carousel: Add Carousel Banner',))
addPermissionsForRole(carousel, 'Editor',
('Carousel: Add Carousel Banner',))
# make sure *only* Carousel banners are addable
aspect = ISelectableConstrainTypes(carousel)
aspect.setConstrainTypesMode(1)
aspect.setLocallyAllowedTypes(['Carousel Banner'])
aspect.setImmediatelyAddableTypes(['Carousel Banner'])
carousel.reindexObject()
self.request.RESPONSE.redirect(
carousel.absolute_url() + '/@@edit-carousel'
)
示例10: handleSave
def handleSave(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
return
allowed_types = data['allowed_types']
immediately_addable = [
t for t in allowed_types
if t not in data['secondary_types']]
aspect = ISelectableConstrainTypes(self.context)
aspect.setConstrainTypesMode(data['constrain_types_mode'])
aspect.setLocallyAllowedTypes(allowed_types)
aspect.setImmediatelyAddableTypes(immediately_addable)
contextURL = self.context.absolute_url()
self.request.response.redirect(contextURL)
示例11: __init__
def __init__(self, context):
self.context = ISelectableConstrainTypes(context)
示例12: migrate_typerestriction
def migrate_typerestriction(self):
constraints = ISelectableConstrainTypes(self.new)
constraints.setConstrainTypesMode(ENABLED)
constraints.setImmediatelyAddableTypes(self.new_allowed)
constraints.setLocallyAllowedTypes(self.new_allowed)
示例13: __call__
def __call__(self, context):
constrain_aspect = ISelectableConstrainTypes(context)
items = []
for type_ in constrain_aspect.getDefaultAddableTypes():
items.append(SimpleTerm(value=type_.getId(), title=type_.Title()))
return SimpleVocabulary(items)
示例14: test_create_constraints
def test_create_constraints(self):
"""Test the constraints when creating content."""
from plone.api.exc import InvalidParameterError
from plone.api.exc import MissingParameterError
# This will definitely fail
with self.assertRaises(MissingParameterError):
api.content.create()
# Check the constraints for the type container
with self.assertRaises(MissingParameterError):
api.content.create(
type='Document',
id='test-doc',
)
# Check the constraints for the type parameter
container = mock.Mock()
with self.assertRaises(MissingParameterError):
api.content.create(
container=container,
id='test-doc',
)
# Check the constraints for id and title parameters
with self.assertRaises(MissingParameterError):
api.content.create(
container=container,
type='Document',
)
# Check the constraints for allowed types in the container
container = self.events
with self.assertRaises(InvalidParameterError):
api.content.create(
container=container,
type='foo',
id='test-foo',
)
# Check the constraints for allowed types in the container if
# the container is the portal
container = self.portal
with self.assertRaises(InvalidParameterError) as cm:
api.content.create(
container=container,
type='foo',
id='test-foo',
)
# Check if the underlying error message is included
# in the InvalidParameterError message
self.assertIn(
'No such content type: foo',
str(cm.exception),
)
# Check the constraints for allowed types in the container
# Create a folder
folder = api.content.create(
container=container,
type='Folder',
id='test-folder',
)
assert folder
# Constraint the allowed types
ENABLED = 1
if getattr(aq_base(folder), 'setConstrainTypesMode', None): # AT
folder.setConstrainTypesMode(ENABLED)
folder.setLocallyAllowedTypes(('News Item', ))
else: # DX
from Products.CMFPlone.interfaces import ISelectableConstrainTypes
constraints = ISelectableConstrainTypes(folder)
constraints.setConstrainTypesMode(ENABLED)
constraints.setLocallyAllowedTypes(('News Item', ))
with self.assertRaises(InvalidParameterError):
api.content.create(
container=folder,
type='Document',
id='test-doc',
)