Esempio n. 1
0
def grade(request):
    # accept only POST method, AJAX
    if request.method != 'POST': raise Http404()
    form = ScoreForm(request.POST, initial = {'comment': ''})
    if form.is_valid():
        sid = form.cleaned_data['sid']
        try:
            submission = Submission.objects.get(id=sid)
            problem_name = form.cleaned_data['problem_name']
            score = submission.get_score(problem_name)
            if score is not None:
                score.delete()

            score = Score(submission=submission, 
                    problem_name=problem_name,
                    score=form.cleaned_data['score'],
                    comment=form.cleaned_data['comment'],
                    )
            score.save()
            return json.dumps({ 'code': 0, 
                'message': 'success. Give {} points to problem "{}".'.format(
                    score.score, score.problem_name)
                })
        except Exception as e:
            return json.dumps({'code': 1, 'message': unicode(e)})
    else:
        return json.dumps({'code': 2,'message': unicode(form.errors)})
Esempio n. 2
0
def run():
	# auto_assign()
	for subm in Submission.objects.filter(grader=autograder, finished=False):
		for problem in subm.assignment.problems:
			evalInfo = evaluate(problem, subm)
			previous = subm.score_set.filter(problem_name=problem.name)
			if previous is not None: 
				previous.delete()
			score = Score(submission = subm, 
				problem_name = problem.name,
				comment = evalInfo.comment,
				score = evalInfo.score,
			)
			print 'score: ', subm.id, subm.user, subm.assignment.title, problem.name, evalInfo.score 
			score.save()
		subm.finished = True
		subm.save()