Ignore:
Timestamp:
06/17/08 17:42:51 (11 years ago)
Author:
anonymous
Message:

References #1758, not ready yet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ExerciseMaterial.py

    r2410 r2417  
    165165        return text 
    166166 
    167  
    168  
     167    def replace_blanks_with_feedback(self, text, your_answerdict, i): 
     168        """ prepare the exercise for web-based feedback, make a html version out of it """ 
     169        fitb_correct_repl = u"""<span class="correct_fitb">%s</span>""" 
     170        fitb_incorrect_repl = u"""<span class="incorrect_fitb">%s</span> <span class="corrected_fitb">%s</span>""" 
     171        self.iterator = 0 
     172 
     173        def rep(match): 
     174            value = match.group('filler') 
     175            your_answer_all = your_answerdict.get('exercise_%s_answer_%s' % (i, self.iterator), '') 
     176            your_answer = your_answer_all[0] 
     177            self.iterator+=1 
     178            if your_answer_all[1] == 'correct': 
     179                return fitb_correct_repl % (to_unicode(your_answer.strip())) 
     180            elif your_answer_all[1] == 'incorrect': 
     181                return fitb_incorrect_repl % (to_unicode(your_answer.strip()), value) 
     182        text = fill_in_the_blanks.sub(rep, text) 
     183        del self.iterator 
     184        return text 
     185 
     186 
     187    def showWebFeedback(self, REQUEST): 
     188        """ Deals with the web-based feedback """ 
     189        feedbody = u'' 
     190        multiple_choices_repl = u"""<span class="%s"><input type="checkbox" value="%s" name="exercise_%s_answer_%s" id="exercise_%s_answer_%s" %s />%s</span><br />""" 
     191 
     192        exercise_body = self.getBodyText() 
     193 
     194        #XXX This one should check if there something has been submitted, if not -> just show the text 
     195        #return u"""<p>You have not provided any values</p>""" 
     196 
     197        # The juice is here 
     198        i = 0 
     199        for (chapter_text, chapter_type) in exercise_body: 
     200            if chapter_type == 'multiple_choices': 
     201                mchoice_body = u'' 
     202                correct_answers = chapter_text[1] 
     203                answers_total = correct_answers + chapter_text[2] 
     204                for a in range(len(correct_answers)): 
     205                    answer_value = REQUEST.get('exercise_%s_checkbox_%s' % (i,a),'') 
     206                    if answer_value: 
     207                        mchoice_body += multiple_choices_repl % ('correct_mc', '0', i, a, i, a, 'checked="checked"', correct_answers[a]) 
     208                    else: 
     209                        mchoice_body += multiple_choices_repl % ('incorrect_mc', '0', i, a, i, a, '', correct_answers[a]) 
     210                for a in range(len(correct_answers),len(answers_total)): 
     211                    answer_value = REQUEST.get('exercise_%s_checkbox_%s' % (i,a),'') 
     212                    if answer_value: 
     213                        mchoice_body += multiple_choices_repl % ('incorrect_mc', '0', i, a, i, a, 'checked="checked"', answers_total[a]) 
     214                    else: 
     215                        mchoice_body += multiple_choices_repl % ('correct_mc', '0', i, a, i, a, '', answers_total[a]) 
     216                feedbody += u"""<p>%s</p> <p>%s</p>""" % (chapter_text[0], mchoice_body) 
     217            elif chapter_type == 'fill_in_the_blanks': 
     218                correct_answer_dict = self.get_values_from_fitbs(i) 
     219                my_answer_dict = {} 
     220                all_answers_n = len(correct_answer_dict.keys()) 
     221                for it in range(all_answers_n): 
     222                    my_answer = REQUEST.get('exercise_%s_answer_%s' % (i,it),'') 
     223                    correct_answer = [to_unicode(c.strip()) for c in correct_answer_dict['exercise_%s_answer_%s' % (i,it)]] 
     224                    if to_unicode(my_answer.strip()) in correct_answer: 
     225                        my_answer_dict['exercise_%s_answer_%s' % (i,it)]=(my_answer, 'correct') 
     226                    else: 
     227                        my_answer_dict['exercise_%s_answer_%s' % (i,it)]=(my_answer, 'incorrect') 
     228                exercise_text = self.replace_blanks_with_feedback(chapter_text, my_answer_dict, i) 
     229                feedbody += u"""%s""" % (exercise_text) 
     230 
     231            i += 1 # increase the thing 
     232        if REQUEST.get('students_email', ''): 
     233            # START the e-mail sending method 
     234            # XXX Change the email-sending method not to redirect, just do the job and etll the user about the result 
     235            self.sendAnswers(REQUEST) 
     236        # XXX Create a redirector name "feedback" for "feedback_view" 
     237        return feedbody 
     238         
    169239    def sendAnswers(self, REQUEST): 
    170240        """ Send e-mail to a teacher """ 
     
    177247        teachers_email = REQUEST.get('teachers_email','') 
    178248 
     249        # XXX This might not be needed anymore, doing the check before calling out the mothod anyway 
    179250        if not students_email or (teachers_email and not students_name): 
    180251            msg = _(u"You have not provided enough information to send an e-mail.") 
    181252            putils.addPortalMessage(msg, type='warn') 
    182             return REQUEST.RESPONSE.redirect(self.absolute_url()) 
     253            #return REQUEST.RESPONSE.redirect(self.absolute_url()) 
    183254 
    184255        if not self.lemill_tool.validateCaptcha(REQUEST.get('captcha')): 
    185256            msg = _(u"Invalid answer for humanity test.") 
    186257            putils.addPortalMessage(msg, type='warn') 
    187             return REQUEST.RESPONSE.redirect(self.absolute_url()) 
     258            #return REQUEST.RESPONSE.redirect(self.absolute_url()) 
    188259         
    189260        exercise_body = self.getBodyText() 
     
    282353                msg = _(u"The e-mail has been sent to you and a teacher.") 
    283354                putils.addPortalMessage(msg) 
    284                 return REQUEST.RESPONSE.redirect(self.absolute_url()) 
     355                #return REQUEST.RESPONSE.redirect(self.absolute_url()) 
    285356            except: 
    286357                msg = _(u"The e-mail could not be sent.") 
    287358                putils.addPortalMessage(msg, type='warn') 
    288                 return REQUEST.RESPONSE.redirect(self.absolute_url()) 
     359                #return REQUEST.RESPONSE.redirect(self.absolute_url()) 
    289360        else: 
    290361            message_from = "%s <%s>" % ('LeMill', students_email) 
     
    294365                msg = _(u"The e-mail has been sent to you.") 
    295366                putils.addPortalMessage(msg) 
    296                 return REQUEST.RESPONSE.redirect(self.absolute_url()) 
     367                #return REQUEST.RESPONSE.redirect(self.absolute_url()) 
    297368            except: 
    298369                msg = _(u"The e-mail could not be sent.") 
    299370                putils.addPortalMessage(msg, type='warn') 
    300                 return REQUEST.RESPONSE.redirect(self.absolute_url()) 
     371                #return REQUEST.RESPONSE.redirect(self.absolute_url()) 
    301372 
    302373 
Note: See TracChangeset for help on using the changeset viewer.