# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import TextField, FileField, BooleanField, StringField from Products.Archetypes.public import TextAreaWidget, FileWidget, RichWidget, BooleanWidget, StringWidget, SelectionWidget from Products.Archetypes.public import BaseContent, OrderedBaseFolder, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from BaseFunctions import BaseFunctions from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME, TASK_LIST, STIMULUS_LIST schema = BaseSchema + Schema(( TextField('description', accessor='getDescription', #primary=True, validators = ('isTidyHtmlWithCleanup',), default_output_type = 'text/x-html-safe', allowable_content_types = ('text/html',), widget = RichWidget( label="Description", description="", label_msgid='label_description', description_msgid='description_description', visible={'view':'visible','edit':'visible'}, i18n_domain="psyhvel", rows = 10 ), ), BooleanField('descriptionIsTop', accessor = 'getDescriptionIsTop', default = True, widget = BooleanWidget( label = 'Description is top side', label_msgid='label_description_is_top', description = 'Check if you want to see description text in top, other way it is in bottom side', description_msgid = 'desc_description_is_top', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), TextField('additionalinfo', accessor='getAdditionalInfo', isMetadata = 1, schemata = 'metadata', widget = TextAreaWidget( label="Info", description="", label_msgid='label_info', description_msgid='description_info', i18n_domain="psyhvel", ), ), )) #XXX hide unneccessary metadata fields schema['language'].schemata='default' schema['language'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema['subject'].schemata='default' schema['subject'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema['allowDiscussion'].schemata='default' schema['allowDiscussion'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema['effectiveDate'].schemata='default' schema['effectiveDate'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema['expirationDate'].schemata='default' schema['expirationDate'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema['contributors'].schemata='default' schema['contributors'].widget.visible = {'edit' : 'invisible', 'view' : 'invisible' } schema_test = schema.copy() + Schema(( )) schema_test.delField('descriptionIsTop') schema_sheet = schema.copy() + Schema(( StringField('time', accessor = 'getTime', default = '0', widget = StringWidget( label = 'Time', label_msgid='label_time', description = 'Answering time, if set, form will be submitted automatically when running out of time, default is 0 - submit is manual', description_msgid = 'desc_time', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), )) schema_task = schema_sheet + Schema(( BooleanField('multipleChoice', accessor = 'getMultipleChoice', widget = BooleanWidget( label = 'Multiple choice', label_msgid='label_multiple_choice', description = 'Check if there is more than one right answer for this question', description_msgid = 'desc_multiple_choice', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), BooleanField('answerRequired', accessor = 'getAnswerRequired', widget = BooleanWidget( label = 'Answering is required', label_msgid='label_answer_required', description = 'Check if answering is required', description_msgid = 'desc_answer_required', i18n_domain="psyhvel", visible = {'view': 'invisible', 'edit':'visible'}, ), ), )) schema_stimulus = schema_sheet + Schema(( )) class TestFolder(OrderedBaseFolder, BaseFunctions): """ Psyhvel test folder""" meta_type = "TestFolder" archetype_name = "Test" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = TASK_LIST+STIMULUS_LIST security = ClassSecurityInfo() schema = schema_test actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/library_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Modify portal content',), }, { 'id':'metadata', 'name':'Info', 'action':'string:${object_url}/base_metadata', 'permissions': ('Modify portal content',), }, ) def skeem(self): """fff""" for f in self.schema.fields(): print f #XXX this is kahtlene asi def getCurrentSheet(self): """return current sheet""" return self.getFolderContents()[0].getObject() def getObjectsXML(self, files): """special data""" xml = self.getBaseXML() xml += '\n' xml += '' return [xml, files] def isExportable(self): """is exportable""" return True; def isImportable(self): """is exportable""" return True; registerType(TestFolder, PROJECT_NAME) class BaseSheet(OrderedBaseFolder,BaseFunctions): """ Psyhvel base sheet""" meta_type = "BaseSheet" archetype_name = "Base Sheet" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema_sheet actions = ( { 'id':'metadata', 'visible':False, 'permissions': ('Modify portal content',), }, ) def getNumbers(self): """return numbers for table length and width""" nrs = [] for nr in range(1,20, 1): nrs.append(nr) return nrs def isExportable(self): """is exportable""" return True; registerType(BaseSheet, PROJECT_NAME) class BaseTask(BaseSheet): """ Psyhvel base task""" meta_type = "BaseTask" archetype_name = "Base Task" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema_task def isExportable(self): """is exportable""" return True; registerType(BaseTask, PROJECT_NAME) class BaseStimulus(BaseSheet): """ Psyhvel base stimulus""" meta_type = "BaseStimulus" archetype_name = "Base Stimulus" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema_stimulus def isExportable(self): """is exportable""" return True; registerType(BaseStimulus, PROJECT_NAME)