from Products.Archetypes.public import TextField, StringField from Products.Archetypes.public import TextAreaWidget, SelectionWidget from Products.Archetypes.public import Schema from Products.Archetypes.public import registerType from Products.PloneSilverCity.config import available_languages, project, javascript from Products.ATContentTypes.content import base from Products.ATContentTypes.content import schemata from AccessControl import ClassSecurityInfo, Permissions from ComputedAttribute import ComputedAttribute from Globals import InitializeClass from Products.CMFCore.permissions import ManageProperties code = TextField('code', searchable=True, widget=TextAreaWidget( rows=40, view_js=(javascript), view_css=("SyntaxHighlighter.css",), label="Source code", description="The source code that you'd like to add to the site" ) ) language = StringField('language', vocabulary=available_languages, enforceVocabulary=True, widget=SelectionWidget( label="Source language", description="The language of the source code you are adding to the site." ) ) schema = base.ATContentTypeSchema.copy() + Schema((code, language),) class PloneSilverCity(base.ATCTContent): # see testSchemaOrder schema = schemata.finalizeATCTSchema(schema) schema.moveField('language', after='code') content_icon = 'document_icon.gif' meta_type = project portal_type = 'Source Code' archetype_name = 'Source Code' default_view = 'silvercity_view' immediate_view = 'silvercity_view' security = ClassSecurityInfo() actions = base.updateActions(base.ATCTContent, ( { 'id' : 'source', 'name' : 'Source', 'action' : 'string:${object_url}/getCode', 'permissions' : (ManageProperties,), }, ) ) def setLanguage(self, value): """ If you do enforceVocabulary, it doesn't seem to raise an error, I think it should, so here's a wrapper to make it do that, if it is, we can remove this wrapper and the test should pass """ # first time this is run, ie: when you create an object # the contents of variable value, is an empty string # change the default value on the field if you want # different if value and value not in available_languages: raise ValueError, "The language %s is not one of the available languages: %s" \ % (value, available_languages) self.getField('language').set(self, value) InitializeClass(PloneSilverCity) registerType(PloneSilverCity, project)