Back to index

plone3  3.1.7
SimpleType.py
Go to the documentation of this file.
00001 from Products.Archetypes.atapi import *
00002 from Products.Archetypes.config import PKG_NAME
00003 from Products.CMFCore.permissions import setDefaultRoles
00004 from AccessControl import ClassSecurityInfo
00005 
00006 schema = BaseSchema + Schema((
00007     TextField('body',
00008               required=1,
00009               searchable=1,
00010               default_output_type='text/html',
00011               allowable_content_types=('text/plain',
00012                                        'text/restructured',
00013                                        'text/html',
00014                                        'application/msword'),
00015               widget  = RichWidget(description="""Enter or upload text for the Body of the document"""),
00016               ),
00017     StringField('ptype',
00018               default_method='Type'
00019               ),
00020     ))
00021 
00022 
00023 class SimpleType(BaseContent):
00024     """A simple archetype"""
00025     schema = schema
00026 
00027 registerType(SimpleType, PKG_NAME)
00028 
00029 TestView = 'Archetypes Tests: Protected Type View'
00030 setDefaultRoles(TestView, ('Anonymous', 'Manager',))
00031 
00032 TestWrite = 'Archetypes Tests: Protected Type Write'
00033 setDefaultRoles(TestWrite, ('Anonymous', 'Manager',))
00034 
00035 class SimpleProtectedType(SimpleType):
00036 
00037     security = ClassSecurityInfo()
00038 
00039     attr_security = AttributeValidator()
00040     security.setDefaultAccess(attr_security)
00041     # Delete so it cannot be accessed anymore.
00042     del attr_security
00043 
00044     archetype_name = portal_type = meta_type = 'SimpleProtectedType'
00045     schema = schema.copy()
00046     for f in schema.fields():
00047         f.read_permission = TestView
00048         f.write_permission = TestWrite
00049 
00050     security.declareProtected(TestView, 'foo')
00051     def foo(self):
00052         return 'bar'
00053 
00054 registerType(SimpleProtectedType, PKG_NAME)