
Hornet: Plone skin based example
Setup Database
For this example, we are going to create a simple Employee database with the following structure.
employeeId | INT, auto_increment, primary key |
---|---|
first_name | VARCHAR(255) |
last_name | VARCHAR(255) |
employee_type | VARCHAR(2) |
notes | TEXT |
code | VARCHAR(2), primary key |
---|---|
description | VARCHAR(255) |
Create a database and execute the following SQL
CREATE TABLE `employee_types` (
`code` VARCHAR( 2 ),
`description` VARCHAR( 255 ),
PRIMARY KEY ( `code` )
);
CREATE TABLE `employees` (
`id` INT NOT NULL AUTO_INCREMENT ,
`first_name` VARCHAR( 255 ),
`last_name` VARCHAR( 255 ),
`employee_type` VARCHAR( 2 ),
`notes` TEXT,
PRIMARY KEY ( `id` ) ,
INDEX ( `employee_type` )
);
INSERT INTO `employee_types` ( `code` , `description` )
VALUES ('FT', 'Full Time'), ('PT', 'Part Time'), 'CA', 'Casual');
Create a Hornet Mount Point and connect it to your newly created employee database (See the quickstart documentation for more information). In this example, we give our mount point an id of 'db_example'.
The next step is to define our schemas.
in portal_skins/custom, create a python script called 'schema_employee_type'
# Hornet Imports
from Products.Hornet.Schema.Sources.PySchema import PySchema
from Products.Hornet.Schema.Widgets import FieldSet, StringWidget
# Employee Types Schema
return PySchema(fieldsets=(
FieldSet('employee_type', label="Employee Type", widgets=(
StringWidget('code', label="Employee Code", desc="Max two(2) characters"),
StringWidget('description', label="Description"),
)),
))
Do the same for 'schema_employee'
# Hornet Imports
from Products.Hornet.Schema.Sources.PySchema import PySchema
from Products.Hornet.Schema.Widgets import FieldSet, StringWidget, SelectionWidget
# Employee Schema
return PySchema(fieldsets=(
FieldSet('employees', label="Employee Information", widgets=(
StringWidget('first_name', label="First Name"),
StringWidget('last_name', label="Surname"),
SelectionWidget(
'employee_type',
label="Employee Type",
vocab='vocab_employee_types',
default="Please Choose",
),
TextWidget('notes', label="Notes"),
)),
))
in the above schema, employee_type is a drop-down list box. the line vocab='vocab_employee_types' instructs hornet to attempt to execute the method 'vocab_employee_types' to find a valid vocabulary to populate our list with.
Create a python script called vocab_employee_types.py
# db_example - The id of the Hornet Moint Point
# employee_types - The id of the Hornet Folder attached to the 'employee_types' table
# createVocab - Returns a vocabulary consisting of code/description pairs.
return context.db_example.employee_types.createVocab( 'code', 'description' )
Now to apply the schemas to hornet
Using the ZMI, Navigate to the Hornet Mount Point, select the Hornet Folder 'employees',
and click 'Properties'. Set a property called cb_schema ('Callback Schema') to 'schema_employee'
Repeat this process for 'employee_types'- set cb_schema to 'schema_employee_type' (The name of our python script containing the schema)
Adding Data
Navigate to http://(your plone site)/db_example/employees/create/hornet_record_edit_form
('create' is a special pseudo record that is used to create new records.)

Fill out some sample data and click save. A new record will be created in your SQL database and you will be redirected to the new objects URL