# -*- coding: utf-8
# -*- Mode: Python; py-indent-offset: 4 -*-
""" ExtendedText type """
__version__ = "$Revision:33$"[11:-2]
import Globals
from AccessControl import ClassSecurityInfo
from OFS.SimpleItem import SimpleItem
import re
from zope.interface import implements
from Products.QTAuthor.common import commons
from Products.QTAuthor.BaseQuestion import BaseQuestion
from Products.QTAuthor.Permissions import *
from Products.QTAuthor.interfaces import IBaseQuestion, IQuestionAuthoring
class ExtendedTextType(BaseQuestion):
""" """
meta_type = 'extended_text_type'
security = ClassSecurityInfo()
security.declareObjectPublic()
implements(IBaseQuestion, IQuestionAuthoring)
manage_options = SimpleItem.manage_options
def __init__(self, id):
self.id=id
BaseQuestion.__init__(self)
security.declarePrivate('manage_afterAdd')
def manage_afterAdd(self, item, container):
self.index_object()
security.declareProtected(perm_view_question, 'getType')
def getType(self):
return 'extended_text_type'
security.declareProtected(perm_edit_question, 'setLength')
def setLength(self, answerlength):
self.answerlength = answerlength
self.textarealength = 6
if answerlength != '':
self.textarealength = int(answerlength) * 6
security.declareProtected(perm_view_question, 'getTextareaLength')
def getTextareaLength(self):
""" """
return self.textarealength
security.declareProtected(perm_view_question, 'getLength')
def getLength(self):
""" """
return self.answerlength
def setPlaceholderText(self, placeholdertext):
self.placeholdertext = placeholdertext
security.declareProtected(perm_view_question, 'getPlaceholderText')
def getPlaceholderText(self):
""" """
return getattr(self, 'placeholdertext', '')
def getMaxPoints(self):
return 0.0
security.declareProtected(perm_edit_question, 'changeQuestion')
def changeQuestion(self, REQUEST, add=0):
""" """
answerlength = REQUEST.get('answerlength')
self.setLength(answerlength)
self.setPlaceholderText(REQUEST.get('placeholdertext'))
self.setCommonData(REQUEST)
self.reindex_object()
if answerlength != '':
if add == 1:
return REQUEST.RESPONSE.redirect(self.getId()+'/index_html')
self._setHtml()
return REQUEST.RESPONSE.redirect('index_html')
message = []
message.append("Insert answer length!")
return REQUEST.RESPONSE.redirect(self.getId() +'/edit?message='+'
'.join(message))
def xml2(self, fullURLs=False):
""" """
xml = u'\n'
xml += '\n'
xml=xml+ '\n'
xml=xml+ '\n'
xml=xml+ '\n'
xml += '\n\n
'
placeholdertxt = self.getPlaceholderText().decode('utf-8')
xml=xml+ '\n'
xml=xml+ '\n'
xml += """
0
0
""" % self.getId()
xml=xml+ '\n'
#REQUEST.RESPONSE.setHeader("Content-type", "text/xml")
return xml
security.declareProtected('QTAuthor: View question', 'getInteractionType')
def getInteractionType(self):
""" """
return "extendedTextInteraction"
def importQuestion(self, data, dom):
""" """
import re
additionalFiles = {}
questext = data.split("")
questext = questext[1].split('