import django
from contest.models import *

django.setup()


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
        print "The sort Index is" + str(i) + " You Can modify it latter as you like~"
        ContestProblem.objects.create(contest=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)
        i += 1
    return

@@ -36,16 +36,44 @@
 mport *%0A
+from problem.models import *
 %0Adjango.
@@ -1157,16 +1157,1430 @@
 += 1%0A    return%0A
+%0Adef add_contest_problem_to_problem(contest_id):%0A    try:%0A        contest = Contest.objects.get(pk=contest_id)%0A    except Contest.DoesNotExist:%0A        print %22Contest Doesn't Exist!%22%0A        return%0A    #Get all problems in this contest%0A    problems = ContestProblem.objects.filter(contest=contest)%0A    %0A    #get a tag%0A    try:%0A        tag = ProblemTag.objects.get(name=contest.title)%0A    except ProblemTag.DoesNotExist:%0A        tag = ProblemTag.objects.create(name=tag)%0A        %0A    #for each problem%0A    for problem in problems:%0A        print %22Add problem to problem list:%22%0A        print problem.title%0A        p = Problem(title=problem.title, %0A                              description=problem.description,%0A                              input_description=problem.input_description,%0A                              output_description=problem.output_description,%0A                              samples=problem.samples,%0A                              test_case_id=problem.test_case_id,%0A                              hint=problem.hint,%0A                              created_by=problem.created_by,%0A                              time_limit=problem.time_limit,%0A                              memory_limit=problem.memory_limit,%0A                              visible = False,%0A                              difficulty = 0,%0A                              source = contest.title)%0A        p.tags.add(tag)%0A        p.save()%0A    return

update utils.py 添加了把比赛题目添加到前台题目列表的脚本工具