# -*- coding: utf-8
# Copyright 2006 by Meelis Mets
from Products.Archetypes.public import BaseSchema, Schema
from Products.Archetypes.public import BooleanField, ImageField, StringField
from Products.Archetypes.public import BooleanWidget, ImageWidget, StringWidget, SelectionWidget
from Products.Archetypes.public import BaseContent, registerType
from Globals import InitializeClass
from Products.CMFCore.utils import getToolByName
from AccessControl import ClassSecurityInfo, Unauthorized
from config import PROJECT_NAME
from BaseTest import BaseTask
schema = BaseTask.schema + Schema((
ImageField('bodyImage',
accessor = 'getBodyImage',
max_size = (300,300),
widget = ImageWidget(
label = 'Body image',
description = '',
label_msgid="label_body_image",
description_msgid="desc_body_image",
i18n_domain="psyhvel",
visible = {'view': 'visible', 'edit':'visible'},
),
),
StringField('tableWidth',
accessor = 'getTableWidth',
vocabulary = 'getNumbers',
default = '5',
widget = SelectionWidget(
format = 'select',
label = 'Table width',
label_msgid='label_table_width',
description = 'How many objects are in table by horizontally',
description_msgid = 'desc_table_width',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'visible'},
),
),
StringField('tableHeight',
accessor = 'getTableHeight',
vocabulary = 'getNumbers',
default = '1',
widget = SelectionWidget(
format = 'select',
label = 'Table height',
label_msgid='label_table_height',
description = 'How many objects are in table by vertically',
description_msgid = 'desc_table_height',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'visible'},
),
),
BooleanField('tableHasBorder',
accessor = 'getTableHasBorder',
widget = BooleanWidget(
label = 'Objects in table have border',
label_msgid='label_table_has_border',
description = 'Check if you want to add border to objects',
description_msgid = 'desc_table_has_border',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'visible'},
),
),
StringField('choicesPerPage',
accessor = 'getChoicesPerPage',
default = '0',
widget = StringWidget(
label = 'Max choices per page',
label_msgid='label_choices_per_page',
description = 'How many choices are maximum in task, if "0" then task has no limits',
description_msgid = 'desc_choices_per_page',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'visible'},
),
),
))
schema.moveField('multipleChoice', after='tableHasBorder')
schema.moveField('answerRequired', after='multipleChoice')
schema.moveField('time', pos='bottom')
class ChoiceTask(BaseTask):
""" Choice task"""
meta_type = "ChoiceTask"
archetype_name = "Choice Task"
global_allow = 0
exclude_from_nav = True
filter_content_types = True
allowed_content_types = ('ChoiceObject',)
security = ClassSecurityInfo()
schema = schema
actions = (
{
'id':'view',
'name':'View',
'action':'string:${object_url}/choice_task',
'permissions': ('View',),
},
{
'id':'edit',
'name':'Configuration',
'action':'string:${object_url}/base_edit',
'permissions': ('Modify portal content',),
},
{
'id':'choices',
'name':'Choices',
'action':'string:${object_url}/objects_view',
'permissions': ('Modify portal content',),
},
{
'id':'metadata',
'name':'Info',
'action':'string:${object_url}/base_metadata',
'permissions': ('Modify portal content',),
}
)
def getObjectsXML(self, files):
"""special xml"""
xml = self.getBaseXML()
img = self.getField('bodyImage')
ctype = img.getContentType(self)
fname = img.getFilename(self)
imagefile = img.getBaseUnit(self)
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += '\n'
xml += ''
files.append({'filename':fname, 'file':str(imagefile)})
return [xml, files]
registerType(ChoiceTask, PROJECT_NAME)