Ejemplo n.º 1
0
    def add_questions_matching(self):
        matching_questions = []

        for n in xrange(2):
            ma_question = {}

            ma_question['name'] = 'Matching Question #%s' % (n + 1)
            ma_question['text'] = 'Text for matching question #%s' % (n + 1)
            ma_question['stamp'] = generate_stamp()
            ma_question['id'] = m_hash(ma_question)
            ma_question['general_feedback'] = 'Gen feedback for ma #%s' % (n + 1)

            answers = []

            for i in xrange(4):
                answer = {}

                answer['question_text'] = 'Question %s text for mc #%s' % (i, n)
                answer['answer_text'] = 'Question %s text for mc #%s' % (i, n)
                answer['id'] = m_hash(answer)

                answers.append(answer)

            ma_question['answers'] = answers

            matching_questions.append(ma_question)

        self.questions['matching'] = matching_questions
Ejemplo n.º 2
0
    def add_questions_shortanswer(self):
        shortanswer_questions = []

        for n in xrange(2):
            sa_question = {}

            sa_question['name'] = 'Shortanswer Question #%s' % (n + 1)
            sa_question['text'] = 'Text for shortanswer question #%s' % (n + 1)
            sa_question['stamp'] = generate_stamp()
            sa_question['id'] = m_hash(sa_question)
            sa_question['general_feedback'] = 'Gen feedback for sa #%s' % (n + 1)

            answers = []

            for i in xrange(4):
                answer = {}

                answer['answer_text'] = 'Answer %s text for sa #%s' % (i, n)
                answer['points'] = 1 if i == 1 else 0
                answer['feedback'] = 'Answer %s feedback for sa #%s' % (i, n)
                answer['id'] = m_hash(answer)

                answers.append(answer)

            sa_question['answers'] = answers

            sa_question['answer_string'] = ','.join(str(a['id']) for a in answers)

            shortanswer_questions.append(sa_question)

        self.questions['shortanswer'] = shortanswer_questions
Ejemplo n.º 3
0
    def _load(self):
        self.name = self.xml.find('.//presentation//mat_formattedtext').text
        self.text = self.name

        query = './/itemfeedback[@ident="correct"]//mat_formattedtext'

        true_fb_el = self.xml.find(query)
        false_fb_el = self.xml.find(query.replace('"c', '"inc'))

        self.true_feedback = true_fb_el.text if true_fb_el is not None else ''
        self.false_feedback = false_fb_el.text if false_fb_el is not None else ''

        answer_query = './/respcondition[@title="correct"]//varequal'

        answer_elem = self.xml.find(answer_query)

        if answer_elem is not None:
            a = answer_elem.text

            self.true_points, self.false_points = (1,
                                                   0) if a == 'true' else (0,
                                                                           1)

            self.true_answer_id = utils.m_hash(self, self.true_points)
            self.false_answer_id = utils.m_hash(self, self.false_points)
        else:
            # Survey
            # TODO: Make this multichoice
            self.true_points, self.false_points = (1, 0)

            self.true_answer_id = utils.m_hash(self, self.true_points)
            self.false_answer_id = utils.m_hash(self, self.false_points)
Ejemplo n.º 4
0
    def _load(self):
        self.name = self.xml.find('.//presentation//mat_formattedtext').text
        self.text = self.name

        query = './/itemfeedback[@ident="correct"]//mat_formattedtext'

        true_fb_el = self.xml.find(query)
        false_fb_el = self.xml.find(query.replace('"c', '"inc'))

        self.true_feedback = true_fb_el.text if true_fb_el is not None else ''
        self.false_feedback = false_fb_el.text if false_fb_el is not None else ''

        answer_query = './/respcondition[@title="correct"]//varequal'

        answer_elem = self.xml.find(answer_query)

        if answer_elem is not None:
            a = answer_elem.text

            self.true_points, self.false_points = (1, 0) if a == 'true' else (0, 1)

            self.true_answer_id = utils.m_hash(self, self.true_points)
            self.false_answer_id = utils.m_hash(self, self.false_points)
        else:
            # Survey
            # TODO: Make this multichoice
            self.true_points, self.false_points = (1, 0)

            self.true_answer_id = utils.m_hash(self, self.true_points)
            self.false_answer_id = utils.m_hash(self, self.false_points)
Ejemplo n.º 5
0
    def add_questions_shortanswer(self):
        shortanswer_questions = []

        for n in xrange(2):
            sa_question = {}

            sa_question['name'] = 'Shortanswer Question #%s' % (n + 1)
            sa_question['text'] = 'Text for shortanswer question #%s' % (n + 1)
            sa_question['stamp'] = generate_stamp()
            sa_question['id'] = m_hash(sa_question)
            sa_question['general_feedback'] = 'Gen feedback for sa #%s' % (n +
                                                                           1)

            answers = []

            for i in xrange(4):
                answer = {}

                answer['answer_text'] = 'Answer %s text for sa #%s' % (i, n)
                answer['points'] = 1 if i == 1 else 0
                answer['feedback'] = 'Answer %s feedback for sa #%s' % (i, n)
                answer['id'] = m_hash(answer)

                answers.append(answer)

            sa_question['answers'] = answers

            sa_question['answer_string'] = ','.join(
                str(a['id']) for a in answers)

            shortanswer_questions.append(sa_question)

        self.questions['shortanswer'] = shortanswer_questions
Ejemplo n.º 6
0
    def add_questions_matching(self):
        matching_questions = []

        for n in xrange(2):
            ma_question = {}

            ma_question['name'] = 'Matching Question #%s' % (n + 1)
            ma_question['text'] = 'Text for matching question #%s' % (n + 1)
            ma_question['stamp'] = generate_stamp()
            ma_question['id'] = m_hash(ma_question)
            ma_question['general_feedback'] = 'Gen feedback for ma #%s' % (n +
                                                                           1)

            answers = []

            for i in xrange(4):
                answer = {}

                answer['question_text'] = 'Question %s text for mc #%s' % (i,
                                                                           n)
                answer['answer_text'] = 'Question %s text for mc #%s' % (i, n)
                answer['id'] = m_hash(answer)

                answers.append(answer)

            ma_question['answers'] = answers

            matching_questions.append(ma_question)

        self.questions['matching'] = matching_questions
Ejemplo n.º 7
0
    def add_questions_multichoice(self):
        multichoice_questions = []

        for n in xrange(2):
            mc_question = {}

            mc_question['name'] = 'Multichoice Question #%s' % (n + 1)
            mc_question['text'] = 'Text for multichoice question #%s' % (n + 1)
            mc_question['stamp'] = generate_stamp()
            mc_question['single_answer'] = n
            mc_question['id'] = m_hash(mc_question)
            mc_question['general_feedback'] = 'Gen feedback for mc #%s' % (n + 1)
            mc_question['correct_feedback'] = 'Correct feedback for mc #%s' % (n + 1)
            mc_question['partially_correct_feedback'] = 'Partial feedback for mc #%s' % (n + 1)
            mc_question['incorrect_feecback'] = 'Incorrect feedback for mc #%s' % (n + 1)

            answers = []

            for i in xrange(4):
                answer = {}

                answer['answer_text'] = 'Answer %s text for mc #%s' % (i, n)
                answer['points'] = 1 if i == 1 else 0
                answer['feedback'] = 'Answer %s feedback for mc #%s' % (i, n)
                answer['id'] = m_hash(answer)

                answers.append(answer)

            mc_question['answers'] = answers

            mc_question['answer_string'] = ','.join(str(a['id']) for a in answers)

            multichoice_questions.append(mc_question)

        self.questions['multichoice'] = multichoice_questions
Ejemplo n.º 8
0
    def __init__(self, name, res_num):
        self.name = self.content = name
        self.res_num = res_num

        self.id = utils.m_hash(self)
        self.section_id = utils.m_hash(self)

        self.type = 'label'
Ejemplo n.º 9
0
    def __init__(self, name, res_num):
        self.name = self.content = name
        self.res_num = res_num

        self.id = utils.m_hash(self)
        self.section_id = utils.m_hash(self)

        self.type = 'label'
Ejemplo n.º 10
0
    def __init__(self, xml, res_num):
        if self.__class__ == 'Resource':
            raise NotImplementedError('Do not instantiate base class')

        self.res_num = res_num
        self.indent = 0

        ContentItem.__init__(self, xml)

        self.id = utils.m_hash(self)
        self.section_id = utils.m_hash(self)
Ejemplo n.º 11
0
    def __init__(self, xml, res_num):
        if self.__class__ == 'Resource':
            raise NotImplementedError('Do not instantiate base class')

        self.res_num = res_num
        self.indent = 0

        ContentItem.__init__(self, xml)

        self.id = utils.m_hash(self)
        self.section_id = utils.m_hash(self)
Ejemplo n.º 12
0
    def build_answers(self):
        self.single_answer = 1

        answer_query = './/respcondition[@title="correct"]//varequal'
        answer_elem = self.xml.find(answer_query)

        if answer_elem is not None:
            answer = answer_elem.text

            ans_type = answer.split('.')[0]

            true_points, false_points = (1,
                                         0) if answer.endswith('true') else (0,
                                                                             1)

            right_ans = {}
            right_ans['answer_text'] = self.ans_types[ans_type][0]
            right_ans['points'] = true_points

            if true_points == 1:
                right_ans['feedback'] = self.cor_fb
            else:
                right_ans['feedback'] = self.incor_fb

            right_ans['id'] = utils.m_hash(right_ans)  # Fix m_hash

            wrong_ans = {}
            wrong_ans['answer_text'] = self.ans_types[ans_type][1]
            wrong_ans['points'] = false_points

            if false_points == 1:
                wrong_ans['feedback'] = self.cor_fb
            else:
                wrong_ans['feedback'] = self.incor_fb

            wrong_ans['id'] = utils.m_hash(wrong_ans)  # Fix_mhash
        else:
            # TODO: Improve
            # Survey
            right_ans = {}
            right_ans['answer_text'] = 'Agree'
            right_ans['points'] = 1
            right_ans['feedback'] = ''
            right_ans['id'] = utils.m_hash(right_ans)  # Fix m_hash

            wrong_ans = {}
            wrong_ans['answer_text'] = 'Disagree'
            wrong_ans['points'] = 0
            wrong_ans['feedback'] = ''
            wrong_ans['id'] = utils.m_hash(wrong_ans)  # Fix_mhash

        self.answers = (right_ans, wrong_ans)
Ejemplo n.º 13
0
    def add_labels(self):
        self.labels = []

        for n in xrange(4):
            label = {}

            label['name'] = 'Label #%s' % (n + 1)
            label['content'] = '<i>Label #%s</i>' % (n + 1)
            label['id'] = m_hash(label['name'], label['content'])
            label['section_num'] = n
            label['section_id'] = m_hash(label['id'], label['section_num'])

            self.labels.append(label)
Ejemplo n.º 14
0
    def add_forums(self):
        self.forums = []

        for n in xrange(4):
            forum = {}

            forum['name'] = 'Forum #%s' % (n + 1)
            forum['introduction'] = 'Forum #%s introduction' % (n + 1)
            forum['id'] = m_hash(forum['name'], forum['introduction'])
            forum['section_num'] = n
            forum['section_id'] = m_hash(forum['id'], forum['section_num'])

            self.forums.append(forum)
Ejemplo n.º 15
0
    def add_forums(self):
        self.forums = []

        for n in xrange(4):
            forum = {}

            forum['name'] = 'Forum #%s' % (n + 1)
            forum['introduction'] = 'Forum #%s introduction' % (n + 1)
            forum['id'] = m_hash(forum['name'], forum['introduction'])
            forum['section_num'] = n
            forum['section_id'] = m_hash(forum['id'], forum['section_num'])

            self.forums.append(forum)
Ejemplo n.º 16
0
    def add_labels(self):
        self.labels = []

        for n in xrange(4):
            label = {}

            label['name'] = 'Label #%s' % (n + 1)
            label['content'] = '<i>Label #%s</i>' % (n + 1)
            label['id'] = m_hash(label['name'], label['content'])
            label['section_num'] = n
            label['section_id'] = m_hash(label['id'], label['section_num'])

            self.labels.append(label)
Ejemplo n.º 17
0
    def build_answers(self):
        self.single_answer = 1

        answer_query = './/respcondition[@title="correct"]//varequal'
        answer_elem = self.xml.find(answer_query)

        if answer_elem is not None:
            answer = answer_elem.text

            ans_type = answer.split('.')[0]

            true_points, false_points = (1, 0) if answer.endswith('true') else (0, 1)

            right_ans = {}
            right_ans['answer_text'] = self.ans_types[ans_type][0]
            right_ans['points'] = true_points

            if true_points == 1:
                right_ans['feedback'] = self.cor_fb
            else:
                right_ans['feedback'] = self.incor_fb

            right_ans['id'] = utils.m_hash(right_ans) # Fix m_hash

            wrong_ans = {}
            wrong_ans['answer_text'] = self.ans_types[ans_type][1]
            wrong_ans['points'] = false_points

            if false_points == 1:
                wrong_ans['feedback'] = self.cor_fb
            else:
                wrong_ans['feedback'] = self.incor_fb

            wrong_ans['id'] = utils.m_hash(wrong_ans) # Fix_mhash
        else:
            # TODO: Improve
            # Survey
            right_ans = {}
            right_ans['answer_text'] = 'Agree'
            right_ans['points'] = 1
            right_ans['feedback'] = ''
            right_ans['id'] = utils.m_hash(right_ans) # Fix m_hash

            wrong_ans = {}
            wrong_ans['answer_text'] = 'Disagree'
            wrong_ans['points'] = 0
            wrong_ans['feedback'] = ''
            wrong_ans['id'] = utils.m_hash(wrong_ans) # Fix_mhash

        self.answers = (right_ans, wrong_ans)
Ejemplo n.º 18
0
    def build_answers(self):
        self.single_answer = 0

        answer_query = './/render_choice//response_label'

        for answer_elem in self.xml.findall(answer_query):
            answer = {}
            answer['ident'] = answer_elem.attrib['ident']
            answer['answer_text'] = answer_elem.find(
                './/mat_formattedtext').text

            # Filter out blank choices
            if not answer['answer_text']:
                continue

            self.answers.append(answer)

        query = './/respcondition[@title="correct"]//and/varequal'
        correct_idents = [a.text for a in self.xml.findall(query)]

        for answer in self.answers:
            if answer['ident'] in correct_idents:
                answer['points'] = 1
                answer['feedback'] = self.cor_fb
            else:
                answer['points'] = 0
                answer['feedback'] = self.incor_fb

            answer['id'] = utils.m_hash(answer)
Ejemplo n.º 19
0
    def _load(self):
        self.name = self.xml.find('.//presentation//mat_formattedtext').text
        self.text = self.name

        self.answers = []

        answer_query = './/render_choice//response_label'

        for answer_elem in self.xml.findall(answer_query):
            answer = {}
            answer['ident'] = answer_elem.attrib['ident']
            answer['question_text'] = answer_elem.find(
                './/mat_formattedtext').text

            self.answers.append(answer)

        query = './/respcondition[@title="correct"]//varequal'
        ordered_ident_elems = self.xml.findall(query)

        for n, ordered_ident_elem in enumerate(ordered_ident_elems):
            for answer in self.answers:
                if answer['ident'] == ordered_ident_elem.text:
                    answer['answer_text'] = n + 1

                    break

        for answer in self.answers:
            answer['id'] = utils.m_hash(answer)
Ejemplo n.º 20
0
    def add_questions_essay(self):
        essay_questions = []

        for n in xrange(2):
            essay_question = {}

            essay_question['name'] = 'Essay Question #%s' % (n + 1)
            essay_question['text'] = 'Text for essay question #%s' % (n + 1)
            essay_question['stamp'] = generate_stamp()
            essay_question['id'] = m_hash(essay_question)
            essay_question['feedback'] = 'Feedback for Essay Question #%s' % (n + 1)
            essay_question['answer_id'] = m_hash(essay_question)

            essay_questions.append(essay_question)

        self.questions['essay'] = essay_questions
Ejemplo n.º 21
0
    def build_answers(self):
        self.single_answer = 0

        answer_query = './/render_choice//response_label'

        for answer_elem in self.xml.findall(answer_query):
            answer = {}
            answer['ident'] = answer_elem.attrib['ident']
            answer['answer_text'] = answer_elem.find('.//mat_formattedtext').text

            # Filter out blank choices
            if not answer['answer_text']:
                continue

            self.answers.append(answer)

        query = './/respcondition[@title="correct"]//and/varequal'
        correct_idents = [a.text for a in self.xml.findall(query)]

        for answer in self.answers:
            if answer['ident'] in correct_idents:
                answer['points'] = 1
                answer['feedback'] = self.cor_fb
            else:
                answer['points'] = 0
                answer['feedback'] = self.incor_fb

            answer['id'] = utils.m_hash(answer)
Ejemplo n.º 22
0
    def __init__(self, archive_filename):
        self.archive_filename = archive_filename

        self.timestamp = str(time.time()).split('.')[0]

        try:
            self.zip = zipfile.ZipFile(self.archive_filename)
        except zipfile.error:
            raise zipfile.error(self.archive_filename)

        self.manifest = self.parse_manifest()

        self.forums = []
        self.labels = []
        self.quizzes = []
        self.resources = []

        self.questions = {}
        self.questions['essay'] = []
        self.questions['matching'] = []
        self.questions['truefalse'] = []
        self.questions['shortanswer'] = []
        self.questions['multichoice'] = []

        self.convert_resources()

        self.sections = self.create_default_sections()
        self.sections += self.create_content_areas()

        self.quiz_category_stamp = utils.generate_stamp()
        self.quiz_category_id = utils.m_hash(self.quiz_category_stamp)

        self.has_questions = any(self.questions.values())

        self.zip.close()
Ejemplo n.º 23
0
    def _load(self):
        self.name = self.xml.find('.//presentation//mat_formattedtext').text
        self.text = self.name

        self.answers = []

        answer_query = './/render_choice//response_label'

        for answer_elem in self.xml.findall(answer_query):
            answer = {}
            answer['ident'] = answer_elem.attrib['ident']
            answer['question_text'] = answer_elem.find('.//mat_formattedtext').text

            self.answers.append(answer)

        query = './/respcondition[@title="correct"]//varequal'
        ordered_ident_elems = self.xml.findall(query)

        for n, ordered_ident_elem in enumerate(ordered_ident_elems):
            for answer in self.answers:
                if answer['ident'] == ordered_ident_elem.text:
                    answer['answer_text'] = n + 1

                    break

        for answer in self.answers:
            answer['id'] = utils.m_hash(answer)
Ejemplo n.º 24
0
    def add_questions_essay(self):
        essay_questions = []

        for n in xrange(2):
            essay_question = {}

            essay_question['name'] = 'Essay Question #%s' % (n + 1)
            essay_question['text'] = 'Text for essay question #%s' % (n + 1)
            essay_question['stamp'] = generate_stamp()
            essay_question['id'] = m_hash(essay_question)
            essay_question['feedback'] = 'Feedback for Essay Question #%s' % (
                n + 1)
            essay_question['answer_id'] = m_hash(essay_question)

            essay_questions.append(essay_question)

        self.questions['essay'] = essay_questions
Ejemplo n.º 25
0
    def build_answers(self):
        self.single_answer = 1

        answer_query = './/render_choice//response_label'

        for answer_elem in self.xml.findall(answer_query):
            answer = {}
            answer['ident'] = answer_elem.attrib['ident']
            answer['answer_text'] = answer_elem.find(
                './/mat_formattedtext').text

            # Filter out blank choices
            if not answer['answer_text']:
                continue
            while '@[email protected]@X@bbcswebdav' in answer[
                    'answer_text']:
                answer['answer_text'] = self.handle_embedded_stubfile(
                    answer['answer_text'])

            self.answers.append(answer)

        query = './/respcondition[@title="correct"]//varequal'

        correct_elem = self.xml.find(query)

        if correct_elem is not None:
            correct_ident = correct_elem.text

            for answer in self.answers:
                if answer['ident'] == correct_ident:
                    answer['points'] = 1
                    answer['feedback'] = self.cor_fb
                else:
                    answer['points'] = 0
                    answer['feedback'] = self.incor_fb

                answer['id'] = utils.m_hash(answer)
        else:
            for answer in self.answers:
                answer['points'] = 1
                answer['feedback'] = self.cor_fb
                answer['id'] = utils.m_hash(answer)
Ejemplo n.º 26
0
    def add_questions_multichoice(self):
        multichoice_questions = []

        for n in xrange(2):
            mc_question = {}

            mc_question['name'] = 'Multichoice Question #%s' % (n + 1)
            mc_question['text'] = 'Text for multichoice question #%s' % (n + 1)
            mc_question['stamp'] = generate_stamp()
            mc_question['single_answer'] = n
            mc_question['id'] = m_hash(mc_question)
            mc_question['general_feedback'] = 'Gen feedback for mc #%s' % (n +
                                                                           1)
            mc_question['correct_feedback'] = 'Correct feedback for mc #%s' % (
                n + 1)
            mc_question[
                'partially_correct_feedback'] = 'Partial feedback for mc #%s' % (
                    n + 1)
            mc_question[
                'incorrect_feecback'] = 'Incorrect feedback for mc #%s' % (n +
                                                                           1)

            answers = []

            for i in xrange(4):
                answer = {}

                answer['answer_text'] = 'Answer %s text for mc #%s' % (i, n)
                answer['points'] = 1 if i == 1 else 0
                answer['feedback'] = 'Answer %s feedback for mc #%s' % (i, n)
                answer['id'] = m_hash(answer)

                answers.append(answer)

            mc_question['answers'] = answers

            mc_question['answer_string'] = ','.join(
                str(a['id']) for a in answers)

            multichoice_questions.append(mc_question)

        self.questions['multichoice'] = multichoice_questions
Ejemplo n.º 27
0
    def add_sections(self):
        self.sections = []

        for n in xrange(5):
            section = {}

            section['number'] = n
            section['summary'] = '<h2>Test Section #%s</h2>' % (n + 1)
            section['visible'] = 1
            section['id'] = m_hash(section['number'], section['summary'])

            self.sections.append(section)
Ejemplo n.º 28
0
    def add_sections(self):
        self.sections = []

        for n in xrange(5):
            section = {}

            section['number'] = n
            section['summary'] = '<h2>Test Section #%s</h2>' % (n + 1)
            section['visible'] = 1
            section['id'] = m_hash(section['number'], section['summary'])

            self.sections.append(section)
Ejemplo n.º 29
0
    def _load(self):
        self.name = self.xml.find('.//presentation//mat_formattedtext').text
        self.text = self.name

        self.answers = []

        for answer_text in [e.text for e in self.xml.findall('.//varequal')]:
            answer = {}
            answer['answer_text'] = answer_text
            answer['points'] = 1
            answer['id'] = utils.m_hash(answer)

            self.answers.append(answer)
Ejemplo n.º 30
0
    def _load(self):
        self.name = self.xml.find('.//presentation//mat_formattedtext').text
        self.text = self.name

        self.answers = []

        for answer_text in [e.text for e in self.xml.findall('.//varequal')]:
            answer = {}
            answer['answer_text'] = answer_text
            answer['points'] = 1
            answer['id'] = utils.m_hash(answer)

            self.answers.append(answer)
Ejemplo n.º 31
0
    def add_questions_truefalse(self):
        truefalse_questions = []

        for n in xrange(2):
            tf_question = {}

            tf_question['name'] = 'True/False Question #%s' % (n + 1)
            tf_question['text'] = 'Text for truefalse question #%s' % (n + 1)
            tf_question['stamp'] = generate_stamp()
            tf_question['id'] = m_hash(tf_question)
            tf_question['general_feedback'] = 'Gen feedback for tf #%s' % (n + 1)

            tf_question['true_answer_id'] = m_hash(tf_question)
            tf_question['true_points'] = n
            tf_question['true_feedback'] = '#%s true feedback' % (n + 1)

            tf_question['false_answer_id'] = m_hash(tf_question)
            tf_question['false_points'] = -n + 1
            tf_question['false_feedback'] = '#%s false feedback' % (n + 1)

            truefalse_questions.append(tf_question)

        self.questions['truefalse'] = truefalse_questions
Ejemplo n.º 32
0
    def add_questions_truefalse(self):
        truefalse_questions = []

        for n in xrange(2):
            tf_question = {}

            tf_question['name'] = 'True/False Question #%s' % (n + 1)
            tf_question['text'] = 'Text for truefalse question #%s' % (n + 1)
            tf_question['stamp'] = generate_stamp()
            tf_question['id'] = m_hash(tf_question)
            tf_question['general_feedback'] = 'Gen feedback for tf #%s' % (n +
                                                                           1)

            tf_question['true_answer_id'] = m_hash(tf_question)
            tf_question['true_points'] = n
            tf_question['true_feedback'] = '#%s true feedback' % (n + 1)

            tf_question['false_answer_id'] = m_hash(tf_question)
            tf_question['false_points'] = -n + 1
            tf_question['false_feedback'] = '#%s false feedback' % (n + 1)

            truefalse_questions.append(tf_question)

        self.questions['truefalse'] = truefalse_questions
Ejemplo n.º 33
0
    def add_resources(self):
        text_res = {}
        text_res['name'] = 'Text Page Resource'
        text_res['type'] = 'text'
        text_res['reference'] = '2'
        text_res['summary'] = 'Text Page Resource Summary'
        text_res['alltext'] = 'Blah Blah Blah Blah'
        text_res['id'] = m_hash(text_res['name'], text_res['alltext'])
        text_res['section_num'] = 4
        text_res['section_id'] = m_hash(text_res['id'],
                                        text_res['section_num'])

        html_res = {}
        html_res['name'] = 'Web Page Resource'
        html_res['type'] = 'html'
        html_res['reference'] = '2'
        html_res['summary'] = 'Web Page Resource Summary'
        html_res['alltext'] = '<h2>Blah Blah Blah Blah</h2>'
        html_res['id'] = m_hash(html_res['name'], html_res['alltext'])
        html_res['section_num'] = 4
        html_res['section_id'] = m_hash(html_res['id'],
                                        html_res['section_num'])

        link_res = {}
        link_res['name'] = 'Link Resource'
        link_res['type'] = 'file'
        link_res['reference'] = 'http://cnn.com'
        link_res['summary'] = 'Link Resource Summary'
        link_res['alltext'] = ''
        link_res['id'] = m_hash(link_res['name'], link_res['reference'])
        link_res['section_num'] = 4
        link_res['section_id'] = m_hash(link_res['id'],
                                        link_res['section_num'])

        file_res = {}
        file_res['name'] = 'File Resource'
        file_res['type'] = 'file'
        file_res['reference'] = 'moodle.xml'
        file_res['summary'] = 'File Resource Summary'
        file_res['alltext'] = ''
        file_res['id'] = m_hash(file_res['name'], file_res['reference'])
        file_res['section_num'] = 4
        file_res['section_id'] = m_hash(file_res['id'],
                                        file_res['section_num'])

        self.resources = [text_res, html_res, link_res, file_res]
Ejemplo n.º 34
0
    def _load(self):
        self.name = self.xml.find('.//presentation//mat_formattedtext').text
        while '@[email protected]@X@bbcswebdav' in self.name:
            self.name = self.handle_embedded_stubfile(self.name)
        self.text = self.name

        self.answers = []

        for answer_text in [e.text for e in self.xml.findall('.//varequal')]:
            while '@[email protected]@X@bbcswebdav' in answer_text:
                answer_text = self.handle_embedded_stubfile(answer_text)
            answer = {}
            answer['answer_text'] = answer_text
            answer['points'] = 1
            answer['id'] = utils.m_hash(answer)

            self.answers.append(answer)
Ejemplo n.º 35
0
    def add_resources(self):
        text_res = {}
        text_res['name'] = 'Text Page Resource'
        text_res['type'] = 'text'
        text_res['reference'] = '2'
        text_res['summary'] = 'Text Page Resource Summary'
        text_res['alltext'] = 'Blah Blah Blah Blah'
        text_res['id'] = m_hash(text_res['name'], text_res['alltext'])
        text_res['section_num'] = 4
        text_res['section_id'] = m_hash(text_res['id'], text_res['section_num'])

        html_res = {}
        html_res['name'] = 'Web Page Resource'
        html_res['type'] = 'html'
        html_res['reference'] = '2'
        html_res['summary'] = 'Web Page Resource Summary'
        html_res['alltext'] = '<h2>Blah Blah Blah Blah</h2>'
        html_res['id'] = m_hash(html_res['name'], html_res['alltext'])
        html_res['section_num'] = 4
        html_res['section_id'] = m_hash(html_res['id'], html_res['section_num'])

        link_res = {}
        link_res['name'] = 'Link Resource'
        link_res['type'] = 'file'
        link_res['reference'] = 'http://cnn.com'
        link_res['summary'] = 'Link Resource Summary'
        link_res['alltext'] = ''
        link_res['id'] = m_hash(link_res['name'], link_res['reference'])
        link_res['section_num'] = 4
        link_res['section_id'] = m_hash(link_res['id'], link_res['section_num'])

        file_res = {}
        file_res['name'] = 'File Resource'
        file_res['type'] = 'file'
        file_res['reference'] = 'moodle.xml'
        file_res['summary'] = 'File Resource Summary'
        file_res['alltext'] = ''
        file_res['id'] = m_hash(file_res['name'], file_res['reference'])
        file_res['section_num'] = 4
        file_res['section_id'] = m_hash(file_res['id'], file_res['section_num'])

        self.resources = [text_res, html_res, link_res, file_res]
Ejemplo n.º 36
0
    def __init__(self, xml, res_num):
        if self.__class__ == 'Question':
            raise NotImplementedError('Do not instantiate base class')
        self.res_num = res_num
        ContentItem.__init__(self, xml)

        if not self.name:
            self.name = '________'

        self.name = re.sub(r'<.*?>', '', self.name).strip()

        query = './/flow[@class="FILE_BLOCK"]//matapplication'

        for elem in self.xml.findall(query):
            self.image = utils.fix_filename(elem.attrib['label'], res_num)

        self.stamp = utils.generate_stamp()
        self.id = utils.m_hash(self)
Ejemplo n.º 37
0
    def _load(self):
        self.name = self.xml.find('.//presentation//mat_formattedtext').text
        self.text = self.name

        self.answers = []

        ident_query = './/flow[@class="RESPONSE_BLOCK"]//response_lid'
        text_query = './/flow[@class="RESPONSE_BLOCK"]//mat_formattedtext'

        idents = self.xml.findall(ident_query)
        texts = self.xml.findall(text_query)

        for n, i in enumerate(self.xml.findall(ident_query)):
            answer = {}
            answer['ident'] = idents[n].attrib['ident']
            answer['question_text'] = texts[n].text

            labels = idents[n].findall('.//response_label')

            answer['choice_idents'] = tuple([l.attrib['ident'] for l in labels])

            self.answers.append(answer)

        answer_query = './/flow[@class="RIGHT_MATCH_BLOCK"]//mat_formattedtext'

        answer_texts = [a.text for a in self.xml.findall(answer_query)]

        for match in self.xml.findall('.//varequal'):
            question_ident = match.attrib['respident']
            answer_ident = match.text

            for answer in self.answers:
                if answer['ident'] == question_ident:
		    try:
                    	i = answer['choice_idents'].index(answer_ident)
		    except Exception:
			break

                    answer['answer_text'] = answer_texts[i]

                    break

        for answer in self.answers:
            answer['id'] = utils.m_hash(answer)
Ejemplo n.º 38
0
    def _load(self):
        self.name = self.xml.find('.//presentation//mat_formattedtext').text
        while '@[email protected]@X@bbcswebdav' in self.name:
            self.name = self.handle_embedded_stubfile(self.name)
        self.text = self.name

        self.answers = []

        ident_query = './/flow[@class="RESPONSE_BLOCK"]//response_lid'
        text_query = './/flow[@class="RESPONSE_BLOCK"]//mat_formattedtext'

        idents = self.xml.findall(ident_query)
        texts = self.xml.findall(text_query)

        for n, i in enumerate(self.xml.findall(ident_query)):
            answer = {}
            answer['ident'] = idents[n].attrib['ident']
            answer['question_text'] = texts[n].text

            labels = idents[n].findall('.//response_label')

            answer['choice_idents'] = tuple(
                [l.attrib['ident'] for l in labels])

            self.answers.append(answer)

        answer_query = './/flow[@class="RIGHT_MATCH_BLOCK"]//mat_formattedtext'

        answer_texts = [a.text for a in self.xml.findall(answer_query)]

        for match in self.xml.findall('.//varequal'):
            question_ident = match.attrib['respident']
            answer_ident = match.text

            for answer in self.answers:
                if answer['ident'] == question_ident:
                    i = answer['choice_idents'].index(answer_ident)

                    answer['answer_text'] = answer_texts[i]

                    break

        for answer in self.answers:
            answer['id'] = utils.m_hash(answer)
Ejemplo n.º 39
0
    def __init__(self, xml, res_num):
        if self.__class__ == 'Question':
            raise NotImplementedError('Do not instantiate base class')

        ContentItem.__init__(self, xml)

        if not self.name:
            self.name = '________'

        self.name = re.sub(r'<.*?>', '', self.name).strip()
        self.res_num = res_num

        query = './/flow[@class="FILE_BLOCK"]//matapplication'

        for elem in self.xml.findall(query):
            self.image = utils.fix_filename(elem.attrib['label'], res_num)

        self.stamp = utils.generate_stamp()
        self.id = utils.m_hash(self)
Ejemplo n.º 40
0
    def _load(self):
        self.name = self.xml.find('.//assessment').attrib['title']

        self.stamp = utils.generate_stamp()

        self.category_id = utils.m_hash(self.name, self.stamp)

        query = './/presentation_material//mat_formattedtext'
        description = self.xml.find(query).text

        query = './/rubric[@view="All"]//mat_formattedtext'
        instructions = self.xml.find(query).text

        description = '' if not description else description
        instructions = '' if not instructions else instructions

        self.intro = description + '<br /><br />' + instructions

        self.intro = '' if self.intro == '<br /><br />' else self.intro

        self.type = 'quiz'
Ejemplo n.º 41
0
    def _load(self):
        self.name = self.xml.find('.//assessment').attrib['title']

        self.stamp = utils.generate_stamp()

        self.category_id = utils.m_hash(self.name, self.stamp)

        query = './/presentation_material//mat_formattedtext'
        description = self.xml.find(query).text

        query = './/rubric[@view="All"]//mat_formattedtext'
        instructions = self.xml.find(query).text

        description = '' if not description else description
        instructions = '' if not instructions else instructions

        self.intro = description + '<br /><br />' + instructions

        self.intro = '' if self.intro == '<br /><br />' else self.intro

        self.type = 'quiz'
Ejemplo n.º 42
0
    def _load(self):
        self.name = self.xml.find('.//assessment').attrib['title']

        self.stamp = utils.generate_stamp()

        self.category_id = utils.m_hash(self.name, self.stamp)

        query = './/presentation_material//mat_formattedtext'
        description = self.xml.find(query).text

        query = './/rubric[@view="All"]//mat_formattedtext'
        instructions = self.xml.find(query).text

        description = '' if not description else description
        instructions = '' if not instructions else instructions

        self.intro = description + '<br /><br />' + instructions

        self.intro = '' if self.intro == '<br /><br />' else self.intro
        while '@[email protected]@X@bbcswebdav' in self.intro:
            self.intro = self.handle_embedded_stubfile(self.intro)
        self.type = 'quiz'
Ejemplo n.º 43
0
    def __init__(self, archive_filename, course_id, parameters):
        self.archive_filename = archive_filename
	self.course_id = course_id
	self.parameters = parameters

        self.timestamp = str(time.time()).split('.')[0]

        try:
            self.zip = zipfile.ZipFile(self.archive_filename)
        except zipfile.error:
            raise zipfile.error(self.archive_filename)

        self.manifest = self.parse_manifest()

        self.forums = []
        self.labels = []
        self.quizzes = []
        self.resources = []

        self.questions = {}
        self.questions['essay'] = []
        self.questions['matching'] = []
        self.questions['truefalse'] = []
        self.questions['shortanswer'] = []
        self.questions['multichoice'] = []

        self.convert_resources()

        self.sections = self.create_default_sections()
        self.sections += self.create_content_areas()

        self.quiz_category_stamp = utils.generate_stamp()
        self.quiz_category_id = utils.m_hash(self.quiz_category_stamp)

        self.has_questions = any(self.questions.values())

        self.zip.close()
Ejemplo n.º 44
0
 def _load(self):
     self.name = self.xml.find('.//presentation//mat_formattedtext').text
     while '@[email protected]@X@bbcswebdav' in self.name:
         self.name = self.handle_embedded_stubfile(self.name)
     self.text = self.name
     self.answer_id = utils.m_hash(self)
Ejemplo n.º 45
0
    def __init__(self, xml, quiz_questions, res_num):
        Resource.__init__(self, xml, res_num)

        self.questions = quiz_questions
        self.question_string = ','.join([str(q.id) for q in self.questions])
        self.feedback_id = utils.m_hash(self)
Ejemplo n.º 46
0
    def __init__(self, xml, quiz_questions, res_num):
        Resource.__init__(self, xml, res_num)

        self.questions = quiz_questions
        self.question_string = ','.join([str(q.id) for q in self.questions])
        self.feedback_id = utils.m_hash(self)
Ejemplo n.º 47
0
 def _load(self):
     self.name = self.xml.find('.//presentation//mat_formattedtext').text
     self.text = self.name
     self.answer_id = utils.m_hash(self)
Ejemplo n.º 48
0
 def _load(self):
     self.name = self.xml.find('.//presentation//mat_formattedtext').text
     self.text = self.name
     self.answer_id = utils.m_hash(self)