Пример #1
0
def execute(state, plugin, argument):
    if not state.question:
        return
    stats = statistics.question_stats()
    columns = set()
    for s in stats.all_students:
        a = s.answer(state.question.name)
        if a.answered:
            for k in a.grades:
                if a.grades[k] != '0':
                    columns.add(k)
    columns = sorted(columns)

    table = []
    for s in stats.all_students:
        a = s.answer(state.question.name)
        if not a.answered:
            continue
        table.append([utilities.answer_format(a.answered)] +
                     [a.grades.get(c, 0) for c in columns])

    return utilities.sortable_table(plugin.sort_column,
                                    table,
                                    url=plugin.plugin.css_name,
                                    titles=['X'] + columns)
Пример #2
0
def execute(state, plugin, argument):
    if state.question == None:
        return

    teacher = state.student.filename

    if argument:
        the_student, grade = argument.split(',')
        if the_student.startswith('*'):
            the_student = the_student[1:]
            student.students[the_student].set_why(state.question.name, teacher,
                                                  grade)
        else:
            student.students[the_student].set_grade(state.question.name,
                                                    teacher, grade)
        return 'image/png', b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x01sRGB\x00\xae\xce\x1c\xe9\x00\x00\x00\x0fIDAT\x08\x1d\x01\x04\x00\xfb\xff\x00\x00\xff\x00\x02\x02\x01\x00\x0b\x0e\xaa\xaf\x00\x00\x00\x00IEND\xaeB`\x82'

    stats = statistics.question_stats()

    lines = []
    for s in stats.all_students:
        a = s.answer(state.question.name)
        if not a.answered:
            continue
        last = int(a.grades.get(teacher, '-1'))
        why = a.why.get(teacher, '')

        lines.append([
            utilities.answer_format(a.answered),
            '<span><!-- %2d -->' % last + ''.join(
                '<input name="%s" type="radio" value="%d" onclick="question_correction(event)"%s>&nbsp;%d'
                % (s.filename, i, ['', ' checked'][i == last], i) + {
                    0: '',
                    1: '',
                    2: '<br>'
                }[i % 3] for i in range(6)) + '</span>',
            '<textarea rows="2" cols="40" name="*%s" onchange="question_correction(event)">%s</textarea>'
            % (s.filename, cgi.escape(why)),
        ])

    if len(lines) == 0:
        return
    return ('<noscript>!!!!!!!JAVASCRIPT NEEDED!!!!!!</noscript>' +
            utilities.sortable_table(
                plugin.sort_column,
                lines,
                url=plugin.plugin.css_name,
                html_class="question_correction_table",
            ))
Пример #3
0
def execute(state, dummy_plugin, dummy_argument):
    if state.question == None:
        return
    if state.student.answered_question(state.question.name):
        return

    s = []
    for p in state.question.required:
        if p.hidden:
            continue
        if p.hide:
            continue
        q = questions.questions[p.name]
        question = q.get_question(state)
        try:
            answer = utilities.answer_format(
                state.student.answers[p.name].answered, question=question)
        except (KeyError, AttributeError):
            answer = ''
        question = question.split("{{{")[0]
        answer = '<div class="answer">' + answer + '</div>'
        if (q.courses or p.before) and q.before:
            before = q.get_before(state)
        else:
            before = ""
        s.append('<div class="tab"')
        if len(s) == 1:
            s.append(' id="first_tab"')
        s.append(
            '><div class="name" onclick="goto_tab((event||window.event).target)">'
        )
        s.append(cgi.escape(p.name))
        s.append("</div>")
        s.append('<div class="content">')
        s.append('<div class="before">')
        s.append(before)
        s.append("</div>")
        s.append('<div class="question">')
        s.append(question)
        s.append("</div>")
        s.append("</div>")
        s.append(answer)
        s.append("</div>")
    if s:
        return ('<div class="tabs">' + ''.join(s) + """</div>
<div id="display_tab"></div>
<div id="display_answer"></div>
<script>goto_tab(document.getElementById('first_tab'))</script>""")
Пример #4
0
def execute(state, plugin, argument):
    state.yes_it_is_good = False
    if state.question == None:
        return
    if state.question.tests == ():
        return
    if state.form.get('erase', False):
        state.student.erase(state.question.name)
    if argument and (
            state.question in state.student.answerables()
            or configuration.allowed_to_change_answer(state)
            or (state.student.answer(state.question.name).nr_good_answer
                and not state.student.answer(state.question.name).answered)
    ):
        if time.time() < state.student.answer(state.question.name
        ).suspended_until():
            return # Cheater

        # Fill 'last_answer' attribute
        state.student.bad_answer_yet_given(state.question.name, argument)
        # Check the answer even if it is a known one because
        # the question tests may have been updated in live
        number, message = state.student.check_answer(argument, state)
        if number:
            state.student.good_answer(state.question.name,argument)
            state.yes_it_is_good = True
        else:
            # Does not count the same bad answer
            if not state.student.bad_answer_yet_given(state.question.name,
                                                      argument):
                state.student.bad_answer(state.question.name, argument)

    if not state.question.answerable(state.student):
        state.question = None
        return '<p class="maximum_bad_answer">'

    if (not state.question.required.answered(state.student.answered_questions(),
                                            state.student)
        and not state.plugins_dict['questions_all'].current_acls['executable']
        ):
        return ('<p class="missing_required">: '
                + ', '.join(questions.questions[q].a_href()
                            for q in state.question.required.missing(
                                    state.student.answered_questions(),
                                    state.student)))

    if not isinstance(plugin.title, tuple):
        plugin.title = (plugin.title, plugin.title)

    question = state.question.get_question(state)

    if state.student.answered_question(state.question.name):
        # Value setted in question_change_answer plugin
        if not configuration.allowed_to_change_answer(state) or argument:
            s = state.student.last_answer(state.question.name)
            plugin.value_title = plugin.title[-1]

            if state.answer_always_visible or argument:
                return utilities.answer_format(s, question=question)
            else:
                return ('<div class="show_on_hover">'
                        + utilities.answer_format(s, question=question)
                        + '</div>')

    plugin.value_title = plugin.title[0]

    s = '<FORM CLASS="questionanswer" ID="questionanswer" accept-charset="utf-8" METHOD="GET" ACTION="#">'

    suspend = state.student.answer(state.question.name).suspended_until()
    s += "<script>suspended_until(" + str(suspend) + ");</script>"

    last_answer = state.student.last_answer(state.question.name)
    if last_answer == "":
        try:
            last_answer = state.question.default_answer(state)
        except TypeError:
            last_answer = state.question.default_answer
        style = ''
    else:
        if state.student.bad_answer_yet_given(state.question.name,
                                              last_answer):
            style = 'background:#FAA'
        else:
            # Assume it was a correct answer
            style = ''

    last_answer_html = (html.escape(last_answer)
                        .replace("%","&#37;")
                        .replace("'", "&#39;")
                        .replace('"', '&#34;'))

    if '{{{' in question:
        t = question.split('{{{')[1:]
        if '{{{ shuffle' in question:
            for i, line in enumerate(t):
                if line.startswith(" shuffle"):
                    line = line.split('}}}')
                    shuffle = line[0]
                    if line[1].strip():
                        t[i] = '}}}' + line[1]
                    else:
                        del t[i]
                    break
            if shuffle == " shuffle lines":
                t = shuffle_lines(t)
            elif shuffle == " shuffle blocs":
                last = 0
                newt = []
                t[-1] += '\n\n'
                for i, line in enumerate(t):
                    if '\n\n' in line:
                        newt += shuffle_lines(t[last: i+1])
                        last = i+1
                t = newt
            else:
                random.shuffle(t)
        nr_checked = 0
        for i in t:
            j = i.split('}}}')
            if j[0] == '$':
                s += j[1]
                continue
            if j[0].startswith('$'):
                key = j[0].lstrip('$')
                columns = len(j[0]) - len(key)
                if columns == 1:
                    columns = 10
                value = ''
                for k in last_answer.split('\n'):
                    if k.startswith(key + '='):
                        value = k[len(key)+1:]
                s += '<input onkeypress="check_button(this)" class="checkbox" name="%s$%s.%s.%s" value="%s" size="%s">' % (
                    plugin.plugin.css_name, key.replace('"', '&#34;'),
                    configuration.session.name,
                    html.escape(state.question.name),
                    value.replace('"', '&#34;'), columns
                    )
                s += j[1]
            else:
                if j[0].startswith('↑'):
                    j[0] = j[0][1:]
                    if s.endswith("<br>"):
                        s = s[:-4]
                if j[0].startswith('!'):
                    j[0] = j[0][1:]
                    button_type = "radio"
                elif j[0].startswith('$'):
                    j[0] = j[0][1:]
                    button_type = "text"
                else:
                    button_type = "checkbox"
                if j[0] == '':
                    s += j[1] + '<br>'
                    continue
                if j[0] in last_answer:
                    checked = ' checked'
                    if nr_checked == 0:
                        checked += ' id="2"'
                        nr_checked = 1
                else:
                    checked = ''
                s += '<label><input onchange="check_button(this)" class="checkbox" type="%s" name="%s" value="%s"%s>' % (
                    button_type, plugin.plugin.css_name,
                    j[0].replace('"', '&#34;'), checked
                ) + j[1] + '</label><br>'
        if nr_checked == 0:
            checked = ' id="2"'
        else:
            checked = ''
        s += '<button disabled type="submit"%s><p class="answer_button"></p></button>' % checked
    elif state.question.nr_lines == 1:
        s += '<INPUT TYPE="text" ID="2" NAME="%s.%s.%s" SIZE="%d" VALUE="%s" ALT="%s" onkeyup="if(this.value==this.alt && this.alt!==\'\') this.style.background=\'#FAA\'; else this.style.background=\'white\'" style="%s">'% (
            # INPUT NAME
            plugin.plugin.css_name, configuration.session.name,
            html.escape(state.question.name),
            #
            configuration.nr_columns, last_answer_html,
            style and last_answer_html or '',
            style)
    else:
        s += '<TEXTAREA NAME="%s" ID="2" COLS="%d" ROWS="%d" onkeypress="return disable_tab(event)">%s</TEXTAREA>' % (
            plugin.plugin.css_name,
            configuration.nr_columns,
            state.question.nr_lines,
            last_answer_html)
        s += '<br><button type="submit"><p class="answer_button"></p></button>'
        
    s += '''
</FORM>
<script type="text/javascript">
if ( ! window.disable_auto_focus )
    document.getElementById(2).focus() ;
window.scrollTo(0,0) ;
new PersistentInput("2", {}) ;
update_suspended_time() ;
</script>'''.format(json.dumps(state.question.name))
    if state.question.maximum_bad_answer:
        s += '<p class="nr_try">%d</p>' % (
            state.question.maximum_bad_answer
            - state.student.bad_answer_question(state.question.name))
    return s