def import_to_database(model=None, path=None): assert (model is None) != (path is None) if path is not None: model = get_contest_by_path(path) contest_path = path or str(model.path) if not os.path.exists(contest_path): model.delete() return None conf = PleaseContest(contest_path).config model.name = conf.get("name", "") method = conf.get("id_method", "") if method: for id in Contest.ID_METHODS: if id[1] == method: model.id_method = id[0] break model.statement_name = conf["statement"].get("name", "") model.statement_location = conf["statement"].get("location", "") model.statement_date = conf["statement"].get("date", "") model.statement_template = conf["statement"].get("template", "contest.tex") model.save() order = 0 ContestProblem.objects.filter(contest=model).delete() for problem in conf["problem"]: ContestProblem( problem=Problem.objects.get(path=norm(os.path.join(os.path.dirname(model.path), problem["path"]))), contest=model, id_in_contest=problem["id"], order=order, ).save() order += 1 a = Contest.objects.get(id=1) return model
def import_to_database(model=None, path=None): assert ((model is None) != (path is None)) if path is not None: model = get_contest_by_path(path) contest_path = path or str(model.path) if not os.path.exists(contest_path): model.delete() return None conf = PleaseContest(contest_path).config model.name = conf.get("name", "") method = conf.get("id_method", "") if method: for id in Contest.ID_METHODS: if id[1] == method: model.id_method = id[0] break model.statement_name = conf['statement'].get("name", "") model.statement_location = conf['statement'].get("location", "") model.statement_date = conf['statement'].get("date", "") model.statement_template = conf['statement'].get("template", "contest.tex") model.save() order = 0 ContestProblem.objects.filter(contest=model).delete() for problem in conf['problem']: ContestProblem(problem=Problem.objects.get(path=norm( os.path.join(os.path.dirname(model.path), problem['path']))), contest=model, id_in_contest=problem['id'], order=order).save() order += 1 a = Contest.objects.get(id=1) return model
def export_from_database(model=None, path=None): assert (model is None) != (path is None) if path is not None: model = get_contest_by_path(path) os.remove(model.path) contest = PleaseContest(model.path, True) conf = contest.config conf["please_version"] = conf["please_version"] or str(globalconfig.please_version) conf["name"] = str(model.name) for id in Contest.ID_METHODS: if id[0] == model.id_method: conf["id_method"] = id[1] conf["statement"]["name"] = str(model.statement_name) conf["statement"]["location"] = str(model.statement_location) conf["statement"]["date"] = str(model.statement_date) conf["statement"]["template"] = str(model.statement_template) problems = ContestProblem.objects.filter(contest=model) contest.save() with ChangeDir(os.path.dirname(model.path)): for problem in problems: contest.problem_add(problem.problem.path, problem.id_in_contest) contest.save() """
def export_from_database(model=None, path=None): assert (model is None) != (path is None) if path is not None: model = get_contest_by_path(path) os.remove(model.path) contest = PleaseContest(model.path, True) conf = contest.config conf['please_version'] = conf['please_version'] or str( globalconfig.please_version) conf['name'] = str(model.name) for id in Contest.ID_METHODS: if id[0] == model.id_method: conf['id_method'] = id[1] conf['statement']['name'] = str(model.statement_name) conf['statement']['location'] = str(model.statement_location) conf['statement']['date'] = str(model.statement_date) conf['statement']['template'] = str(model.statement_template) problems = ContestProblem.objects.filter(contest=model) contest.save() with ChangeDir(os.path.dirname(model.path)): for problem in problems: contest.problem_add(problem.problem.path, problem.id_in_contest) contest.save() '''