Esempio n. 1
0
def add_student_content_attempt(request, form):
    dajax = Dajax()

    try:

        form_dict={}
        for  obj in form:
            form_dict[obj['name']]=obj['value']
        form = StudentContentAttemptRequiredScoreForm(form_dict)

        try:
            sca=form.save()
        except ValueError:
            dajax.assign('#add_attempt_errors','innerHTML', "%s" % form['score'].errors)
            dajax.append('#add_attempt_errors','innerHTML', " %s" % form['datetime'].errors)
        else:
            total_score=sca.content.student_score(sca.student)
            number_attempts = len(sca.content.studentcontentattempt_set.filter(student=sca.student))
            table_row = "<tr><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp%s</td></tr>" % \
                (number_attempts, format_datetime(sca.datetime), sca.score)
            dajax.append('#attempt_table', 'innerHTML', table_row)
            dajax.assign('#assessment_score_table', 'innerHTML', total_score)
            dajax.assign('#assessment_score', 'innerHTML', total_score)
            dajax.script('toggleAttemptForm();')
            dajax.clear('#add_attempt_errors','innerHTML')
            
    except Exception as e:
        dajax.alert("something wrong: %s" % e)

    return dajax.json()
Esempio n. 2
0
def edit_student_content_attempt(request, form, attempt_id, attempt_number):
    dajax = Dajax()

    try:

        sca = StudentContentAttempt.objects.get(id=attempt_id)

        form_dict={}
        for  obj in form:
            form_dict[obj['name']]=obj['value']
        form = StudentContentAttemptRequiredScoreForm(form_dict, instance=sca)

        try:
            sca=form.save()
        except ValueError:
            dajax.assign('#edit_attempt_%i_errors' % attempt_number,
                         'innerHTML', "%s" % form['score'].errors)
            dajax.append('#edit_attempt_%i_errors' % attempt_number,
                         'innerHTML', " %s" % form['datetime'].errors)
        else:
            total_score=sca.content.student_score(sca.student)
            new_form = StudentContentAttemptRequiredScoreForm(instance=sca)
            dajax.assign('#edit_student_content_attempt_%i_form_inner' % \
                             attempt_number,\
                             'innerHTML', new_form.as_p())
            dajax.assign('#attempt_%i_score_inner' % attempt_number,\
                             'innerHTML', sca.score)
            dajax.assign('#assessment_score_table', 'innerHTML', total_score)
            dajax.assign('#assessment_score', 'innerHTML', total_score)
            dajax.script('toggleEditForm(%i);' % attempt_number)
            
            
    except Exception as e:
        dajax.alert("something wrong: %s" % e)

    return dajax.json()