[Product-Developers] Remove dashes from shortname - override choosename in namechooser.py?
l at lrowe.co.uk
Thu Jul 28 14:37:49 UTC 2011
Giacomo Spettoli wrote:
> Il 27/07/2011 20:34, imran.azad ha scritto:
>> I want to remove the dashes from the shortname of the object. In other
>> I want to remove all dashes in the id of an object. I have noticed there
>> a function in namechooser.py called chooseName which does the following:
>> name = getUtility(IURLNormalizer).normalize(name)
>> if I set the variable to:
>> name = name
>> It works! And the dashes aren't added. However this approach is modifying
>> the Plone Core :-(
>> I want to avoid doing this, I would rather like to override the
>> How can I do this from my class(custom content type using Dexterity)
>> Thank You
>> View this message in context:
>> Sent from the Product Developers mailing list archive at Nabble.com.
>> Product-Developers mailing list
>> Product-Developers at lists.plone.org
> you can customize the behaviour of name normalization by registering
> a local utility that implements IURLNormalizer interface.
> Read more here:
The IURLNormalizer utility is designed for normalizing non-ascii and unsafe
characters into something sensible (which is dependent on your language,
e.g. in German ü normalized to ue.) It is looked up on the request rather
than the context, so you probably want a custom INameFromTitle adapter
for an example dexterity behavior.
That example looks slightly complex because it uses __new__ to ensure that
INameFromTitle(object, None) returns None in the case that it can't
determine the primary field for an object, yours should probably just look
def __init__(self, context):
self.title = context.title.replace(' ', '')
View this message in context: http://plone.293351.n2.nabble.com/Remove-dashes-from-shortname-override-choosename-in-namechooser-py-tp6627262p6630087.html
Sent from the Product Developers mailing list archive at Nabble.com.
More information about the Product-Developers