# -*- coding: utf-8 # -*- Mode: Python; py-indent-offset: 4 -*- """ Slider type """ __version__ = "$Revision:33$"[11:-2] import Globals from AccessControl import ClassSecurityInfo from OFS.SimpleItem import SimpleItem 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 SliderType(BaseQuestion): """ """ meta_type = 'slider_type' security = ClassSecurityInfo() security.declareObjectPublic() implements(IBaseQuestion, IQuestionAuthoring) manage_options = SimpleItem.manage_options def __init__(self, id): self.id=id self.answers={} self.count = {} BaseQuestion.__init__(self) security.declarePrivate('manage_afterAdd') def manage_afterAdd(self, item, container): self.index_object() security.declareProtected(perm_edit_question, 'setAnswers') def setAnswers(self, beginning, ending, points, lower, upper): #self.rightanswer = right self.rangebeginning = beginning self.rangeending = ending self.rangepoints = points self.lowerbound = lower self.upperbound = upper security.declareProtected(perm_view_question, 'getBeginning') def getBeginning(self): """ """ return self.rangebeginning security.declareProtected(perm_view_question, 'getEnding') def getEnding(self): """ """ return self.rangeending security.declareProtected(perm_view_question, 'getPoints') def getPoints(self): """ """ return self.rangepoints security.declareProtected(perm_view_question, 'getLower') def getLower(self): """ """ return self.lowerbound security.declareProtected(perm_view_question, 'getUpper') def getUpper(self): """ """ return self.upperbound security.declareProtected(perm_view_question, 'getType') def getType(self): return 'slider_type' def getMaxPoints(self): return float(self.getPoints()) security.declareProtected(perm_edit_question, 'changeQuestion') def changeQuestion(self, REQUEST, add=0): """ """ rangeBeginning = REQUEST.get('rangebeginning', '') rangeEnding = REQUEST.get('rangeending', '') rangePoints = REQUEST.get('rangepoints', '') if not rangePoints: rangePoints = '1' lowerbound = REQUEST.get('lowerbound', '0') upperbound = REQUEST.get('upperbound', '') self.setAnswers(rangeBeginning, rangeEnding, rangePoints, lowerbound, upperbound) self.setCommonData(REQUEST) self.reindex_object() message = [] if (rangeBeginning == '' or rangeEnding == ''): message.append("Please mark correct range!") if (lowerbound == '' or upperbound == ''): message.append("Please mark lower bound and upper bound!") if len(message) > 0: return REQUEST.RESPONSE.redirect(self.absolute_url()+'/edit?message='+'
'.join(message)) if add == 1: return REQUEST.RESPONSE.redirect(self.getId()+'/index_html') return REQUEST.RESPONSE.redirect('index_html') def xml2(self, fullURLs=False): """ """ xml = u'\n' xml += '\n' xml=xml+ '\n' # # 16 # xml=xml+ '\n' i = int(self.getBeginning()) for i in range(int(self.getBeginning()), int(self.getEnding()) + 1): xml=xml+ '\n' i = i + 1 xml=xml+ '\n' xml=xml+ '\n' xml=xml+ '\n' xml=xml+ '\n' xml += '

\n\n

\n' xml=xml+ '\n' xml=xml+ '' xml=xml+ '
\n' xml=xml+ self.map_response() xml=xml+'
\n' #REQUEST.RESPONSE.setHeader("Content-type", "text/xml") return xml security.declareProtected(perm_view_question, 'getInteractionType') def getInteractionType(self): """ """ return "sliderInteraction" def importQuestion(self, data, dom): """ """ import re additionalFiles = {} questext = data.split('') questext = questext[1].split('(.*?)', re.S) val = cm.search(ans_send).group(1) sum += float(val) count += 1 average = sum/count rounded_avg = "%.2f" %average text = 'Average: '+str(average) return text def getCSVstats(self, ans_send, frequencies): import re text = "" ques_id = self.getId() if ques_id in frequencies: array = frequencies.get(ques_id) else: array = [] cm = re.compile('(.*?)', re.S) val = cm.search(ans_send).group(1) text += val + ';' array.append(val) frequencies[ques_id] = array return {'csvtext': text, 'frequencies': frequencies} Globals.InitializeClass(SliderType) # EOF