34,79 €
The Plone Content Management System is one of the best open source CMS, because by using Plone's development framework you can extend its functionality according to the specific requirements of your website. The Plone framework has lots of components that can be used to create add-ons or extensions called Plone Products. You can optimize your site for improved usability, accessibility, and security by creating custom Plone products.This book covers recipes that will help you create custom Plone Products and implement them on your website. Every topic covered in this book is accompanied by essential fundamentals and step-by-step explanation that will help you understand it better. With the help of this book you will be able to create custom Plone products that are well suited for your website.You can read the whole book or just pick recipes relevant for you; cross references help you understand the recipes even if you do not read them in order.If you work through the book in order, you will start by setting up an example project of a news website that will be developed throughout the book. You will learn about all of the necessary tools a Plone developer must have before starting any project. You will develop the website further by detecting problems and debugging them. You will be able to modify code on-the-fly or get help on how to do some tasks by installing and using special tools such as IPython, ipdb, and PDBDebugMode. You will then create a new content type, based on an existing one, and wrap the final product into a Python egg.You will set up automated testing to prevent errors in code that have evolved in the development stage. You will use paster to automatically create a new custom content type from scratch. You will improve the performance of your application by creating lightweight content types and following other recipes covered in this book. Key features such as usability, internationalization, accessibility and security are covered to make sure that your development and customizations will be at the level of Plone core and its most remarkable add-on products.You will improve your user interface by creating simple client-side visual changes and server-side manipulation of objects. You will learn to create and manage portlets by using Portlet manager and customize your website by modifying third-party products. Finally you will learn to communicate with an external non-Python-based system and make your products available for future use.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 381
Veröffentlichungsjahr: 2010
Copyright © 2010 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: May 2010
Production Reference: 1300410
Published by Packt Publishing Ltd.
32 Lincoln Road
Olton
Birmingham, B27 6PA, UK.
ISBN 978-1-847196-72-9
www.packtpub.com
Cover Image by Vinayak Chittar (<[email protected]>)
Authors
Juan Pablo Giménez
Marcos F. Romero
Reviewers
Martin Aspeli
Alec Mitchell
Emanuel Sartor
Acquisition Editor
Rashmi Phadnis
Development Editor
Reshma Sundaresan
Technical Editor
Pallavi Kachare
Copy Editor
Lakshmi Menon
Indexer
Hemangini Bari
Editorial Team Leader
Akshara Aware
Project Team Leader
Priya Mukherji
Project Coordinator
Prasad Rai
Proofreader
Kevin McGowan
Graphics
Geetanjali Sawant
Production Coordinator
Shantanu Zagade
Cover Work
Shantanu Zagade
Juan Pablo Giménez's programming career started in 1996. He was a C/C++ programmer in real-time systems under the QNX OS, but quickly the philosophy of Linux and free software became more and more interesting for him as he became a sysadmin and a PHP programmer. In 2000 he began his own company, Rcom, through which he has provided IT services using FOSS tools to cover a wide range of languages and technologies. Despite having gone through abundant experience with other languages and CMS frameworks, today he focuses totally on developing products and sites under Plone.
I want to thank my family, my parents, my sister, and especially my grandmother Chola, for years of support and understanding while I sojourned in the-for them-incomprehensible world of programming.
Thanks to my best friends and associates in Rcom, Juan Pablo Noriega, Roman Mottino, Eugenio Oliveri, and Leandro Viani.
Thanks to Emanuel Sartor and the Plone community for always being there to help me in my learning process.
And thanks, Laura, for putting up with me and my crazy passions; without you, it would not have been possible for me to reach this far; thank you also for bringing to life Julieta and Sofia, the joy of my days.
Marcos F. Romero has been a software developer since 1997, working with Lotus Notes, both to develop applications, and as a trainer of users and other developers.
In 1999, he launched his first web site, after which he specialized in HTML, CSS, JavaScript, and DOM among other technologies.
Since then he has taken part in numerous other web sites and webapps—including a Lotus Notes CMS—and started working as a consultant to other professionals.
In 2007, he started to participate in Plone projects and became fascinated by the Open Source world.
For over 10 years he has been interested in Usability as a discipline applicable to everyday activities and, focused on the customer's and end user's needs, he aims to simplify and help their everyday tasks. Today he actively applies this concept in Inter-Cultura, a company that specializes in Usability and User Experience, where he has been working for several years.
All my appreciation to Gonzalo J. Auza, who ushered me into the world of Plone and who has supported me all along. A big thanks to Juan Pablo Giménez, who can't but continue to teach me; and to Martin Aspeli, Alec Mitchell, and Emanuel Sartor, who kindly agreed to share their knowledge by reviewing this book.
My gratitude to Rebeca Resnik, my English teacher, who has a lot to do with this endeavour.
A special thanks to my family and friends—especially to my parents—who phoned me continually for updates on my progress towards completion of this book.
But most of all, thanks to my wife, who lovingly did more than her share with our kids, buying me the time and quiet to complete this book.
Alec Mitchell is a Plone core developer and has been an active member of the Plone community since 2004. He was the release manager for Plone 2.5, a member of both the inaugural Plone 2.5 Framework Team, and the Plone 4.0 Framework Team. He is the co-maintainer of the Plone core content types (ATContentTypes), as well as the maintainer of Plone's default versioning system (CMFEditions) and a few popular add-on products for Plone.
Alec is an independent consultant based in Los Angeles, California. He specializes in Python, Zope and Plone development, high-performance website deployment and optimizations, and integration with web services. He has helped small and large organizations around the world to get the most from their content management systems.
Emanuel Sartor is an IT professional who has been involved in open source software since 1999. He is the cofounder and CTO at Menttes, an Argentinean company that provides custom Python, Plone and Zope based solutions.
As an active participant in the Open Source community, Emanuel has contributed many add-on products for Plone. He has conducted multiple talks and trainings at conferences such as The Jornadas Regionales de Software Libre and PyConAr. He also cofounded Plone Cono Sur, a regional Plone users group that continues to educate others about Plone.
A Laura, Julieta y Sofía
A Mercedes, Clara, Magui y Rosario
The Plone Content Management System is one of the best open source CMS because, by using Plone’s development framework, you can extend its functionality according to the specific requirements of your website. The Plone framework has lots of components that can be used to create add-ons or extensions called Plone Products. You can optimize your site for improved usability, accessibility, and security, by creating custom Plone products.
This book covers recipes that will help you create custom Plone Products and implement them on your website. Every topic covered in this book is accompanied by essential fundamentals and step-by-step explanations that will help you understand it better. With the help of this book you will be able to create custom Plone products that are well suited to your website.
Chapter 1, Getting Started will introduce the reader to the project that will be developed: a news website with banners hosted in OpenX. It will also cover the tools a Plone developer must have before starting a project.
Chapter 2, Using Development Tools, will show you how to install and use special tools that we often need to find problems (debug), modify code on the fly, or get help on tasks during the development phase of a project.
Chapter 3, Creating Content Types with ArchGenXML, will introduce the ArchGenXML technology by creating a new content type (based on an existing one), and will wrap the final product into a Python egg. It is a great tool to help with the development of Archetypes-based content types.
Chapter 4, Prevent Bugs through Testing, will show how automatic testing helps preventing the malfunctioning of features due to lack of communication or ignorance of some parts of code when projects evolve or the development team changes.
Chapter 5, Creating a Custom Content Type with Paster will cover the creation of Archetypes content types from scratch by hand... kind of. We will actually use paster to automatically create most of it.
Chapter 6, Creating Lightweight Content Types, will introduce other technologies to create lighter content types. (Archetypes is a great, though very large, framework developing content types.)
Chapter 7, Improving Product Performance, will teach you how to reap the benefits of Plone by dealing with the problem of creating content types in which the objects’ final HTML rendering performs badly, and how to benchmark these improvements.
Chapter 8, Internationalization, will cover the different tools used to offer a properly internationalized product.
Chapter 9, Adding Security to our Products will go through the steps to secure tasks and content types: permissions, roles, groups, workflows, and configuration options.
Chapter 10, Improving User Interface with KSS, will introduce the use of KSS — an Ajax framework that allows UI development without writing any JavaScript, in Plone by creating from simple client-side visual changes to server-side objects manipulation.
Chapter 11, Creating Portlets, will give you step-by-step instructions for adding portlets. Portlets are used to provide contextual information about the main contents of a page.
Chapter 12, Extending Third Party Products, will deal with what to display in the final web page and how, and will show how to add new features to existing components.
Chapter 13, Interacting with Other Systems: XML-RPC will go through some essential Python modules which are used in the advertisement service to communicate with an external non-Python-based system.
Chapter 14, Setting our Products Ready for Production, will help you create your own products repository and be ready for the website launch. After finishing the development of the products, we must make them available for future use or evolution.
Appendix, Creating a Policy Product, will introduce a special kind of product to deal with site installation, configuration, and customization with code, instead of using manual actions that are likely to be forgotten.
Although this is a cookbook, we won’t give isolated recipes for each individual task, we’ll follow a common theme throughout the book to make it easy to understand.
Some of the topics that we cover may not be all together in one chapter because:
Examples of these subjects are buildout recipe configuration and code testing.
In addition, we’d like to mention that, for ease of explanation and understanding, we approached the writing of the book as if this were a website project commissioned to us by a customer.
The project we are tackling is the design of a digital newspaper website with a particular requirement: the customer needs, with equal importance, to publish pieces of news and to insert advertisements all over the place.
Below is a summarized list of the functionalities the customer requested and we will cover in this book. We will include details related to specific things that Plone doesn’t provide out of the box.
In addition, the customer is planning to release a Spanish version of the website in the near future. So they also require that:
Everything in the website must be translated or, at least, be translatable into other languages.There are also two additional requirements that are not particular to this project but to everyone, and are related to the quality of the final product:
Accessing the website must be fast, especially for readers.All of the code must be properly commented and tested so that future changes can be made, without too much effort, by a different development team.Of course, the customer has his own branding, so they need the website to have a distinctive look and feel. This part of the project will be developed by another company (that will not be covered in this book). The process of creation and applying visual design to a Plone site is called skinning. The result of this process is called the skin or theme, which is usually contained in a single Plone product.
Take a look at the list of ready-to-use themes at: http://plone.org/products/by-category/themes.
To follow all the recipes of this book you merely need a Linux or Windows system that can run Python 2.4 or above. There are only two recipes, however, that are intended for Linux only.
This book is for programmers who have some knowledge of Python, Plone, and Zope. If you want to develop feature-rich add-on products in Plone, this book is for you. It is aimed at the development of backend features, so you need not have other web-related skills such as HTML, CSS, or JavaScript.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code for the book
Visit https://www.packtpub.com//sites/default/files/downloads/6729_Code.zip to directly download the example code.
The downloadable files contain instructions on how to use them.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
In this chapter, we will cover the following recipes:
Plone is probably the best Python CMS (Content Management System). This means that it’s a piece of software that provides all the necessary tools for people to publish content.
Why do we say that Plone is the CMS? For several reasons:
These two last are, no doubt, its most important features: Plone is extendible, because it’s also a framework, and that is what we’ll mostly cover in this book—the components that are part of the framework and how to use them to build our extensions.
Find out more about Plone features at: http://plone.org/about.
In Plone, the extension facility is provided via the installation of products. Think of them as plugins, add-ons, extensions, or whatever name you want. In Plone literature, they are called products, though.
While most Plone add-ons are technically Python packages, we will use the term products throughout this book because it is still very commonly used in Zope and Plone sphere.
As a matter of fact, Plone itself is a whole set of products, and some of its current basic features were born initially as additional characteristics, like Archetypes (more of this in the Chapter 3). With a little luck and a lot of work, one of your products may be included in a future release.
You can find a variety of available Open Source community-developed products at http://plone.org/products.
In this chapter, we are going to install Plone (in both Linux and Windows). Plone is not an isolated software application, it needs Zope and other associated products to be installed as well. To understand this process and all these components, let’s define a not-too-comprehensive, but sufficient glossary:
Term
Definition
Python module
A file containing Python definitions and statements.
Python package
A set of Python modules.
Python egg
A way of distributing Python packages. It is very interesting because it provides not only the programming code but also metadata like the version number, dependencies, and license terms.
Buildout
An environment or system created with a configuration file that is used by a special Python package, named zc.buildout, to execute a set or parts in a repeatable way so that it can be run on different computers or operating systems.
Buildout Recipe
A Python package, used by zc.buildout, that performs a particular action, like compiling the source code of an application, downloading and extracting a tar.gz file, executing some shell commands, and so on.
Zope installation
The set of Python packages, templates, and other files needed to execute a Zope server.
Zope instance
A particular Zope server installation, each of which might have its own configuration set of add-on Python packages and database.
In the following sections, we’ll mainly look at a method named buildout for a proper Zope instance set up. However, we won’t cover all of its possibilities. Throughout the whole book, after adding products to the project we are developing, we will add recipes or parameters to the buildout file, which we will create in this chapter.
As with Linux and Mac, there is also a Windows unified installer (based on the buildout method described above) available, which provides the easiest way to install Plone in a Windows environment.
Download the latest Plone release from http://plone.org/download (3.3.4 at the time of writing) and run it.
This installation process is an easy four-step wizard that will guide you through:
As a way of learning the buildout approach, which we introduced in the last two recipes, you are encouraged to go through the buildout.cfg file created in the chosen destination folder.
Although this method is really straightforward, if you plan to use several buildouts, Windows installer is unlikely to be the best solution, as it will reinstall the whole bundle, including the Python interpreter, every single time you create a new buildout.
As we have covered for Linux, we will see here the manual installation method to create a Zope instance on a Windows system.
We chose c:\MinGW as the installation folder. If you choose a different one, please adjust the next steps.
After the installation is finished, copy cc1.exe and collect2.exe from the c:\MinGW\libexec\gcc\mingw32\3.4.5 folder to c:\MinGW\bin.
Now add c:\MinGW\bin to the system PATH environment variable the same way we did with the Python PATH.
Fix the Python compiler problem: Given that the Python-installed version has been compiled on a different machine (we installed the binaries and they are usually compiled with Visual Studio), in order to prevent problems during other packages’ compilation, we must tell our environment to use the just-configured MinGW compiler.To do this, create or update the distutils.cfg file in c:\Python24\Lib\distutils (adjust the path to your Python installation directory) with this content:
First download the EasySetup installation file from http://peak.telecommunity.com/dist/ez_setup.py and run
Now you can use easy_install to install ZopeSkel, and then create the buildout:
