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/Products
directory, add a product,CMF_FAQ
. - In the new product, add a ZClass,
FAQ
, withCMFCore.PortalContent
andCMFDefault.DefaultDublinCoreImpl
as 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
tokens
property; give it a default value of1 1
. Making the section a tuple of seciton IDs makes sorting by section work well. -
faq_question
- a
text
property. -
faq_reply
- a
text
property. -
faq_urls
- a
lines
property. 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_changeProperties
on theFAQ_properties
propertysheet of the FAQ, and redirects to thefaq_edit
view.
Add this folder to the skin search path of the
Basic
skin (and/or others germane to your site). -
- In your CMFSite's
portal_types
tool, add a new FactoryTypeInformation object,FAQ
. Itsproduct
property should be set to "CMF_FAQ", and itsfactory
property 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: