Ejemplo n.º 1
0
def test_upload_student(request, task_id):

    task = get_object_or_404(Task, pk=task_id)
    if task.publication_date >= datetime.now():
        raise Http404

    if request.method == "POST":
        solution = Solution(task=task, author=request.user, testupload=True)
        formset = SolutionFormSet(request.POST,
                                  request.FILES,
                                  instance=solution)
        if formset.is_valid():
            solution.save()
            formset.save()
            solution.check_solution(run_secret=False)

            return HttpResponseRedirect(
                reverse('solution_detail', args=[solution.id]))
    else:
        formset = SolutionFormSet()

    return render_to_response("solutions/solution_test_upload.html", {
        "formset": formset,
        "task": task
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def test_upload(request, task_id):
    if not request.user.is_trainer and not request.user.is_tutor and not request.user.is_superuser:
        return access_denied(request)

    task = get_object_or_404(Task, pk=task_id)

    if request.method == "POST":
        solution = Solution(task=task, author=request.user, testupload=True)
        formset = SolutionFormSet(request.POST,
                                  request.FILES,
                                  instance=solution)
        if formset.is_valid():
            solution.save()
            formset.save()
            solution.check_solution(run_secret=True)

            return HttpResponseRedirect(
                reverse('solution_detail_full', args=[solution.id]))
    else:
        formset = SolutionFormSet()

    return render(request, "solutions/solution_test_upload.html", {
        "formset": formset,
        "task": task
    })
Ejemplo n.º 3
0
def solution_list(request, task_id, user_id=None):
    if (user_id and not request.user.is_trainer and not request.user.is_superuser):
        return access_denied(request)

    task = get_object_or_404(Task, pk=task_id)
    author = get_object_or_404(User, pk=user_id) if user_id else request.user
    solutions = task.solution_set.filter(author = author).order_by('-id')
    final_solution = task.final_solution(author)

    if task.publication_date >= datetime.now() and not request.user.is_trainer:
        raise Http404

    if request.method == "POST":
        if task.expired() and not request.user.is_trainer:
            return access_denied(request)

        solution = Solution(task = task, author=author)
        formset = SolutionFormSet(request.POST, request.FILES, instance=solution)
        if formset.is_valid():
            solution.save()
            formset.save()
            run_all_checker = bool(User.objects.filter(id=user_id, tutorial__tutors__pk=request.user.id) or request.user.is_trainer)
            solution.check_solution(run_all_checker)

            if solution.accepted:
                # Send submission confirmation email
                t = loader.get_template('solutions/submission_confirmation_email.html')
                c = {
                    'protocol': request.is_secure() and "https" or "http",
                    'domain': RequestSite(request).domain,
                    'site_name': settings.SITE_NAME,
                    'solution': solution,
                }
                with tempfile.NamedTemporaryFile(mode='w+') as tmp:
                    tmp.write(t.render(c))
                    tmp.seek(0)
                    [signed_mail, __, __, __, __]  = execute_arglist(["openssl", "smime", "-sign", "-signer", settings.CERTIFICATE, "-inkey", settings.PRIVATE_KEY, "-in", tmp.name], ".", unsafe=True)
                connection = get_connection()
                message = ConfirmationMessage(_("%s submission confirmation") % settings.SITE_NAME, signed_mail, None, [solution.author.email], connection=connection)
                if solution.author.email:
                    message.send()

            if solution.accepted or get_settings().accept_all_solutions:
                solution.final = True
                solution.save()

            return HttpResponseRedirect(reverse('solution_detail', args=[solution.id]))
    else:
        formset = SolutionFormSet()

    attestations = Attestation.objects.filter(solution__task=task, author__tutored_tutorials=request.user.tutorial)
    attestationsPublished = attestations[0].published if attestations else False

    return render(request, "solutions/solution_list.html",
                {"formset": formset, "task":task, "solutions": solutions, "final_solution":final_solution, "attestationsPublished":attestationsPublished, "author":author, "invisible_attestor":get_settings().invisible_attestor})
Ejemplo n.º 4
0
def solution_list(request, task_id, user_id=None):
        if (user_id and not request.user.is_trainer and not request.user.is_superuser):
		return access_denied(request)

	task = get_object_or_404(Task,pk=task_id)
	author = get_object_or_404(User,pk=user_id) if user_id else request.user
	solutions = task.solution_set.filter(author = author).order_by('-id')
	final_solution = task.final_solution(author)

        if task.publication_date >= datetime.now() and not request.user.is_trainer:
		raise Http404
	
	if request.method == "POST":
                if task.expired() and not request.user.is_trainer:
                        return access_denied(request)

		solution = Solution(task = task, author=author)
		formset = SolutionFormSet(request.POST, request.FILES, instance=solution)
		if formset.is_valid():
			solution.save()
			formset.save()
                        run_all_checker = bool(User.objects.filter(id=user_id, tutorial__tutors__pk=request.user.id) or request.user.is_trainer)
			solution.check(run_all_checker)
			
			if solution.accepted:  
				# Send submission confirmation email
				t = loader.get_template('solutions/submission_confirmation_email.html')
				c = {
					'protocol': request.is_secure() and "https" or "http",
					'domain': RequestSite(request).domain, 
					'site_name': settings.SITE_NAME,
					'solution': solution,
				}
				if solution.author.email:
					send_mail(_("%s submission confirmation") % settings.SITE_NAME, t.render(Context(c)), None, [solution.author.email])
		
			if solution.accepted or get_settings().accept_all_solutions:
				solution.final = True
				solution.save()
			
			return HttpResponseRedirect(reverse('solution_detail', args=[solution.id]))
	else:
		formset = SolutionFormSet()
	
	attestations = Attestation.objects.filter(solution__task=task, author__tutored_tutorials=request.user.tutorial)
	attestationsPublished = attestations[0].published if attestations else False

	return render_to_response("solutions/solution_list.html",
                {"formset": formset, "task":task, "solutions": solutions, "final_solution":final_solution, "attestationsPublished":attestationsPublished, "author":author, "invisible_attestor":get_settings().invisible_attestor},
		context_instance=RequestContext(request))
Ejemplo n.º 5
0
def solution_list(request, task_id, user_id=None):
        if (user_id and not request.user.is_trainer and not request.user.is_superuser):
		return access_denied(request)

	task = get_object_or_404(Task,pk=task_id)
	author = get_object_or_404(User,pk=user_id) if user_id else request.user
	solutions = task.solution_set.filter(author = author).order_by('-id')
	final_solution = task.final_solution(author)

        if task.publication_date >= datetime.now() and not request.user.is_trainer:
		raise Http404
	
	if request.method == "POST":
                if task.expired() and not request.user.is_trainer:
                        return access_denied(request)

		solution = Solution(task = task, author=author)
		formset = SolutionFormSet(request.POST, request.FILES, instance=solution)
		if formset.is_valid():
			solution.save()
			formset.save()
                        run_all_checker = bool(User.objects.filter(id=user_id, tutorial__tutors__pk=request.user.id) or request.user.is_trainer)
			solution.check_solution(run_all_checker)
			
			if solution.accepted:  
				# Send submission confirmation email
				t = loader.get_template('solutions/submission_confirmation_email.html')
				c = {
					'protocol': request.is_secure() and "https" or "http",
					'domain': RequestSite(request).domain, 
					'site_name': settings.SITE_NAME,
					'solution': solution,
				}
				if solution.author.email:
					send_mail(_("%s submission confirmation") % settings.SITE_NAME, t.render(c), None, [solution.author.email])
		
			if solution.accepted or get_settings().accept_all_solutions:
				solution.final = True
				solution.save()
			
			return HttpResponseRedirect(reverse('solution_detail', args=[solution.id]))
	else:
		formset = SolutionFormSet()
	
	attestations = Attestation.objects.filter(solution__task=task, author__tutored_tutorials=request.user.tutorial)
	attestationsPublished = attestations[0].published if attestations else False

	return render(request, "solutions/solution_list.html",
                {"formset": formset, "task":task, "solutions": solutions, "final_solution":final_solution, "attestationsPublished":attestationsPublished, "author":author, "invisible_attestor":get_settings().invisible_attestor})
Ejemplo n.º 6
0
def test_upload_student(request, task_id):
    task = get_object_or_404(Task, pk=task_id)
    if task.publication_date >= datetime.now():
        raise Http404

    if request.method == "POST":
        solution = Solution(task = task, author=request.user, testupload = True)
        formset = SolutionFormSet(request.POST, request.FILES, instance=solution)
        if formset.is_valid():
            solution.save()
            formset.save()
            solution.check_solution(run_secret = False)

            return HttpResponseRedirect(reverse('solution_detail', args=[solution.id]))
    else:
        formset = SolutionFormSet()

    return render("solutions/solution_test_upload.html", {"formset": formset, "task":task})
Ejemplo n.º 7
0
def test_upload(request, task_id):
        if not request.user.is_trainer and not request.user.is_tutor and not request.user.is_superuser:
		return access_denied(request)

	task = get_object_or_404(Task,pk=task_id)

	if request.method == "POST":
		solution = Solution(task = task, author=request.user, testupload = True)
		formset = SolutionFormSet(request.POST, request.FILES, instance=solution)
		if formset.is_valid():
			solution.save()
			formset.save()
			solution.check_solution(run_secret = True)

			return HttpResponseRedirect(reverse('solution_detail_full', args=[solution.id]))
	else:
		formset = SolutionFormSet()
	
	return render(request, "solutions/solution_test_upload.html", {"formset": formset, "task":task})