A pattern for programatically creating Plone content
I'm importing content from a legacy system to a new website that I'm doing with Plone 4 (wow! what an improvement, in speed and technology) and was looking at the existing documentation on how to programatically create new Plone content. The issue I'm having with the existing documentation is that it's incomplete. It won't give you automatically created ids, you'll have to manually call mutators if you don't know any better, etc.
This is what I have come up with (this code runs in a browser view):
_id = self.context.generateUniqueId("Document") _id = self.context.invokeFactory(type_name=type_name, id=_id) ob = self.context[_id] ob.edit( description = "text...", subject = ('tag1', 'tag2'), title = "some title...", ) ob._renameAfterCreation(check_auto_id=True) _id = ob.getId()
One thing I notice is that Plone 4 starts faster, comes with easily pluggable developer tools, and in general feels a lot more polished then any previous Plone releases. It's a good system to work with.
Previous: A miniguide to Dolmen packages