Esempio n. 1
0
def model_solution(request, task_id):
    """ View in the admin """
    task = get_object_or_404(Task, pk=task_id)

    if request.method == "POST":
        solution = Solution(task=task, author=request.user)
        formset = ModelSolutionFormSet(request.POST,
                                       request.FILES,
                                       instance=solution)
        if formset.is_valid():
            try:
                solution.save()
                # no deleting the old solution:
                # delete will cascade on db level deleting checker results and checker
                # as this isn't easily prevented just keep the old solution around until the task is deleted
                formset.save()
                solution.check_solution(request.session)
                task.model_solution = solution
                task.save()
            except:
                solution.delete()  # delete files
                raise  # don't commit db changes
    else:
        formset = ModelSolutionFormSet()
    context = {
        "formset": formset,
        "task": task,
        'title': "Model Solution",
        'is_popup': True,
    }
    return render(request, "admin/tasks/task/model_solution.html", context)
Esempio n. 2
0
def model_solution(request, task_id):
	""" View in the admin """
	task = get_object_or_404(Task,pk=task_id)
	
	if request.method == "POST":	
		solution = Solution(task = task, author=request.user)
		formset = ModelSolutionFormSet(request.POST, request.FILES, instance=solution)
		if formset.is_valid():
			try:
				solution.save(); 
				# no deleting the old solution:
				# delete will cascade on db level deleting checker results and checker 
				# as this isn't easily prevented just keep the old solution around until the task is deleted
				formset.save()		
				solution.check_solution(request.session)
				task.model_solution = solution;
				task.save()
			except:
				solution.delete()	# delete files 
				raise				# dont commit db changes
	else:
		formset = ModelSolutionFormSet()
	context = {"formset": formset, "task": task, 'title': "Model Solution", 'is_popup': True, }
	return render(request, "admin/tasks/task/model_solution.html", context)