def save(self, commit=True): title = self.cleaned_data.get("contest_title") description = self.cleaned_data.get("description") password = self.cleaned_data.get("password") private = 1 if password else 0 start_time = self.cleaned_data.get("start_time") end_time = self.cleaned_data.get("end_time") problem_data = self.cleaned_data.get("problem_data") contest = Contest( title=title, start_time=start_time, end_time=end_time, description=description, private=private, impose=0, type=self.judge_type, password=password, creator=self.user, ) contest.save() for i in range(0, problem_data['number']): title = problem_data['titles'][i] if not title: title = self.problem[i].title new_problem = In_Problem( problem=self.problem[i], problem_new_id=i, title=title, ) new_problem.save() contest.problem.add(new_problem) return contest
def save(self, user): cid = self.cleaned_data.get("cid") from datetime import datetime from problem.models import Problem from contest.models import Contest, In_Problem try: contest = Contest.objects.get(clone=cid) flag = True except: contest = Contest( title="None", start_time=datetime.now(), end_time=datetime.now(), description="", private=0, impose=0, type=1, password="", creator=user, ) contest.save() flag = False if not flag: for i in range(self.number): p = Problem(oj="hdu_std", problem_id=i + 1001, judge_type=1, data_number=cid) p.save() new_problem = In_Problem( problem=p, problem_new_id=i, title="None", ) new_problem.save() contest.problem.add(new_problem) c = Connect() c.clone_contest(cid, contest.id)