Back to index

plone3  3.1.7
namechooser.py
Go to the documentation of this file.
00001 from zope.interface import implements
00002 
00003 from zope.app.container.interfaces import INameChooser
00004 from zope.app.container.contained import NameChooser
00005 
00006 ATTEMPTS = 10000
00007 
00008 class RuleNameChooser(NameChooser):
00009     """A name chooser for content rules.
00010     """
00011     
00012     implements(INameChooser)
00013     
00014     def __init__(self, context):
00015         self.context = context
00016 
00017     def chooseName(self, name, object):
00018         container = self.context
00019 
00020         if not name:
00021             name = object.__class__.__name__.lower()
00022 
00023         i = 1
00024         new_name = "%s-%d" % (name, i)
00025         while new_name in container and i <= ATTEMPTS:
00026             i += 1
00027             new_name = "%s-%d" % (name, i)
00028             
00029         self.checkName(new_name, object)
00030         return new_name