Back to index

plone3  3.1.7
ATRefBrowserDemo.py
Go to the documentation of this file.
00001 """ demonstrates the use of ATReferenceBrowserWidget """
00002 
00003 from Products.Archetypes.atapi import *
00004 
00005 from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget import *
00006 from Products.ATReferenceBrowserWidget.config import PROJECTNAME
00007 from DateTime import DateTime
00008 
00009 
00010 schema = BaseSchema +  Schema((
00011     ReferenceField('singleRef', 
00012                    multiValued=0,
00013                    allowed_types=('ATDocument','ATFile', 'Article', 'ATRefBrowserDemo'),
00014                    relationship='Rel1',
00015                    widget=ReferenceBrowserWidget(default_search_index='SearchableText', description='This is the first field. Pick an object.')),
00016     ReferenceField('multiRef', 
00017                    multiValued=1,
00018                    relationship='Rel2',
00019                    widget=ReferenceBrowserWidget(show_indexes=1, description='And here is another field with a longer description text to explain the user better what to do with this field.')) ,
00020     ReferenceField('multiRef2', 
00021                    multiValued=1,
00022                    relationship='Rel3',
00023                    widget=ReferenceBrowserWidget(allow_search=1, 
00024                                                  allow_browse=0,
00025                                                  show_indexes=1, 
00026                                                  available_indexes={'SearchableText':'Free text search',
00027                                                                     'Description': "Object's description"},
00028                                                  description='And here is another field.')) ,    
00029     ReferenceField('multiRef3', 
00030                    multiValued=1,
00031                    relationship='Rel3',
00032                    widget=ReferenceBrowserWidget(show_indexes=1, 
00033                                                  description='And here is another field.',
00034                                                  startup_directory='/Members')) ,
00035     ReferenceField('multiRef4',
00036                    multiValued=1,
00037                    relationship='Rel4',
00038                    widget=ReferenceBrowserWidget(show_indexes=1,
00039                                                  allow_browse=0,
00040                                                  description='And here is another field with a fixed query restriction (only published objects will appear).',
00041                                                  base_query={'review_state':'published'},
00042                                                  )) ,
00043     ReferenceField('multiRef5',
00044                    multiValued=1,
00045                    relationship='Rel5',
00046                    widget=ReferenceBrowserWidget(show_indexes=1,
00047                                                  allow_browse=0,
00048                                                  description='And here is another field with some dynamic query restrictions (only objects with "start" withing one week of the current date will appear).',
00049                                                  base_query='dynamicBaseQuery',
00050                                                  )) ,
00051     
00052                               ))
00053 
00054 class ATRefBrowserDemo(BaseContent):
00055     """
00056     Demo from ATReferenceBrowserWidget
00057     """
00058     content_icon = "document_icon.gif"
00059     schema = schema
00060     def dynamicBaseQuery(self):
00061         """This example function generates a base query which ensures that only
00062         objects whose start property is within one week of the current day"""
00063         return {'start': {'query':[DateTime()-7,DateTime()+7], 'range':'minmax'}}
00064     
00065 
00066 registerType(ATRefBrowserDemo, PROJECTNAME)