def ajax_save_grade(request): if 'mark_id' in request.POST and 'value' in request.POST: mark_id = request.POST['mark_id'].strip() value = request.POST['value'].strip() try: mark = Mark.objects.get(id=mark_id) except Mark.DoesNotExist: return HttpResponse('NO MARK WITH ID ' + mark_id, status=404) if not request.user.is_superuser and not request.user.groups.filter(name='registrar').count() \ and request.user.username != mark.item.course.teacher.username \ and not mark.item.course.secondary_teachers.filter(username=request.user.username).count(): return HttpResponse(status=403) if len(value) and value.lower != 'none': mark.mark = value else: mark.mark = None value = 'None' # temporarily log who's changing stuff since i'll have to manually recalculate averages later mark.description += ',' + request.user.username try: mark.full_clean() mark.save() except Exception as e: return HttpResponse(e, status=400) gradebook_recalculate_on_mark_change(mark) # just the whole course average for now # TODO: update filtered average average = gradebook_get_average(mark.student, mark.item.course, None, None, None) return HttpResponse(json.dumps({'success': 'SUCCESS', 'value': value, 'average': str(average)})) else: return HttpResponse('POST DATA INCOMPLETE', status=400)
def ajax_save_grade(request): if 'mark_id' in request.POST and 'value' in request.POST: mark_id = request.POST['mark_id'].strip() value = request.POST['value'].strip() try: mark = Mark.objects.get(id=mark_id) except Mark.DoesNotExist: return HttpResponse('NO MARK WITH ID ' + mark_id, status=404) if not request.user.is_superuser and not request.user.groups.filter(name='registrar').count() \ and request.user.username != mark.item.course.teacher.username \ and not mark.item.course.secondary_teachers.filter(username=request.user.username).count(): return HttpResponse(status=403) if len(value) and value.lower != 'none': mark.mark = value else: mark.mark = None value = 'None' try: with reversion.create_revision(): mark.full_clean() mark.save() reversion.set_user(request.user) reversion.set_comment("gradebook") except Exception as e: return HttpResponse(e, status=400) affected_agg_pks = [x.pk for x in gradebook_recalculate_on_mark_change(mark)] # just the whole course average for now # TODO: update filtered average #average = gradebook_get_average(mark.student, mark.item.course, None, None, None) return HttpResponse(json.dumps({'success': 'SUCCESS', 'value': value, 'average': 'Please clear your browser\'s cache.', 'affected_aggregates': affected_agg_pks})) else: return HttpResponse('POST DATA INCOMPLETE', status=400)
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, {}),)
def ajax_save_grade(request): if 'mark_id' in request.POST and 'value' in request.POST: mark_id = request.POST['mark_id'].strip() value = request.POST['value'].strip() try: mark = Mark.objects.get(id=mark_id) except Mark.DoesNotExist: return HttpResponse('NO MARK WITH ID ' + mark_id, status=404) if not request.user.is_superuser and not request.user.groups.filter(name='registrar').count() \ and request.user.username != mark.item.course.teacher.username \ and not mark.item.course.secondary_teachers.filter(username=request.user.username).count(): return HttpResponse(status=403) if len(value) and value.lower != 'none': mark.mark = value else: mark.mark = None value = 'None' # temporarily log who's changing stuff since i'll have to manually recalculate averages later mark.description += ',' + request.user.username try: mark.full_clean() mark.save() except Exception as e: return HttpResponse(e, status=400) gradebook_recalculate_on_mark_change(mark) # just the whole course average for now # TODO: update filtered average average = gradebook_get_average(mark.student, mark.item.course, None, None, None) return HttpResponse( json.dumps({ 'success': 'SUCCESS', 'value': value, 'average': str(average) })) else: return HttpResponse('POST DATA INCOMPLETE', status=400)
def ajax_save_grade(request): if 'mark_id' in request.POST and 'value' in request.POST: mark_id = request.POST['mark_id'].strip() value = request.POST['value'].strip() try: mark = Mark.objects.get(id=mark_id) except Mark.DoesNotExist: return HttpResponse('NO MARK WITH ID ' + mark_id, status=404) if not request.user.is_superuser and not request.user.groups.filter(name='registrar').count() \ and request.user.username != mark.item.course.teacher.username \ and not mark.item.course.secondary_teachers.filter(username=request.user.username).count(): return HttpResponse(status=403) if not request.user.has_perm('grades.change_grade') \ and mark.item.marking_period is not None \ and not mark.item.marking_period.active: # you aren't a registrar, so you can't modify an item from an inactive marking period return HttpResponse(status=403) if len(value) and value.lower != 'none': mark.mark = value else: mark.mark = None value = 'None' try: with reversion.create_revision(): mark.full_clean() mark.save() reversion.set_user(request.user) reversion.set_comment("gradebook") except Exception as e: return HttpResponse(e, status=400) affected_agg_pks = [ x.pk for x in gradebook_recalculate_on_mark_change(mark) ] # just the whole course average for now # TODO: update filtered average #average = gradebook_get_average(mark.student, mark.item.course, None, None, None) return HttpResponse( json.dumps({ 'success': 'SUCCESS', 'value': value, 'average': 'Please clear your browser\'s cache.', 'affected_aggregates': affected_agg_pks })) else: return HttpResponse('POST DATA INCOMPLETE', status=400)
def ajax_save_grade(request): if 'mark_id' in request.POST and 'value' in request.POST: mark_id = request.POST['mark_id'].strip() value = request.POST['value'].strip() try: mark = Mark.objects.get(id=mark_id) except Mark.DoesNotExist: return HttpResponse('NO MARK WITH ID ' + mark_id, status=404) if not request.user.is_superuser and not request.user.groups.filter(name='registrar').count() \ and request.user.username != mark.item.course.teacher.username \ and not mark.item.course.secondary_teachers.filter(username=request.user.username).count(): return HttpResponse(status=403) if not request.user.has_perm('grades.change_grade') \ and mark.item.marking_period is not None \ and not mark.item.marking_period.active: # you aren't a registrar, so you can't modify an item from an inactive marking period return HttpResponse(status=403) if len(value) and value.lower != 'none': mark.set_grade(value) else: mark.set_grade(None) value = 'None' try: with reversion.create_revision(): mark.full_clean() mark.save() reversion.set_user(request.user) reversion.set_comment("gradebook") except Exception as e: return HttpResponse(e, status=400) try: affected_agg_pks = [x.pk for x in gradebook_recalculate_on_mark_change(mark)] except: # BAD BAD BAD... stale Aggregates ahead! logging.error("Mark {} saved successfully but Aggregate calculation failed".format(mark.pk), exc_info=True) affected_agg_pks = None # just the whole course average for now # TODO: update filtered average #average = gradebook_get_average(mark.student, mark.item.course, None, None, None) return HttpResponse(json.dumps({'success': 'SUCCESS', 'value': value, 'average': 'Please clear your browser\'s cache.', 'affected_aggregates': affected_agg_pks})) else: return HttpResponse('POST DATA INCOMPLETE', status=400)