From a6ee2b217238851e836c7c3efaec870cce8d1808 Mon Sep 17 00:00:00 2001 From: "sxw@401" Date: Sun, 6 Sep 2015 08:39:00 +0800 Subject: [PATCH] =?UTF-8?q?Accessories:=E6=B7=BB=E5=8A=A0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E4=BB=8E=E5=B7=B2=E6=9C=89=E7=9A=84=E6=AF=94=E8=B5=9B?= =?UTF-8?q?=E9=A2=98=E7=9B=AE=E5=88=9B=E5=BB=BA=E6=AF=94=E8=B5=9B!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Accessories/utils.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Accessories/utils.py b/Accessories/utils.py index fea32c68..e0cd879c 100644 --- a/Accessories/utils.py +++ b/Accessories/utils.py @@ -1,9 +1,27 @@ import django -from contest.models import Contest +from contest.models import * + django.setup() -def add_exist_problem_to_contest(problems, contest_id): - for problem in problems: - print problem.title +def add_exist_problem_to_contest(problems, contest_id): + try: + contest = Contest.objects.get(pk=contest_id) + except Contest.DoesNotExist: + print "Contest Doesn't Exist!" + return + i = 1 + for problem in problems: + print "Add the problem:" + print problem.title + ContestProblem.create(contest, sort_index=str(i), + title=problem.title, description=problem.description, + input_description=problem.input_description, + output_description=problem.output_description, + samples=problem.samples, + test_case_id=problem.test_case_id, + hint=problem.hint, + created_by=problem.created_by, + time_limit=problem.time_limit, + memory_limit=problem.memory_limit) return