def add_tree_block(request): if request.method == 'POST': form = AddContestForm(request.POST) if form.is_valid(): path = form.cleaned_data['path'] return { 'form': form, 'paths': import_tree(path), } else: form = AddContestForm() return {'form': form}
def add_contest_block(request): is_success, is_error = False, False if request.method == 'POST': form = AddContestForm(request.POST) if form.is_valid(): filename = form.cleaned_data['path'] if os.path.exists(filename): contest = Contest(path=filename) contest.save() import_to_database(contest) is_success = True else: is_error = True else: form = AddContestForm() return { 'form': form, 'is_success': is_success, 'is_error': is_error, }