From 3f570f0b336958dfcf9c95d2d39e3a4339f78790 Mon Sep 17 00:00:00 2001 From: esp Date: Sun, 6 Sep 2015 14:55:56 +0800 Subject: [PATCH] =?UTF-8?q?update=20utils.py=20=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E6=8A=8A=E6=AF=94=E8=B5=9B=E9=A2=98=E7=9B=AE=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=B0=E5=89=8D=E5=8F=B0=E9=A2=98=E7=9B=AE=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E8=84=9A=E6=9C=AC=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Accessories/utils.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Accessories/utils.py b/Accessories/utils.py index 264bd556..36551bbd 100644 --- a/Accessories/utils.py +++ b/Accessories/utils.py @@ -1,6 +1,6 @@ import django from contest.models import * - +from problem.models import * django.setup() @@ -27,3 +27,39 @@ def add_exist_problem_to_contest(problems, contest_id): memory_limit=problem.memory_limit) i += 1 return + +def add_contest_problem_to_problem(contest_id): + try: + contest = Contest.objects.get(pk=contest_id) + except Contest.DoesNotExist: + print "Contest Doesn't Exist!" + return + #Get all problems in this contest + problems = ContestProblem.objects.filter(contest=contest) + + #get a tag + try: + tag = ProblemTag.objects.get(name=contest.title) + except ProblemTag.DoesNotExist: + tag = ProblemTag.objects.create(name=tag) + + #for each problem + for problem in problems: + print "Add problem to problem list:" + print problem.title + p = Problem(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, + visible = False, + difficulty = 0, + source = contest.title) + p.tags.add(tag) + p.save() + return \ No newline at end of file