Example #1
0
def new_attestation_for_solution(request, solution_id, force_create=False):
    if not (request.user.is_tutor or request.user.is_trainer
            or request.user.is_superuser):
        return access_denied(request)

    solution = get_object_or_404(Solution, pk=solution_id)

    attestations = Attestation.objects.filter(solution=solution)
    if ((not force_create) and attestations):
        return render_to_response(
            "attestation/attestation_already_exists_for_solution.html", {
                'task': solution.task,
                'attestations': attestations,
                'solution': solution,
                'show_author': not get_settings().anonymous_attestation
            },
            context_instance=RequestContext(request))

    attest = Attestation(solution=solution, author=request.user)
    attest.save()
    for solutionFile in solution.solutionfile_set.filter(
            mime_type__startswith='text'):
        annotatedFile = AnnotatedSolutionFile(attestation=attest,
                                              solution_file=solutionFile,
                                              content=solutionFile.content())
        annotatedFile.save()
    for rating in solution.task.rating_set.all():
        ratingResult = RatingResult(attestation=attest, rating=rating)
        ratingResult.save()
    return HttpResponseRedirect(reverse('edit_attestation', args=[attest.id]))
Example #2
0
def update_attestations(request):
	""" View in the admin """
	if request.method == 'POST': 
		form = ImportForm(request.POST, request.FILES)
		if form.is_valid(): 
			try:
				Attestation.update_Attestations(request, form.files['file'])
				return render(request, 'admin/attestation/update.html', {'form': form, 'title':"Update Attestations"  })
			except Exception, e:
				from django.forms.utils import ErrorList
				msg = "An Error occured. The import file was propably malformed.: %s" % str(e)
				form._errors["file"] = ErrorList([msg]) 			
Example #3
0
def update_attestations(request):
    """ View in the admin """
    if request.method == 'POST':
        form = ImportForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                Attestation.update_Attestations(request, form.files['file'])
                return render(request, 'admin/attestation/update.html', {'form': form, 'title':"Update Attestations"  })
            except Exception as e:
                from django.forms.utils import ErrorList
                msg = "An Error occured. The import file was propably malformed.: %s" % str(e)
                form._errors["file"] = ErrorList([msg])
    else:
        form = ImportForm()
    return render(request, 'admin/attestation/update.html', {'form': form, 'title':"Update Attestations"  })
Example #4
0
def new_attestation_for_solution(request, solution_id):
	if not (in_group(request.user,'Tutor,Trainer') or request.user.is_superuser):
		return access_denied(request)
	
	solution = get_object_or_404(Solution, pk=solution_id)
			
	attest = Attestation(solution = solution, author = request.user)
	attest.save()
	for solutionFile in  solution.solutionfile_set.filter(mime_type__startswith='text'):
		annotatedFile = AnnotatedSolutionFile(attestation = attest, solution_file=solutionFile, content=solutionFile.content())
		annotatedFile.save()
	for rating in solution.task.rating_set.all():
		ratingResult = RatingResult(attestation = attest, rating=rating)
		ratingResult.save()
	return HttpResponseRedirect(reverse('edit_attestation', args=[attest.id]))
Example #5
0
def new_attestation_for_solution(request, solution_id, force_create = False):
    if not (request.user.is_tutor or request.user.is_trainer or request.user.is_superuser):
        return access_denied(request)

    solution = get_object_or_404(Solution, pk=solution_id)

    attestations = Attestation.objects.filter(solution = solution)
    if ((not force_create) and attestations):
        return render(request, "attestation/attestation_already_exists_for_solution.html", { 'task' : solution.task, 'attestations' : attestations, 'solution' : solution, 'show_author': not get_settings().anonymous_attestation })

    attest = Attestation(solution = solution, author = request.user)
    attest.save()
    for solutionFile in  solution.solutionfile_set.filter(mime_type__startswith='text'):
        annotatedFile = AnnotatedSolutionFile(attestation = attest, solution_file=solutionFile, content=solutionFile.content())
        annotatedFile.save()
    for rating in solution.task.rating_set.all():
        ratingResult = RatingResult(attestation = attest, rating=rating)
        ratingResult.save()
    return HttpResponseRedirect(reverse('edit_attestation', args=[attest.id]))
Example #6
0
def new_attestation_for_solution(request, solution_id):
    if not (in_group(request.user, 'Tutor,Trainer')
            or request.user.is_superuser):
        return access_denied(request)

    solution = get_object_or_404(Solution, pk=solution_id)

    attest = Attestation(solution=solution, author=request.user)
    attest.save()
    for solutionFile in solution.solutionfile_set.filter(
            mime_type__startswith='text'):
        annotatedFile = AnnotatedSolutionFile(attestation=attest,
                                              solution_file=solutionFile,
                                              content=solutionFile.content())
        annotatedFile.save()
    for rating in solution.task.rating_set.all():
        ratingResult = RatingResult(attestation=attest, rating=rating)
        ratingResult.save()
    return HttpResponseRedirect(reverse('edit_attestation', args=[attest.id]))
Example #7
0
    def run(self, env):
        """ Runs tests in a special environment. Here's the actual work. 
        Returning CheckerResult. """

        checkers_passed = 0
        checkers_failed = 0
        for r in env.solution().checkerresult_set.all():
            if r.required():
                if r.passed:
                    checkers_passed += 1
                else:
                    checkers_failed += 1

#result = CheckerResult(checker=self)
        result = CheckerResult(checker=self, solution=env.solution())
        result.set_passed(checkers_failed == 0)

        if User.objects.filter(id=self.author_id).count() == 0:
            self.author_id = None  # warum nicht self.author ???
            return result

# delete all old own Attestations for this solution.
        for a in Attestation.objects.filter(solution=env.solution(),
                                            author=self.author):
            a.delete()

        # reset final/published attestations
        for a in Attestation.objects.filter(
                solution__task=env.solution().task,
                solution__author=env.solution().author):
            a.final = False
            a.published = False
            a.save()

        # reset final solution
        s = env.solution().task.final_solution(env.solution().author)
        if s:
            s.final = False
            s.save()

        # create new attestation
        if self.task.final_grade_rating_scale:
            grades = list(
                self.task.final_grade_rating_scale.ratingscaleitem_set.all())
            if checkers_failed == 0:
                if checkers_passed > 0:
                    result.set_log('All %d required checkers passed.' %
                                   checkers_passed)
                else:
                    result.set_log('WARNING: No checkers.')

                new_final_solution = env.solution()
                if new_final_solution:
                    new_final_solution.final = True
                    new_final_solution.save()

                a = Attestation(solution=env.solution(),
                                author=self.author,
                                public_comment=self.public_comment,
                                private_comment=self.private_comment,
                                final=self.final,
                                published=self.published,
                                published_on=datetime.now(),
                                final_grade=grades[-1])
                a.save()
            else:
                result.set_log('%d required checkers failed.' %
                               checkers_failed)
                #                result.set_solution_id(env.solution())
                a = Attestation(solution=env.solution(),
                                author=self.author,
                                public_comment=self.public_comment,
                                private_comment=self.private_comment,
                                final=self.final,
                                published=self.published,
                                published_on=datetime.now(),
                                final_grade=grades[0])
                a.save()
        return result