At the Forge - CMF Types
The easiest way to create a new CMF type is to base it on an existing type with the Web-based CMF type creation tool. This method does not allow you to modify the fields or methods associated with a type, but it does let you change the permissions associated with the type's actions, whether the type can be discussed and even the way in which this data type is displayed.
For example, go to the portal_types tool and choose Factory-based type information from the Select type to add... menu in the top-right corner. You are prompted for two pieces of information, the ID or name of the new type and the existing type on which it should be based. We are creating the ATFDocument, which means we are basing ourselves on CMF Default: Document.
Once you create the new type, it is available and visible from all of the type listings, including the types tool and the contents view in which you create a new instance of a type. Indeed, anyone with administrative privileges on the portal can now see your new ATFDocument type in the menu of options from which they can choose a new type to create.
What's the point of doing this, if ATFDocument and Document are the same? Well, they're not exactly the same; rather, they share methods and an overall class definition. Other information about this type, such as properties, permissions and skins, default to be the same as Document, but they can be made to look quite different. This means that if you want instances of Document to be displayed in black-on-white text without discussions and ATFDocument to be displayed in yellow-on-maroon text with discussions, you can do that quickly and easily with this method. And, if and when you upgrade your copy of CMF, ATFDocument will be updated automatically, along with Document.
Of course, there will be times when you want to create a type that has fields or behavior significantly different from an existing type. Several options exist for doing this, but the most flexible (and challenging and poorly documented) method is to create a new Zope product that adheres to CMF rules. For example, all Python packages must contain an __init__.py file in the package's root directory. This file may be empty, or it may contain statements that are evaluated when the package is first loaded into memory. In the case of a product, __init__.py is where the class is first registered into Zope by use of the initialize() method, which takes a single argument commonly called context. A bare-bones Zope product thus has an __init__.py that looks something like the following mythical MyProduct:
import MyProduct def initialize(context): context.registerClass( MyProduct.MyProduct, constructors=(MyProduct.manage_addMyProductForm, MyProduct.manage_addMyProduct) )
When Zope starts up, it looks through the products and invokes the initialize() method with an appropriate context. Context is part of Zope's system of acquisition, in which an object's attributes are defined by its location in the hierarchy as well as by its class definition. In the above example, MyProduct registers itself with two constructors, the methods manage_addMyProductForm and manage_addMyProduct.
A CMF type must register itself not only with Zope but also with CMF, so it can appear in the various CMF tools. Our product's initialize() method thus needs to include CMF-specific registration, which means that __init__.py needs to import modules from CMF. Moreover, every type in CMF must register itself with one of the CMF-specific initialization routines in Products.CMFCore.utils. For example, __init__.py from CMFDefault, which comes with CMF, first defines the different classes it will register:
contentClasses = ( Document.Document , File.File , Image.Image , Link.Link , Favorite.Favorite , NewsItem.NewsItem , SkinnedFolder.SkinnedFolder )
It then defines the constructor for each of the classes:
contentConstructors = \ ( Document.addDocument , File.addFile , Image.addImage , Link.addLink , Favorite.addFavorite , NewsItem.addNewsItem , SkinnedFolder.addSkinnedFolder )
And, of course, every type can have its own specific tool:
tools = ( DiscussionTool.DiscussionTool , MembershipTool.MembershipTool , RegistrationTool.RegistrationTool , PropertiesTool.PropertiesTool , URLTool.URLTool , MetadataTool.MetadataTool , SyndicationTool.SyndicationTool )
Finally, the initialize() method, abbreviated slightly here, within the package registers these classes using CMF with utils.ToolInit(), for tools, or ContentInit, for content. It then invokes initialize(context) on what it receives back, thus registering the new object with Zope:
def initialize( context ): utils.ToolInit('CMFDefault Tool', tools=tools, product_name='CMFDefault', icon='tool.gif', ).initialize( context ) utils.ContentInit( 'CMFDefault Content' , content_types=contentClasses , permission=AddPortalContent , extra_constructors=contentConstructors , fti=Portal.factory_type_information ).initialize( context ) context.registerClass(Portal.CMFSite, constructors=(Portal.manage_addCMFSiteForm, Portal.manage_addCMFSite, ))
|Designing Electronics with Linux||May 22, 2013|
|Dynamic DNS—an Object Lesson in Problem Solving||May 21, 2013|
|Using Salt Stack and Vagrant for Drupal Development||May 20, 2013|
|Making Linux and Android Get Along (It's Not as Hard as It Sounds)||May 16, 2013|
|Drupal Is a Framework: Why Everyone Needs to Understand This||May 15, 2013|
|Home, My Backup Data Center||May 13, 2013|
- Nice article, thanks for the
1 hour 13 min ago
- I once had a better way I
6 hours 59 min ago
- Not only you I too assumed
7 hours 17 min ago
- another very interesting
9 hours 10 min ago
- Reply to comment | Linux Journal
11 hours 3 min ago
- Reply to comment | Linux Journal
17 hours 57 min ago
- Reply to comment | Linux Journal
18 hours 13 min ago
- Favorite (and easily brute-forced) pw's
20 hours 5 min ago
- Have you tried Boxen? It's a
1 day 1 hour ago
- seo services in india
1 day 6 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi
It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?