Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions
plone.app.content.namechooser.NormalizingNameChooser Class Reference

List of all members.

Public Member Functions

def __init__
def checkName
def chooseName

Public Attributes

 context

Private Member Functions

def _findUniqueName
def _getCheckId
def _getCharset

Detailed Description

A name chooser for a Zope object manager.

If the object is adaptable to or provides INameFromTitle, use the
title to generate a name.

Definition at line 16 of file namechooser.py.


Constructor & Destructor Documentation

Definition at line 25 of file namechooser.py.

00025 
00026     def __init__(self, context):
00027         self.context = context

Here is the caller graph for this function:


Member Function Documentation

def plone.app.content.namechooser.NormalizingNameChooser._findUniqueName (   self,
  name,
  object 
) [private]
Find a unique name in the parent folder, based on the given id, by
appending -n, where n is a number greater than 1, or just the id if
it's ok.

Definition at line 57 of file namechooser.py.

00057 
00058     def _findUniqueName(self, name, object):
00059         """Find a unique name in the parent folder, based on the given id, by
00060         appending -n, where n is a number greater than 1, or just the id if
00061         it's ok.
00062         """
00063         check_id = self._getCheckId(object)
00064 
00065         if not check_id(name, required=1):
00066             return name
00067 
00068         idx = 1
00069         while idx <= ATTEMPTS:
00070             new_name = "%s-%d" % (name, idx)
00071             if not check_id(new_name, required=1):
00072                 return new_name
00073             idx += 1
00074 
00075         raise ValueError("Cannot find a unique name based on %s after %d attemps." % (name, ATTEMPTS,))
        

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the site default charset, or utf-8.

Definition at line 86 of file namechooser.py.

00086 
00087     def _getCharset(self, object):
00088         """Returns the site default charset, or utf-8.
00089         """
00090         properties = queryUtility(IPropertiesTool)
00091         if properties is not None:
00092             site_properties = getattr(properties, 'site_properties', None)
00093             if site_properties is not None:
00094                 return site_properties.getProperty('default_charset', 'utf-8')
00095         return 'utf-8'

Here is the caller graph for this function:

Return a function that can act as the check_id script.

Definition at line 76 of file namechooser.py.

00076 
00077     def _getCheckId(self, object):
00078         """Return a function that can act as the check_id script.
00079         """
00080         check_id = getattr(object, 'check_id', None)
00081         if check_id is None:
00082             parent = aq_inner(self.context)
00083             parent_ids = parent.objectIds()
00084             check_id = lambda id, required: id in parent_ids
00085         return check_id
        

Here is the caller graph for this function:

Definition at line 28 of file namechooser.py.

00028 
00029     def checkName(self, name, object):
00030         return not self._getCheckId(object)(name, required=1)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 31 of file namechooser.py.

00031 
00032     def chooseName(self, name, object):
00033         container = aq_inner(self.context)
00034         if not name:
00035             nameFromTitle = INameFromTitle(object, None)
00036             if nameFromTitle is not None:
00037                 name = nameFromTitle.title
00038             if not name:
00039                 name = getattr(aq_base(object), 'id', None)
00040             if not name:
00041                 name = getattr(aq_base(object), 'portal_type', None)
00042             if not name:
00043                 name = object.__class__.__name__
00044 
00045         if not isinstance(name, unicode):
00046             charset = self._getCharset(object)
00047             name = unicode(name, charset)
00048 
00049         request = getattr(object.__of__(container), 'REQUEST', None)
00050         if request is not None:
00051             name = IUserPreferredURLNormalizer(request).normalize(name)
00052         else:
00053             name = getUtility(IURLNormalizer).normalize(name)
00054             
00055         return self._findUniqueName(name, object)
00056             

Here is the call graph for this function:


Member Data Documentation

Definition at line 26 of file namechooser.py.


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