コード例 #1
0
ファイル: views.py プロジェクト: sicikle/django-sis
def ajax_get_fill_all_form(request, course_id, object_type, object_id):
    model_base = Item if object_type == 'item' else Demonstration
    item_or_demonstration = get_object_or_404(model_base, pk=object_id)
    course = get_object_or_404(Course, pk=course_id)
    if type(item_or_demonstration) == Item and item_or_demonstration.course != course:
        raise Exception('This Item does not belong to the specified Course.')
    if type(item_or_demonstration) == Demonstration and item_or_demonstration.item.course != course:
        raise Exception('This Demonstration does not belong to the specified Course.')
    if type(item_or_demonstration) == Item and item_or_demonstration.category.allow_multiple_demonstrations:
        raise Exception('Marks must be assigned to Demonstrations for this Item, not directly to the Item.')
    if not item_or_demonstration.mark_set.count:
        raise Exception('This {} has no Marks.'.format(item_or_demonstration._meta.object_name))

    if request.POST:
        form = FillAllForm(request.POST, prefix="fill_all")
        if form.is_valid():
            for m in item_or_demonstration.mark_set.all():
                m.mark = form.cleaned_data['mark']
                m.save()
            messages.success(request, 'Marked all students {} for {}'.format(form.cleaned_data['mark'], item_or_demonstration))
            return HttpResponse('SUCCESS')
    else:
        form = FillAllForm(instance=item_or_demonstration.mark_set.all()[0], prefix="fill_all")
    return render_to_response('benchmark_grade/fill_all_form_fragment.html', {
        'action': request.path,
        'form': form,
        'subtitle': unicode(item_or_demonstration),
    }, RequestContext(request, {}),)
コード例 #2
0
ファイル: views.py プロジェクト: fluentglobe/django-sis
def ajax_get_fill_all_form(request, course_id, object_type, object_id):
    model_base = Item if object_type == 'item' else Demonstration
    item_or_demonstration = get_object_or_404(model_base, pk=object_id)
    course = get_object_or_404(Course, pk=course_id)
    if type(item_or_demonstration
            ) == Item and item_or_demonstration.course != course:
        raise Exception('This Item does not belong to the specified Course.')
    if type(item_or_demonstration
            ) == Demonstration and item_or_demonstration.item.course != course:
        raise Exception(
            'This Demonstration does not belong to the specified Course.')
    if type(
            item_or_demonstration
    ) == Item and item_or_demonstration.category.allow_multiple_demonstrations:
        raise Exception(
            'Marks must be assigned to Demonstrations for this Item, not directly to the Item.'
        )
    if not item_or_demonstration.mark_set.count:
        raise Exception('This {} has no Marks.'.format(
            item_or_demonstration._meta.object_name))

    if request.POST:
        form = FillAllForm(request.POST, prefix="fill_all")
        try:
            marking_period = item_or_demonstration.marking_period
        except AttributeError:
            marking_period = item_or_demonstration.item.marking_period
        if not request.user.has_perm(
                'grades.change_grade'
        ) and marking_period is not None and not marking_period.active:
            # you aren't a registrar, so you can't modify an item from an inactive marking period
            form.fields['mark'].validators.append(
                make_validationerror_raiser(
                    'This {} belongs to the inactive marking period {}.'.
                    format(object_type, marking_period)))
        if form.is_valid():
            for m in item_or_demonstration.mark_set.all():
                m.mark = form.cleaned_data['mark']
                m.save()
            messages.success(
                request, 'Marked all students {} for {}'.format(
                    form.cleaned_data['mark'], item_or_demonstration))
            return HttpResponse('SUCCESS')
    else:
        form = FillAllForm(instance=item_or_demonstration.mark_set.all()[0],
                           prefix="fill_all")
    return render_to_response(
        'benchmark_grade/fill_all_form_fragment.html',
        {
            'action': request.path,
            'form': form,
            'subtitle': unicode(item_or_demonstration),
        },
        RequestContext(request, {}),
    )
コード例 #3
0
ファイル: views.py プロジェクト: Sateanu/django-sis
def ajax_get_fill_all_form(request, course_id, object_type, object_id):
    model_base = Item if object_type == 'item' else Demonstration
    item_or_demonstration = get_object_or_404(model_base, pk=object_id)
    course = get_object_or_404(Course, pk=course_id)
    if type(item_or_demonstration) == Item and item_or_demonstration.course != course:
        raise Exception('This Item does not belong to the specified Course.')
    if type(item_or_demonstration) == Demonstration and item_or_demonstration.item.course != course:
        raise Exception('This Demonstration does not belong to the specified Course.')
    if type(item_or_demonstration) == Item and item_or_demonstration.category.allow_multiple_demonstrations:
        raise Exception('Marks must be assigned to Demonstrations for this Item, not directly to the Item.')
    if not item_or_demonstration.mark_set.count:
        raise Exception('This {} has no Marks.'.format(item_or_demonstration._meta.object_name))

    if request.POST:
        # we must pass in an instance, otherwise we fail unique validation 
        instance = item_or_demonstration.mark_set.all()[0]
        form = FillAllForm(request.POST, instance=instance, prefix="fill_all")
        try:
            marking_period = item_or_demonstration.marking_period
        except AttributeError:
            marking_period = item_or_demonstration.item.marking_period
        if not request.user.has_perm('grades.change_grade') and marking_period is not None and not marking_period.active:
                # you aren't a registrar, so you can't modify an item from an inactive marking period
                form.fields['mark'].validators.append(
                    make_validationerror_raiser('This {} belongs to the inactive marking period {}.'.format(object_type, marking_period))
                )
        if form.is_valid():
            for m in item_or_demonstration.mark_set.all():
                m.set_grade(form.cleaned_data['mark'])
                with reversion.create_revision():
                    m.save()
                    reversion.set_user(request.user)
                    reversion.set_comment("gradebook fill all")
                # really expensive!
                gradebook_recalculate_on_mark_change(m)
            messages.success(request, 'Marked all students {} for {}'.format(form.cleaned_data['mark'], item_or_demonstration))
            # the client will reload the whole page, so there's no need to pass a list of affected aggregate pks
            return HttpResponse('SUCCESS')
    else:
        form = FillAllForm(instance=item_or_demonstration.mark_set.all()[0], prefix="fill_all")
    return render_to_response('benchmark_grade/fill_all_form_fragment.html', {
        'action': request.path,
        'form': form,
        'subtitle': unicode(item_or_demonstration),
    }, RequestContext(request, {}),)
コード例 #4
0
def ajax_get_fill_all_form(request, course_id, object_type, object_id):
    model_base = Item if object_type == 'item' else Demonstration
    item_or_demonstration = get_object_or_404(model_base, pk=object_id)
    course = get_object_or_404(Course, pk=course_id)
    if type(item_or_demonstration
            ) == Item and item_or_demonstration.course != course:
        raise Exception('This Item does not belong to the specified Course.')
    if type(item_or_demonstration
            ) == Demonstration and item_or_demonstration.item.course != course:
        raise Exception(
            'This Demonstration does not belong to the specified Course.')
    if type(
            item_or_demonstration
    ) == Item and item_or_demonstration.category.allow_multiple_demonstrations:
        raise Exception(
            'Marks must be assigned to Demonstrations for this Item, not directly to the Item.'
        )
    if not item_or_demonstration.mark_set.count:
        raise Exception('This {} has no Marks.'.format(
            item_or_demonstration._meta.object_name))

    if request.POST:
        form = FillAllForm(request.POST, prefix="fill_all")
        if form.is_valid():
            for m in item_or_demonstration.mark_set.all():
                m.mark = form.cleaned_data['mark']
                m.save()
            messages.success(
                request, 'Marked all students {} for {}'.format(
                    form.cleaned_data['mark'], item_or_demonstration))
            return HttpResponse('SUCCESS')
    else:
        form = FillAllForm(instance=item_or_demonstration.mark_set.all()[0],
                           prefix="fill_all")
    return render_to_response(
        'benchmark_grade/fill_all_form_fragment.html',
        {
            'action': request.path,
            'form': form,
            'subtitle': unicode(item_or_demonstration),
        },
        RequestContext(request, {}),
    )