Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
plone.app.portlets.storage.PortletsNameChooser Class Reference
Inheritance diagram for plone.app.portlets.storage.PortletsNameChooser:
Inheritance graph
[legend]
Collaboration diagram for plone.app.portlets.storage.PortletsNameChooser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def chooseName

Public Attributes

 context

Detailed Description

A name chooser for portlets

Definition at line 70 of file storage.py.


Constructor & Destructor Documentation

Definition at line 76 of file storage.py.

00076 
00077     def __init__(self, context):
00078         self.context = context

Here is the caller graph for this function:


Member Function Documentation

def plone.app.portlets.storage.PortletsNameChooser.chooseName (   self,
  name,
  object 
)
Choose a name based on a the portlet title

>>> from plone.app.portlets.storage import PortletAssignmentMapping
>>> mapping = PortletAssignmentMapping()

>>> from zope.app.container.interfaces import INameChooser
>>> chooser = INameChooser(mapping)

>>> from plone.app.portlets.portlets import base
>>> class DummyAssignment(base.Assignment):
...     title = u""

>>> dummy = DummyAssignment()
>>> dummy.title = u"A test title"

>>> chooser.chooseName(None, dummy)
'a-test-title'

>>> chooser.chooseName(None, dummy)
'a-test-title'

>>> mapping[u'a-test-title'] = dummy
>>> chooser.chooseName(None, dummy)
'a-test-title-1'

>>> dummy.title = 'RSS: http://plone.org'
>>> chooser.chooseName(None, dummy)
'RSS-http-plone.org'

>>> dummy.title = None
>>> chooser.chooseName(None, dummy)
'dummyassignment'

>>> mapping[u'dummyassignment'] = dummy
>>> delattr(dummy, 'title')
>>> chooser.chooseName(None, dummy)
'dummyassignment-1'

Definition at line 79 of file storage.py.

00079 
00080     def chooseName(self, name, object):
00081         """Choose a name based on a the portlet title
00082         
00083         >>> from plone.app.portlets.storage import PortletAssignmentMapping
00084         >>> mapping = PortletAssignmentMapping()
00085         
00086         >>> from zope.app.container.interfaces import INameChooser
00087         >>> chooser = INameChooser(mapping)
00088         
00089         >>> from plone.app.portlets.portlets import base
00090         >>> class DummyAssignment(base.Assignment):
00091         ...     title = u""
00092         
00093         >>> dummy = DummyAssignment()
00094         >>> dummy.title = u"A test title"
00095         
00096         >>> chooser.chooseName(None, dummy)
00097         'a-test-title'
00098         
00099         >>> chooser.chooseName(None, dummy)
00100         'a-test-title'
00101         
00102         >>> mapping[u'a-test-title'] = dummy
00103         >>> chooser.chooseName(None, dummy)
00104         'a-test-title-1'
00105         
00106         >>> dummy.title = 'RSS: http://plone.org'
00107         >>> chooser.chooseName(None, dummy)
00108         'RSS-http-plone.org'
00109         
00110         >>> dummy.title = None
00111         >>> chooser.chooseName(None, dummy)
00112         'dummyassignment'
00113         
00114         >>> mapping[u'dummyassignment'] = dummy
00115         >>> delattr(dummy, 'title')
00116         >>> chooser.chooseName(None, dummy)
00117         'dummyassignment-1'
00118         
00119         
00120         """
00121         container = self.context
00122 
00123         if not name:
00124             name = getattr(object, 'title', None)
00125 
00126         if not name:
00127             name = object.__class__.__name__
00128             
00129         name = getUtility(IIDNormalizer).normalize(name)
00130 
00131         i = 0
00132         new_name = name
00133         while new_name in container and i <= ATTEMPTS:
00134             i += 1
00135             new_name = "%s-%d" % (name, i)
00136             
00137         self.checkName(new_name, object)
        return new_name

Here is the call graph for this function:


Member Data Documentation

Definition at line 77 of file storage.py.


The documentation for this class was generated from the following file: