Ignore:
Timestamp:
09/17/07 17:15:33 (12 years ago)
Author:
jukka
Message:

Added method get_values_from_fitbs which finds the correct answers for fill-in-the-blanks-chapter and returns them as dictionary. Dictionary has answers with keys 'exercise_x_answers_y', and the results are lists, as there can be many good answers. (Pjotr: Evaluating student's response should use this method.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ExerciseMaterial.py

    r2027 r2029  
    5858schema['title'].required = True 
    5959 
     60fill_in_the_blanks=re.compile(r"""(?P<filler>({.*?})+)""",  re.IGNORECASE) 
    6061 
    6162class ExerciseMaterial(Material): 
     
    107108        return extended_answers 
    108109 
     110    def get_values_from_fitbs(self, chapter_index): 
     111        """ find words in {}:s and return them as dict """ 
     112         
     113        text=self.getBodyText() 
     114        text=text[chapter_index][0] 
     115        matches=fill_in_the_blanks.findall(text) 
     116        results={} 
     117        index=0 
     118        print matches 
     119        for m in matches: 
     120            print m 
     121            answer=m[0] 
     122            answer=answer.strip(' {}') 
     123            answer=answer.split('}{') 
     124            print answer 
     125            results['exercise_%s_answer_%s' % (chapter_index, index)]=answer 
     126            index=index+1 
     127        print results 
     128        return results 
     129             
     130 
     131#    def replace_blanks_with_textfields(self, instance, field, chapter_index, show_answer=True): 
     132#        """ find words in { } and replace them with input boxes """ 
     133# 
     134#        replacement="""<input type="text" value="%s" name="exercise_%s_answer_%s" id="exercise_%s_answer_%s" /> """ 
     135#        self.iterator=0 
     136#         
     137#        def rep(match): 
     138#            value=match.group() 
     139#            answer_index=self.iterator 
     140#            if not show_answer: 
     141#                value=self.get 
     142#            else: 
     143#                value="" 
     144#            self.iterator=self.iterator+1 
     145#            return replacement % (value, chapter_index, answer_index, chapter_index, answer_index) 
     146# 
     147#        text=fill_in_the_blanks.sub(rep, fill_in_the_blanks) 
     148#        del self.iterator 
     149#        return text 
     150 
     151 
     152 
     153 
    109154registerType(ExerciseMaterial, PROJECTNAME) 
Note: See TracChangeset for help on using the changeset viewer.