def edit(request, contest_id): if request.method == "POST": form = forms.ContestForm(request.POST) if form.is_valid(): if contest_id == "0": # new contest creation contest = Contest( admin=request.user, title=form.cleaned_data["title"], description=form.cleaned_data["description"] ) contest.save() contest_id = contest.id else: contest = get_object_or_404(Contest, pk=contest_id, admin=request.user) contest.title = form.cleaned_data["title"] contest.description = form.cleaned_data["description"] if form.cleaned_data["close"]: if contest.is_submission_open(): contest.date_submission_closed = timezone.now() elif contest.is_voting_open(): contest.date_voting_closed = timezone.now() else: # TODO: should probably log an error or something pass contest.save() return redirect("contest", contest.id) else: # form not valid if contest_id != "0": # '0' is for new contest creation contest = get_object_or_404(Contest, pk=contest_id, admin=request.user) else: # creating new contest contest = Contest(id=0) else: # GET request if contest_id != "0": # '0' is for new contest creation contest = get_object_or_404(Contest, pk=contest_id, admin=request.user) # at this point we have the correct contest and the user is its admin form = forms.ContestForm(initial={"title": contest.title, "description": contest.description}) else: # creating new contest form = forms.ContestForm() contest = Contest(id=0) return render(request, "contest/edit.html", {"form": form, "contest": contest})
>>>>>>> Zwlin user = User() user.username = '******' user.set_password("123456") user.email="*****@*****.**" user.is_staff = True user.save() # 插入一个比赛 C = Contest() C.description = '写脚本真累' C.participant = 200 C.source = 'zwlin' C.title = 'Testing_Contest' C.create_user = User.objects.get(username='******') C.save() with open("./item.json", 'r') as f: problems = json.load(f) id = 1000 for item in problems: p = Problem() p.problem_id = str(id) p.title = item.get('Title', '') p.description = item.get('ProblemDescription', '') p.input_description = item.get('Input', '') p.output_description = item.get('Output', '') p.sample_input = item.get('SampleInput', '') p.sample_output = item.get('SampleOutput', '')