Back to index

plone3  3.1.7
schemata.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 
00021 
00022 """
00023 __author__  = 'Christian Heimes <tiran@cheimes.de>'
00024 __docformat__ = 'restructuredtext'
00025 
00026 from Products.Archetypes.atapi import BaseSchema
00027 from Products.Archetypes.atapi import MetadataSchema
00028 from Products.Archetypes.atapi import ReferenceField
00029 from Products.Archetypes.atapi import BooleanField
00030 from Products.Archetypes.atapi import BooleanWidget
00031 from Products.ATContentTypes import ATCTMessageFactory as _
00032 from Products.CMFCore.permissions import ModifyPortalContent
00033 
00034 from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget import ReferenceBrowserWidget
00035 
00036 # for ATContentTypes we want to have the description in the edit view
00037 # just like CMF
00038 ATContentTypeSchema = BaseSchema.copy() + MetadataSchema((
00039     BooleanField('excludeFromNav',
00040         required = False,
00041         languageIndependent = True,
00042         schemata = 'metadata', # moved to 'default' for folders
00043         widget = BooleanWidget(
00044             description=_(u'help_exclude_from_nav', default=u'If selected, this item will not appear in the navigation tree'),
00045             label = _(u'label_exclude_from_nav', default=u'Exclude from navigation'),
00046             visible={'view' : 'hidden',
00047                      'edit' : 'visible'},
00048             ),
00049         ),
00050     ),)
00051 
00052 ATContentTypeSchema['id'].searchable = True
00053 ATContentTypeSchema['id'].validators = ('isValidId',)
00054 
00055 # Update the validation layer after change the validator in runtime
00056 ATContentTypeSchema['id']._validationLayer()
00057 
00058 ATContentTypeSchema['description'].schemata = 'default'
00059 
00060 # BBB
00061 ATContentTypeBaseSchema = ATContentTypeSchema
00062 
00063 relatedItemsField = ReferenceField('relatedItems',
00064         relationship = 'relatesTo',
00065         multiValued = True,
00066         isMetadata = True,
00067         languageIndependent = False,
00068         index = 'KeywordIndex',
00069         write_permission = ModifyPortalContent,
00070         widget = ReferenceBrowserWidget(
00071             allow_search = True,
00072             allow_browse = True,
00073             show_indexes = False,
00074             force_close_on_insert = True,
00075             label = _(u'label_related_items', default=u'Related Items'),
00076             description = '',
00077             visible = {'edit' : 'visible', 'view' : 'invisible' }
00078             )
00079         )
00080 ATContentTypeSchema.addField(relatedItemsField.copy())
00081 
00082 #Enabling next / previous navigation
00083 
00084 NextPreviousAwareSchema = MetadataSchema((
00085     BooleanField('nextPreviousEnabled',
00086         #required = False,
00087         languageIndependent = True,
00088         schemata = 'metadata',
00089         widget = BooleanWidget(
00090             description=_(u'help_nextprevious', default=u'This enables next/previous widget on content items contained in this folder.'),
00091             label = _(u'label_nextprevious', default=u'Enable next previous navigation'),
00092             visible={'view' : 'hidden',
00093                      'edit' : 'visible'},
00094             ),
00095         default_method="getNextPreviousParentValue"
00096         ),
00097     ),)
00098 
00099 def marshall_register(schema):
00100     try:
00101         # It's a soft dependency, if not available ignore it.
00102         from Products.Marshall import ControlledMarshaller
00103     except ImportError:
00104         return
00105     # If it's available, then wrap the existing marshaller with a
00106     # ControlledMarshaller.
00107     if not schema.hasLayer('marshall'):
00108         # We are not interested in schemas that don't have a marshaller.
00109         return
00110 
00111     # Get existing marshaller.
00112     marshaller = schema.getLayerImpl('marshall')
00113     # Check if not already wrapped.
00114     if isinstance(marshaller, ControlledMarshaller):
00115         return
00116 
00117     # Wrap into a ControlledMarshaller
00118     marshaller = ControlledMarshaller(marshaller)
00119     schema.registerLayer('marshall', marshaller)
00120 
00121 def finalizeATCTSchema(schema, folderish=False, moveDiscussion=True):
00122     """Finalizes an ATCT type schema to alter some fields
00123     """
00124     schema.moveField('relatedItems', pos='bottom')
00125     if folderish:
00126         schema['relatedItems'].widget.visible['edit'] = 'invisible'
00127     schema.moveField('excludeFromNav', after='allowDiscussion')
00128     if moveDiscussion:
00129         schema.moveField('allowDiscussion', after='relatedItems')
00130 
00131     # Categorization
00132     if schema.has_key('subject'):
00133         schema.changeSchemataForField('subject', 'categorization')
00134     if schema.has_key('relatedItems'):
00135         schema.changeSchemataForField('relatedItems', 'categorization')
00136     if schema.has_key('location'):
00137         schema.changeSchemataForField('location', 'categorization')
00138     if schema.has_key('language'):
00139         schema.changeSchemataForField('language', 'categorization')
00140 
00141     # Dates
00142     if schema.has_key('effectiveDate'):
00143         schema.changeSchemataForField('effectiveDate', 'dates')
00144     if schema.has_key('expirationDate'):
00145         schema.changeSchemataForField('expirationDate', 'dates')    
00146     if schema.has_key('creation_date'):
00147         schema.changeSchemataForField('creation_date', 'dates')    
00148     if schema.has_key('modification_date'):
00149         schema.changeSchemataForField('modification_date', 'dates')    
00150 
00151     # Ownership
00152     if schema.has_key('creators'):
00153         schema.changeSchemataForField('creators', 'ownership')
00154     if schema.has_key('contributors'):
00155         schema.changeSchemataForField('contributors', 'ownership')
00156     if schema.has_key('rights'):
00157         schema.changeSchemataForField('rights', 'ownership')
00158 
00159     # Settings
00160     if schema.has_key('allowDiscussion'):
00161         schema.changeSchemataForField('allowDiscussion', 'settings')
00162     if schema.has_key('excludeFromNav'):
00163         schema.changeSchemataForField('excludeFromNav', 'settings')
00164     if schema.has_key('nextPreviousEnabled'):
00165         schema.changeSchemataForField('nextPreviousEnabled', 'settings')
00166 
00167     marshall_register(schema)
00168     return schema
00169 
00170 # Make sure the base ATCT schema is correctly finalized
00171 finalizeATCTSchema(ATContentTypeSchema)
00172 
00173 __all__ = ('ATContentTypeSchema', 'relatedItemsField',)