Building a FAQ Content Type with ZClasses
How the 'FAQ' type on the dogbowl was built.
Overview
The zope-cmf mailing list had begun to compile a list of FAQs; I wanted to capture them on the dogbowl as content, and decided to make a simple ZClass to represent them.
Recipe
- In the
Control_Panel/Productsdirectory, add a product,CMF_FAQ. - In the new product, add a ZClass,
FAQ, withCMFCore.PortalContentandCMFDefault.DefaultDublinCoreImplas bases. - Delete the permission,
FAQ_permission. - Edit the factory,
FAQ_factory, setting the permission to "Add portal content". - In the ZClass,
FAQ, add a propertysheet,FAQ_properties. Add the following properties to it:-
faq_sections - a
tokensproperty; give it a default value of1 1. Making the section a tuple of seciton IDs makes sorting by section work well. -
faq_question - a
textproperty. -
faq_reply - a
textproperty. -
faq_urls - a
linesproperty. Each line will represent the URL of a resource (list posting, dogbowl document, etc.) related to the question.
-
- In the "Methods" tab of the ZClass, add a PythonScript,
Title. Its body should be:import string section = string.join( context.faq_sections, '.' ) return '%s %s' % ( section, context.faq_question ) - In your CMFSite's
portal_skins, add a new folder,faq_skins. To it, add the following methods:-
faq_view - (DTML Method or Page Template); a straightforward presentation of the FAQ's properties.
-
faq_edit_form - (DTML Method or Page Template); a straigtforward
interface for editing the FAQ's properties; posts to
faq_edit. -
faq_edit - (PythonScript); calls
manage_changePropertieson theFAQ_propertiespropertysheet of the FAQ, and redirects to thefaq_editview.
Add this folder to the skin search path of the
Basicskin (and/or others germane to your site). -
- In your CMFSite's
portal_typestool, add a new FactoryTypeInformation object,FAQ. Itsproductproperty should be set to "CMF_FAQ", and itsfactoryproperty to "FAQ_add". On its "Actions" tab, add the following actions:-
view - mapped to
faq_view. -
edit - mapped to
faq_edit_form. -
metadata - mapped to
metadata_edit_form.
-
You're done!
Installing the Product
Two files comprise the FAQ: