# -*- coding: utf-8
# -*- Mode: Python; py-indent-offset: 4 -*-
""" Hottext 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 HotTextType(BaseQuestion):
""" """
meta_type = 'hottext_type'
security = ClassSecurityInfo()
security.declareObjectPublic()
implements(IBaseQuestion, IQuestionAuthoring)
manage_options = SimpleItem.manage_options
def __init__(self, id):
self.id=id
self.gapvariants = {}
self.gappoints = {}
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 'hottext_type'
security.declareProtected(perm_edit_question, 'setVariants')
def setVariants(self, variants):
self.gapvariants = variants
security.declareProtected(perm_view_question, 'getVariants')
def getVariants(self):
""" """
return self.gapvariants
security.declareProtected(perm_edit_question, 'setCorrectAnswer')
def setCorrectAnswer(self, correct):
self.gappoints = correct
security.declareProtected(perm_view_question, 'getCorrectAnswer')
def getCorrectAnswer(self):
""" """
return self.gappoints
security.declareProtected(perm_edit_question, 'setGapsCount')
def setGapsCount(self, count):
self.gapscount = count
security.declareProtected(perm_view_question, 'getGapsCount')
def getGapsCount(self):
""" """
return self.gapscount
security.declareProtected(perm_view_question, 'getMaxPoints')
def getMaxPoints(self):
return 1.0
security.declareProtected(perm_edit_question, 'changeQuestion')
def changeQuestion(self, REQUEST):
""" """
self.setCommonData(REQUEST)
self.reindex_object()
allgaps = re.findall('\[.*?\]', self.getQuestion(REQUEST))
gapscount = len(allgaps)
message = []
# display message if at least one gap [] is empty
for gap in allgaps:
# check is that gap empty
if gap == "[]":
message.append("You have to write choice into each square brackets!")
break;
if gapscount == 0:
message.append("Mark which words you want to make choices!")
# if something is wrong
if len(message) > 0:
return REQUEST.RESPONSE.redirect(self.absolute_url() +'/edit?message='+'
'.join(message))
return REQUEST.RESPONSE.redirect(self.absolute_url()+'/hottext2.html')
def gaps(self):
""" """
txt = self.getQuestion().decode('utf-8')
allgaps = re.finditer('\[.*?\]', txt)
allgaps1 = re.finditer('\[.*?\]', txt)
p = None
table = u'
'+self.utranslate('Text')+' | '+self.utranslate('Gaps')+' | |
'+txt[e:z[0]]+' | ||
'+y.group()+' | ' x = 0 for k in range(1, gapscount + 1): if (variants.get('gap'+str(k))): variant = variants.get('gap'+str(k)).decode('utf-8') if var == variant and x == 0: table += '' if correctanswer.get('gap') == 'v'+str(k): table += ' | ' x = 1 if x == 0: table += ' | ' table += ' | ' p = y i += 1 table += ' |
'+txt[z[1]:]+' |
\n' question = self.getQuestion() if fullURLs: from xml.sax.saxutils import escape question = escape(question) question = self.replace(question) question = self.fixQuestionText(question) if not fullURLs: question = self.replaceImageurl(question) xml += question xml += '
\n' xml += 'Variants | Frequencies |
---|---|
'+variants.get(var)+' | ' count = 0 for result in results: ans_obj = result.getObject() ans_send = ans_obj.getAnswerSend() cm = re.compile(''+str(count)+' |