On-creation File Extensions for Certain Types
=============================================

To better interact with Windows, which recognizes files by extension,
certain types are given a file extension::

  >>> from Products.CMFCore.utils import getToolByName

  >>> props = getToolByName(self.portal, 'portal_properties')
  >>> desktop = getToolByName(props, 'plone_desktop_uri')
  >>> desktop.manage_changeProperties(filename_normalization=True)
  >>> desktop.manage_changeProperties(relaxed_normalization=False)

  >>> context = self.portal
  >>> name = context.createObject(type_name="Link")
  >>> o = context.restrictedTraverse(name[name.index('portal_factory'):name.rindex('/')])
  >>> o.setTitle("This is a title")
  >>> o.markCreationFlag()
  >>> o.processForm()
  >>> o
  <ATLink at /plone/portal_factory/Link/this-is-a-title.url...>

It is also done with Page::

  >>> name = context.createObject(type_name="Document")
  >>> o = context.restrictedTraverse(name[name.index('portal_factory'):name.rindex('/')])
  >>> o.setTitle("I am a Document, short and stout")
  >>> o.markCreationFlag()
  >>> o.processForm()
  >>> o
  <ATDocument at /plone/portal_factory/Document/i-am-a-document-short-and-stout.html...>

and Event::

  >>> name = context.createObject(type_name="Event")
  >>> o = context.restrictedTraverse(name[name.index('portal_factory'):name.rindex('/')])
  >>> o.setTitle("Rennaisance Festival")
  >>> o.markCreationFlag()
  >>> o.processForm()
  >>> o
  <ATEvent at /plone/portal_factory/Event/rennaisance-festival.ics...>

(with different extensions, naturally.) The examples don't carry all
the way through to making the object concrete, but that's simply a
matter of 'doCreate', which is performed by content_edit, along with
'processForm'.

Of course, extensions are not added if there already is one::

  >>> name = context.createObject(type_name="Document")
  >>> o = context.restrictedTraverse(name[name.index('portal_factory'):name.rindex('/')])
  >>> o.setTitle("iexist.html")
  >>> o.markCreationFlag()
  >>> o.processForm()
  >>> o
  <ATDocument at /plone/portal_factory/Document/iexist.html...>

Only these types are given extensions::

  >>> name = context.createObject(type_name="File")
  >>> o = context.restrictedTraverse(name[name.index('portal_factory'):name.rindex('/')])
  >>> o.setTitle("I'm a file")
  >>> o.markCreationFlag()
  >>> o.processForm()
  >>> o
  <ATFile at /plone/portal_factory/File/...-a-file...>

This is done through monkey patching of the Archetypes method
'_renameAfterCreation' in the 'extensionRename' module.

Even if normalization is disabled at the Enfold Desktop level, the
default Plone normalization of Title to ID should still happen:

  >>> desktop.manage_changeProperties(filename_normalization=False)

  >>> context = self.portal
  >>> name = context.createObject(type_name="Link")
  >>> o = context.restrictedTraverse(name[name.index('portal_factory'):name.rindex('/')])
  >>> o.setTitle("Controle de qualidade")
  >>> o.markCreationFlag()
  >>> o.processForm()
  >>> o
  <ATLink at /plone/portal_factory/Link/controle-de-qualidade.url...>
