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


Python INameChooser.checkName方法代码示例

本文整理汇总了Python中zope.container.interfaces.INameChooser.checkName方法的典型用法代码示例。如果您正苦于以下问题:Python INameChooser.checkName方法的具体用法?Python INameChooser.checkName怎么用?Python INameChooser.checkName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zope.container.interfaces.INameChooser的用法示例。


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

示例1: test_checkName

# 需要导入模块: from zope.container.interfaces import INameChooser [as 别名]
# 或者: from zope.container.interfaces.INameChooser import checkName [as 别名]
 def test_checkName(self):
     namechooser = INameChooser(self.activities)
     normalizer = getUtility(IURLNormalizer)
     obj = createContent(
         'upfront.assessmentitem.content.assessmentitem')
     test_name = normalizer.normalize('Q001')
     self.assertEqual(namechooser.checkName(test_name, obj), True)
     obj = createContentInContainer(self.activities,
         'upfront.assessmentitem.content.assessmentitem')
     self.assertEqual(namechooser.checkName(test_name, obj), False)
开发者ID:upfrontsystems,项目名称:tarmii.theme,代码行数:12,代码来源:test_namechooser.py

示例2: addContentToContainer

# 需要导入模块: from zope.container.interfaces import INameChooser [as 别名]
# 或者: from zope.container.interfaces.INameChooser import checkName [as 别名]
def addContentToContainer(container, object, checkConstraints=True):
    """Copy of plone.dexterity.util.addContentToContainer.
    Modified to check the existing Id on the object before paving over it.
    """
    if not hasattr(aq_base(object), "portal_type"):
        raise ValueError("object must have its portal_type set")

    container = aq_inner(container)
    if checkConstraints:
        container_fti = container.getTypeInfo()

        fti = getUtility(IDexterityFTI, name=object.portal_type)
        if not fti.isConstructionAllowed(container):
            raise Unauthorized("Cannot create %s" % object.portal_type)

        if container_fti is not None and \
                not container_fti.allowType(object.portal_type):
            raise ValueError(
                "Disallowed subobject type: %s" % object.portal_type
            )

    chooser = INameChooser(container)
    if hasattr(object, 'id') and chooser.checkName(object.id, object):
        name = object.id
    else:
        name = INameChooser(container).chooseName(None, object)
        object.id = name

    newName = container._setObject(name, object)
    return container._getOb(newName)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:32,代码来源:setuphandlers.py

示例3: validateActionFields

# 需要导入模块: from zope.container.interfaces import INameChooser [as 别名]
# 或者: from zope.container.interfaces.INameChooser import checkName [as 别名]
    def validateActionFields(self, cat_name, data, allow_dup=False):
        """Check action fields on validity"""
        errors = {}

        if allow_dup:
            # create dummy category to avoid id
            # duplication during action update
            category = ActionCategory(cat_name)
        else:
            # get or create (if necessary) actions category
            category = self.getOrCreateCategory(cat_name)

        # validate action id
        chooser = INameChooser(category)
        try:
            chooser.checkName(data['id'], self.context)
        except Exception, e:
            errors['id'] = self._formatError(e, **{'id': data['id']})
开发者ID:kroman0,项目名称:products,代码行数:20,代码来源:plonetabs.py

示例4: add_site_record

# 需要导入模块: from zope.container.interfaces import INameChooser [as 别名]
# 或者: from zope.container.interfaces.INameChooser import checkName [as 别名]
    def add_site_record(self, site_record):
        orig_name = site_record.id
        chooser = INameChooser(self)
        try:
            chooser.checkName(orig_name, site_record)
        except KeyError:
            # the name already exists, no problem, we're just going to 
            # increment it anyway
            pass
        except (TypeError, ValueError):
            msg = "%s is not useable as a name for a site record" % orig_name
            raise ValueError(msg)

        name = chooser.chooseName(orig_name, site_record)
        checkObject(self, name, site_record)
        site_record.id = name
        self[name] = site_record
        return name
开发者ID:eleddy,项目名称:eastofeaton.pay2plone,代码行数:20,代码来源:utility.py

示例5: normalize

# 需要导入模块: from zope.container.interfaces import INameChooser [as 别名]
# 或者: from zope.container.interfaces.INameChooser import checkName [as 别名]
    def normalize(self, item, max_length, parent_path):
        title = item['effective_title']

        if not isinstance(title, unicode):
            title = title.decode('utf-8')

        # Use URLNormalizer to get locale-dependent transcriptions,
        # and IDNormalizer to get lowercased, ID-safe values.
        normalized_id = self.normalizer.normalize(title, max_length=max_length)
        normalized_id = self.id_normalizer.normalize(
            normalized_id, max_length=max_length)

        # Avoid id conflicts
        parent = traverse(self.context, parent_path)
        chooser = INameChooser(parent)
        if not chooser.checkName(title.encode('utf-8'), parent):
            # namechooser expect the object itself as second paremter, but it's
            # only used for getting the request, therefore we use the parent.
            normalized_id = INameChooser(parent).chooseName(
                normalized_id, parent)

        return normalized_id
开发者ID:4teamwork,项目名称:opengever.core,代码行数:24,代码来源:reference.py


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