O'Reilly logo

Plone 3 Products Development Cookbook by Marcos F. Romero, Juan Pablo Giménez

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a custom validator to a content type

Given that we plan to show an embedded video player when opening a Video page in our website, we must ensure that users won't be able to upload any kind of file other than FLV videos.

Archetypes can validate field inputs in different ways; the most common one is the use of a validators property inside the schema field definition, as it's used in the previous section for the originalDate field.

We prefer using a more modern way to call a validator, a subscription adapter, which is basically a special class that declares to adapt another one and, in the case of Archetypes validators, it implements a specific event interface.

How to do it...

  1. Create this validators.py file inside the contents sub-package of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required