Beispiel #1
0
    def renderView(self, style, preview=False):
        """
        Returns an XHTML string for viewing this block
        """
        lb = "\n"  #Line breaks
        html = common.ideviceHeader(self, style, "view")
        html += '<form name="quizForm%s" id="quizForm%s" action="#" class="quiz-test-form">' % (
            self.idevice.id, self.idevice.id)
        html += lb
        html += u'<input type="hidden" name="passrate" id="passrate-' + self.idevice.id + '" value="' + self.idevice.passRate + '" />' + lb
        for element in self.questionElements:
            if preview:
                html += element.renderPreview()
            else:
                html += element.renderView()
        html += '<div class="block iDevice_buttons">' + lb
        html += '<p><input type="submit" name="submitB" value="' + c_(
            "SUBMIT ANSWERS") + '" /> ' + common.javaScriptIsRequired(
            ) + '</p>' + lb
        html += '</div>' + lb
        html += '<div id="quizFormScore' + self.id + '"></div>' + lb
        html += '</form>' + lb
        html += common.ideviceFooter(self, style, "view")

        return html
Beispiel #2
0
    def renderView(self, style, preview=False):
        """
        Returns an XHTML string for viewing this block
        """
        lb = "\n"  # Line breaks
        html = common.ideviceHeader(self, style, "view")
        html += '<form name="quizForm%s" id="quizForm%s" action="javascript:calcScore2();">' % (
            self.idevice.id,
            self.idevice.id,
        )
        html += lb
        html += (
            u'<input type="hidden" name="passrate" id="passrate-'
            + self.idevice.id
            + '" value="'
            + self.idevice.passRate
            + '" />'
            + lb
        )
        for element in self.questionElements:
            if preview:
                html += element.renderPreview()
            else:
                html += element.renderView()
        html += '<div class="block iDevice_buttons">' + lb
        html += (
            '<p><input type="submit" name="submitB" value="'
            + _("SUBMIT ANSWERS")
            + '"/> '
            + common.javaScriptIsRequired()
            + "</p>"
            + lb
        )
        html += "</div>" + lb
        html += "</form>" + lb
        html += common.ideviceFooter(self, style, "view")

        return html
    def renderView(self, feedbackId=None, preview=False):
        
        # Shows the text with inputs for the missing parts
       
        dT = common.getExportDocType()
        sectionTag = "div"
        if dT == "HTML5":
            sectionTag = "section"

        html = ['<%s class="activity" id="activity-%s">' % (sectionTag,self.id)]
        
        if preview: 
            # to render, use the content with the preview-able resource paths:
            self.field.encodedContent = self.field.content_w_resourcePaths
            html += ['<div class="activity-form">']
        else:
            # to render, use the flattened content, withOUT resource paths: 
            self.field.encodedContent = self.field.content_wo_resourcePaths
            html += ['<form name="cloze-form-'+self.id+'" action="#" onsubmit="showClozeScore(\''+self.id+'\',1);return false" class="activity-form">']

        html += ['<div id="cloze%s">' % self.id]
        html += ['<script type="text/javascript">var YOUR_SCORE_IS="%s"</script>' % c_('Your score is ')]
        # Store our args in some hidden fields
        def storeValue(name):
            value = str(bool(getattr(self.field, name))).lower()
            return common.hiddenField('clozeFlag%s.%s' % (self.id, name), value)
        #html.append(storeValue('showScore'))
      
        if feedbackId:
            html.append(common.hiddenField('clozeVar%s.feedbackId' % self.id,'ta'+feedbackId))
        # Mix the parts together
        words = ""
        wordslista='<option selected="selected"> </option>'
        wordsarray=[]
        listaotras=[]
        listaotras2=[]
        wordsarraylimpo=[] 
        
        for i, (text, missingWord) in enumerate(self.field.parts):
            if missingWord:
                wordsarray.append([missingWord])
        
        listaotras=re.compile(",|\|").split(self.field.otras)
        
        for i, (missingWord) in enumerate(listaotras):
            if missingWord:
                listaotras2.append([missingWord])
        wordsarray=wordsarray + listaotras2 
        wordsarraylimpo= [wordsarray[i] for i in range(len(wordsarray)) if wordsarray[i] not in wordsarray[:i]]
        random.shuffle(wordsarraylimpo)
        for wdlista in wordsarraylimpo:
           wordslista +='<option value="%s">%s</option>' % (escape(wdlista[0], True), wdlista[0])
          
        for i, (text, missingWord) in enumerate(self.field.parts):
            if text:
                html.append(text)
            if missingWord:
                words += "'" + missingWord + "',"
                # The edit box for the user to type into
                inputHtml = ['<label for="clozeBlank%s.%s" class="sr-av">%s (%s):</label>' % (self.id, i, c_("Cloze"), (i+1))]
                inputHtml += ['<select id="clozeBlank%s.%s">' % (self.id, i),wordslista,'</select>']
                html += inputHtml
                            
                # Hidden span with correct answer
                html += ['<span style="display:none" id="clozeAnswer%s.%s">%s</span>' % (self.id, i, self.ecrypt(missingWord))]

        # Score string
        html += ['<div class="block iDevice_buttons">']
        html += ['<p>']
        
        if preview:
            html += [common.button('getScore%s' % self.id, c_(u"Check"), id='getScore%s' % self.id, onclick="showClozeScore('%s',1)" % self.id)]
        else:
            html += [common.submitButton('getScore%s' % self.id, c_(u"Check"), id='getScore%s' % self.id)]
        if feedbackId:
            html += [common.feedbackButton('feedback%s' % self.id, c_(u"Show Feedback"), onclick = "toggleClozeFeedback('%s',this)" % self.id)]
         
        codotras=self.ecrypt(self.field.otras)
        html += [common.hiddenField('clozeOtras%s' % self.id,codotras)]   
        html += ['<input type="hidden" name="clozeFlag%s.strictMarking" id="clozeFlag%s.strictMarking" value="false" />' % (self.id,self.id)]
        html += ['<input type="hidden" name="clozeFlag%s.checkCaps" id="clozeFlag%s.checkCaps" value="false" />' % (self.id,self.id)]
        html += ['<input type="hidden" name="clozeFlag%s.instantMarking" id="clozeFlag%s.instantMarking" value="false" />' % (self.id,self.id)]
        html += [common.javaScriptIsRequired()]
        html += ['</p>']
        html += ['</div>']
        html += ['<div class="score js-feedback" id="clozeScore%s"></div>' % self.id]        
        html += ['</div>']
        if preview: 
            html += ['</div>']
        else:
            html += ['</form>']
        html += ['</%s>' % sectionTag]
        return '\n'.join(html)
Beispiel #4
0
    def renderView(self, feedbackId=None, preview=False):
        
        # Shows the text with inputs for the missing parts
       
        dT = common.getExportDocType()
        sectionTag = "div"
        if dT == "HTML5":
            sectionTag = "section"

        html = ['<%s class="activity" id="activity-%s">' % (sectionTag,self.id)]
        
        if preview: 
            # to render, use the content with the preview-able resource paths:
            self.field.encodedContent = self.field.content_w_resourcePaths
            html += ['<div class="activity-form">']
        else:
            # to render, use the flattened content, withOUT resource paths: 
            self.field.encodedContent = self.field.content_wo_resourcePaths
            html += ['<form name="cloze-form-'+self.id+'" action="#" class="activity-form cloze-form">']

        html += ['<div id="cloze%s">' % self.id]
        # Store our args in some hidden fields
        def storeValue(name):
            value = str(bool(getattr(self.field, name))).lower()
            return common.hiddenField('clozeFlag%s.%s' % (self.id, name), value)
        #html.append(storeValue('showScore'))
      
        if feedbackId:
            html.append(common.hiddenField('clozeVar%s.feedbackId' % self.id,'ta'+feedbackId))
        # Mix the parts together
        words = ""
        wordslista='<option selected="selected"> </option>'
        wordsarray=[]
        listaotras=[]
        listaotras2=[]
        wordsarraylimpo=[] 
        
        for i, (text, missingWord) in enumerate(self.field.parts):
            if missingWord:
                wordsarray.append([missingWord])
        listaotras=self.field.otras.split('|')
        for i, (missingWord) in enumerate(listaotras):
            if missingWord:
                listaotras2.append([missingWord])
        wordsarray=wordsarray + listaotras2 
        wordsarraylimpo= [wordsarray[i] for i in range(len(wordsarray)) if wordsarray[i] not in wordsarray[:i]]
        random.shuffle(wordsarraylimpo)
        for wdlista in wordsarraylimpo:
           wordslista +='<option value="%s">%s</option>' % (escape(wdlista[0], True), wdlista[0])
          
        for i, (text, missingWord) in enumerate(self.field.parts):
            if text:
                html.append(text)
            if missingWord:
                words += "'" + missingWord + "',"
                # The edit box for the user to type into
                inputHtml = ['<label for="clozeBlank%s.%s" class="sr-av">%s (%s):</label>' % (self.id, i, c_("Cloze"), (i+1))]
                inputHtml += ['<select id="clozeBlank%s.%s">' % (self.id, i),wordslista,'</select>']
                html += inputHtml
                            
                # Hidden span with correct answer
                html += ['<span style="display:none" id="clozeAnswer%s.%s">%s</span>' % (self.id, i, self.ecrypt(missingWord))]

        # Score string
        html += ['<div class="block iDevice_buttons">']
        html += ['<p>']
        
        if preview:
            html += [common.button('getScore%s' % self.id, c_(u"Check"), id='getScore%s' % self.id, class_ = "cloze-score-toggler")]
        else:
            html += [common.submitButton('getScore%s' % self.id, c_(u"Check"), id='getScore%s' % self.id)]
        if feedbackId:
            html += [common.button('feedback%s' % self.id, c_(u"Show Feedback"), class_ = "feedbackbutton cloze-feedback-toggler")]
         
        codotras=self.ecrypt(self.field.otras)
        html += [common.hiddenField('clozeOtras%s' % self.id,codotras)]   
        html += ['<input type="hidden" name="clozeFlag%s.strictMarking" id="clozeFlag%s.strictMarking" value="false" />' % (self.id,self.id)]
        html += ['<input type="hidden" name="clozeFlag%s.checkCaps" id="clozeFlag%s.checkCaps" value="false" />' % (self.id,self.id)]
        html += ['<input type="hidden" name="clozeFlag%s.instantMarking" id="clozeFlag%s.instantMarking" value="false" />' % (self.id,self.id)]
        html += [common.javaScriptIsRequired()]
        html += ['</p>']
        html += ['</div>']
        html += ['<div class="score js-feedback" id="clozeScore%s"></div>' % self.id]        
        html += ['</div>']
        if preview: 
            html += ['</div>']
        else:
            html += ['</form>']
        html += ['</%s>' % sectionTag]
        return '\n'.join(html)