def upload_main_block(request, problem): if request.method == 'POST' and 'upload_main' in request.POST: form = ProblemUploadFilesForm(request.POST, request.FILES) modified = False if form.is_valid(): if form.cleaned_data['select_checker']: with ChangeDir(problem.path): path = standard_checkers_utils.add_standard_checker_to_solution( form.cleaned_data['select_checker']) problem.checker_path = norm(path) modified = True elif 'checker' in request.FILES.keys(): checker_file = request.FILES['checker'] problem.checker_path = norm(checker_file.name) file_save(checker_file, problem.path) modified = True if 'validator' in request.FILES.keys(): validator_file = request.FILES['validator'] problem.validator_path = norm(validator_file.name) file_save(validator_file, problem.path) modified = True problem.save() if modified: export_from_database(problem) form = ProblemUploadFilesForm() return {'form': form, 'problem': problem}
def upload_main_block(request, problem): if request.method == 'POST' and 'upload_main' in request.POST: form = ProblemUploadFilesForm(request.POST, request.FILES) modified = False if form.is_valid(): if form.cleaned_data['select_checker']: with ChangeDir(problem.path): path = standard_checkers_utils.add_standard_checker_to_solution(form.cleaned_data['select_checker']) problem.checker_path = norm(path) modified = True elif 'checker' in request.FILES.keys(): checker_file = request.FILES['checker'] problem.checker_path = norm(checker_file.name) file_save(checker_file, problem.path) modified = True if 'validator' in request.FILES.keys(): validator_file = request.FILES['validator'] problem.validator_path = norm(validator_file.name) file_save(validator_file, problem.path) modified = True problem.save() if modified: export_from_database(problem) form = ProblemUploadFilesForm() return {'form': form, 'problem': problem}
def process_additional_upload(request, id): problem = Problem.objects.get(id=id) if request.method == 'POST': form = AdditonalUpload(request.POST, request.FILES) if form.is_valid(): file_save(request.FILES['uploaded'], problem.path) form = AdditonalUpload() else: form = AdditonalUpload() return {'files': sorted(list(file_utils.list_files_flat(problem.path))), 'form': form, 'id': id}
def process_additional_upload(request, id): problem = Problem.objects.get(id=id) if request.method == 'POST': form = AdditonalUpload(request.POST, request.FILES) if form.is_valid(): file_save(request.FILES['uploaded'], problem.path) form = AdditonalUpload() else: form = AdditonalUpload() return { 'files': sorted(list(file_utils.list_files_flat(problem.path))), 'form': form, 'id': id }
def upload_solution(request, id): problem = Problem.objects.get(id=id) if request.method == 'POST': form = SolutionAddForm(request.POST, request.FILES) if 'submit_file' in form.data: if form.is_valid() and request.FILES: solution = Solution(problem=problem) directory = norm(os.path.join(str(problem.path), 'solutions')) solution.path = norm(os.path.relpath( file_save(request.FILES['solution_file'], directory), start=str(problem.path))) solution.input = form.cleaned_data['input_file_name'] solution.output = form.cleaned_data['output_file_name'] solution.save() for choice in Verdict.objects.filter(name__in=form.cleaned_data['possible_verdicts']): solution.possible_verdicts.add(choice) for choice in Verdict.objects.filter(name__in=form.cleaned_data['expected_verdicts']): solution.expected_verdicts.add(choice) solution.save() form = SolutionAddForm() export_from_database(problem) else: form = SolutionAddForm() else: form = SolutionAddForm() return {'form': form}
def upload_solution(request, id): problem = Problem.objects.get(id=id) if request.method == 'POST': form = SolutionAddForm(request.POST, request.FILES) if 'submit_file' in form.data: if form.is_valid() and request.FILES: solution = Solution(problem=problem) directory = norm(os.path.join(str(problem.path), 'solutions')) solution.path = norm( os.path.relpath(file_save(request.FILES['solution_file'], directory), start=str(problem.path))) solution.input = form.cleaned_data['input_file_name'] solution.output = form.cleaned_data['output_file_name'] solution.save() for choice in Verdict.objects.filter( name__in=form.cleaned_data['possible_verdicts']): solution.possible_verdicts.add(choice) for choice in Verdict.objects.filter( name__in=form.cleaned_data['expected_verdicts']): solution.expected_verdicts.add(choice) solution.save() form = SolutionAddForm() export_from_database(problem) else: form = SolutionAddForm() else: form = SolutionAddForm() return {'form': form}