# -*- 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 BaseFunctions import BaseFunctions
schema = BaseSchema + Schema((
ImageField('choiceImage',
accessor = 'getChoiceImage',
max_size = (150,150),
widget = ImageWidget(
label = 'Choice image',
description = '',
label_msgid="label_choice_image",
description_msgid="desc_choice_image",
i18n_domain="psyhvel",
visible = {'view': 'visible', 'edit':'visible'},
),
),
BooleanField('useTitle',
accessor = 'getUseTitle',
widget = BooleanWidget(
label = 'Use title',
label_msgid='label_usetitle',
description = 'Check if you want use title as text (description) in answer',
description_msgid = 'desc_usetitle',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'visible'},
),
),
BooleanField('alreadyChecked',
accessor = 'getAlreadyChecked',
widget = BooleanWidget(
label = 'Already Checked',
label_msgid='label_already_checked',
description = 'Check if you want show choice as already checked option',
description_msgid = 'desc_already_checked',
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'visible'},
),
),
BooleanField('rightChoice',
accessor = 'getRightChoice',
widget = BooleanWidget(
label = 'Right choice',
description = 'Check if this choice is right answer for question',
label_msgid="label_right_choice",
description_msgid="desc_right_choice",
i18n_domain="psyhvel",
visible = {'view': 'invisible', 'edit':'visible'},
),
),
BooleanField('rightChoice2',
accessor = 'getRightChoice2',
widget = BooleanWidget(
label = 'Right choice 2',
description = 'Check if this choice is right answer for question',
label_msgid = "label_right_choice_2",
description_msgid = "desc_right_choice",
i18n_domain = "psyhvel",
visible = {'view': 'invisible', 'edit':'visible'},
),
),
))
class ChoiceObject(BaseContent, BaseFunctions):
""" Psyhvel base test"""
meta_type = "ChoiceObject"
archetype_name = "Choice Object"
global_allow = 0
exclude_from_nav = True
filter_content_types = True
allowed_content_types = ()
security = ClassSecurityInfo()
schema = schema
actions = (
{
'id':'view',
'name':'View',
'action':'string:${object_url}/base_view',
'permissions': ('View',),
},
{
'id':'edit',
'name':'Edit',
'action':'string:${object_url}/base_edit',
'permissions': ('Modify portal content',),
},
{
'id':'metadata',
'visible':False,
'permissions': ('Modify portal content',),
},
)
def getObjectsXML(self, files):
"""special xml"""
xml = self.getBaseXML()
img = self.getField('choiceImage')
fname = img.getFilename(self)
imagefile = img.getBaseUnit(self)
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(ChoiceObject, PROJECT_NAME)