Back to index

plone3  3.1.7
ComplexType.py
Go to the documentation of this file.
00001 from Products.Archetypes.atapi import *
00002 from Products.Archetypes import Field
00003 from SimpleType import SimpleType
00004 from Products.Archetypes.config import PKG_NAME
00005 
00006 fields = ['StringField',
00007           'FileField', 'TextField', 'DateTimeField', 'LinesField',
00008           'IntegerField', 'FloatField', 'FixedPointField',
00009           'BooleanField', 'ImageField'
00010           ]
00011 
00012 field_instances = []
00013 
00014 for f in fields:
00015     field_instances.append(getattr(Field, f)(f.lower()))
00016 
00017 schema = Schema(tuple(field_instances) + (
00018     LinesField('selectionlinesfield1',
00019                vocabulary='_get_selection_vocab',
00020                enforceVocabulary=1,
00021                widget=SelectionWidget(label='Selection'),
00022                ),
00023     LinesField('selectionlinesfield2',
00024                vocabulary='_get_selection_vocab',
00025                widget=SelectionWidget(label='Selection'),
00026                ),
00027     LinesField('selectionlinesfield3',
00028                vocabulary='_get_selection_vocab2',
00029                widget=MultiSelectionWidget(label='MultiSelection'),
00030                ),
00031     TextField('textarea_appendonly',
00032               widget=TextAreaWidget( label='TextArea',
00033                                      append_only=1,),
00034               ),
00035     TextField('textarea_appendonly_timestamp',
00036               widget=TextAreaWidget( label='TextArea',
00037                                      append_only=1,
00038                                      timestamp=1,),
00039               ),                                          
00040     TextField('textarea_maxlength',
00041               widget=TextAreaWidget( label='TextArea',
00042                                      maxlength=20,),
00043               ),                                          
00044     TextField('richtextfield',
00045               allowable_content_types=('text/plain',
00046                                        'text/structured',
00047                                        'text/restructured',
00048                                        'text/html',
00049                                        'application/msword'),
00050               widget=RichWidget(label='rich'),
00051               ),
00052     ReferenceField('referencefield',
00053                    relationship='complextype',
00054                    widget=ReferenceWidget(addable=1),
00055                    allowed_types=('ComplexType', ),
00056                    multiValued=1,
00057                   ),
00058     )) + ExtensibleMetadata.schema
00059 
00060 class ComplexType(SimpleType):
00061     """A simple archetype"""
00062     schema = SimpleType.schema + schema
00063     archetype_name = meta_type = "ComplexType"
00064     portal_type = 'ComplexType'
00065 
00066     def _get_selection_vocab(self):
00067         return DisplayList((('Test','Test'), ))
00068 
00069     def _get_selection_vocab2(self):
00070         return DisplayList((('Test','Test'),('Test2','Test2'), ))
00071 
00072 
00073 registerType(ComplexType, PKG_NAME)