async def post(self, *, title: str, content: str, begin_at_date: str, begin_at_time: str, penalty_since_date: str, penalty_since_time: str, extension_days: float, penalty_rules: str, pids: str): penalty_rules = _parse_penalty_rules_yaml(penalty_rules) try: begin_at = datetime.datetime.strptime(begin_at_date + ' ' + begin_at_time, '%Y-%m-%d %H:%M') begin_at = self.timezone.localize(begin_at).astimezone(pytz.utc).replace(tzinfo=None) except ValueError: raise error.ValidationError('begin_at_date', 'begin_at_time') try: penalty_since = datetime.datetime.strptime(penalty_since_date + ' ' + penalty_since_time, '%Y-%m-%d %H:%M') penalty_since = self.timezone.localize(penalty_since).astimezone(pytz.utc).replace(tzinfo=None) except ValueError: raise error.ValidationError('end_at_date', 'end_at_time') end_at = penalty_since + datetime.timedelta(days=extension_days) if begin_at >= penalty_since: raise error.ValidationError('end_at_date', 'end_at_time') if penalty_since > end_at: raise error.ValidationError('extension_days') pids = contest._parse_pids(pids) await self.verify_problems(pids) tid = await contest.add(self.domain_id, document.TYPE_HOMEWORK, title, content, self.user['_id'], constant.contest.RULE_ASSIGNMENT, begin_at, end_at, pids, penalty_since=penalty_since, penalty_rules=penalty_rules) await self.hide_problems(pids) self.json_or_redirect(self.reverse_url('homework_detail', tid=tid))
async def post(self, *, tid: objectid.ObjectId, title: str, content: str, rule: int, begin_at_date: str=None, begin_at_time: str=None, duration: float, pids: str): tdoc = await contest.get(self.domain_id, document.TYPE_CONTEST, tid) if not self.own(tdoc, builtin.PERM_EDIT_CONTEST_SELF): self.check_perm(builtin.PERM_EDIT_CONTEST) try: begin_at = datetime.datetime.strptime(begin_at_date + ' ' + begin_at_time, '%Y-%m-%d %H:%M') begin_at = self.timezone.localize(begin_at).astimezone(pytz.utc).replace(tzinfo=None) except ValueError: raise error.ValidationError('begin_at_date', 'begin_at_time') end_at = begin_at + datetime.timedelta(hours=duration) if begin_at >= end_at: raise error.ValidationError('duration') pids = contest._parse_pids(pids) await self.verify_problems(pids) await contest.edit(self.domain_id, document.TYPE_CONTEST, tdoc['doc_id'], title=title, content=content, rule=rule, begin_at=begin_at, end_at=end_at, pids=pids) await self.hide_problems(pids) if tdoc['begin_at'] != begin_at \ or tdoc['end_at'] != end_at \ or set(tdoc['pids']) != set(pids) \ or tdoc['rule'] != rule: await contest.recalc_status(self.domain_id, document.TYPE_CONTEST, tdoc['doc_id']) self.json_or_redirect(self.reverse_url('contest_detail', tid=tdoc['doc_id']))
async def post(self, *, tid: objectid.ObjectId, title: str, content: str, begin_at_date: str, begin_at_time: str, penalty_since_date: str, penalty_since_time: str, extension_days: float, penalty_rules: str, pids: str): tdoc = await contest.get(self.domain_id, document.TYPE_HOMEWORK, tid) if not self.own(tdoc, builtin.PERM_EDIT_HOMEWORK_SELF): self.check_perm(builtin.PERM_EDIT_HOMEWORK) penalty_rules = _parse_penalty_rules_yaml(penalty_rules) try: begin_at = datetime.datetime.strptime( begin_at_date + ' ' + begin_at_time, '%Y-%m-%d %H:%M') begin_at = self.timezone.localize(begin_at).astimezone( pytz.utc).replace(tzinfo=None) except ValueError: raise error.ValidationError('begin_at_date', 'begin_at_time') try: penalty_since = datetime.datetime.strptime( penalty_since_date + ' ' + penalty_since_time, '%Y-%m-%d %H:%M') penalty_since = self.timezone.localize(penalty_since).astimezone( pytz.utc).replace(tzinfo=None) except ValueError: raise error.ValidationError('end_at_date', 'end_at_time') end_at = penalty_since + datetime.timedelta(days=extension_days) if begin_at >= penalty_since: raise error.ValidationError('end_at_date', 'end_at_time') if penalty_since > end_at: raise error.ValidationError('extension_days') pids = contest._parse_pids(pids) await self.verify_problems(pids) await contest.edit(self.domain_id, document.TYPE_HOMEWORK, tdoc['doc_id'], title=title, content=content, begin_at=begin_at, end_at=end_at, pids=pids, penalty_since=penalty_since, penalty_rules=penalty_rules) await self.hide_problems(pids) if tdoc['begin_at'] != begin_at \ or tdoc['end_at'] != end_at \ or tdoc['penalty_since'] != penalty_since \ or set(tdoc['pids']) != set(pids): await contest.recalc_status(self.domain_id, document.TYPE_HOMEWORK, tdoc['doc_id']) self.json_or_redirect(self.reverse_url('homework_detail', tid=tid))
async def post(self, *, title: str, content: str, rule: int, begin_at_date: str, begin_at_time: str, duration: float, pids: str): try: begin_at = datetime.datetime.strptime(begin_at_date + ' ' + begin_at_time, '%Y-%m-%d %H:%M') begin_at = self.timezone.localize(begin_at).astimezone(pytz.utc).replace(tzinfo=None) except ValueError: raise error.ValidationError('begin_at_date', 'begin_at_time') end_at = begin_at + datetime.timedelta(hours=duration) if begin_at >= end_at: raise error.ValidationError('duration') pids = contest._parse_pids(pids) await self.verify_problems(pids) tid = await contest.add(self.domain_id, document.TYPE_CONTEST, title, content, self.user['_id'], rule, begin_at, end_at, pids) await self.hide_problems(pids) self.json_or_redirect(self.reverse_url('contest_detail', tid=tid))
async def post(self, *, tid: objectid.ObjectId, title: str, content: str, begin_at_date: str, begin_at_time: str, penalty_since_date: str, penalty_since_time: str, extension_days: float, penalty_rules: str, pids: str): tdoc = await contest.get(self.domain_id, document.TYPE_HOMEWORK, tid) if not self.own(tdoc, builtin.PERM_EDIT_HOMEWORK_SELF): self.check_perm(builtin.PERM_EDIT_HOMEWORK) penalty_rules = _parse_penalty_rules_yaml(penalty_rules) try: begin_at = datetime.datetime.strptime(begin_at_date + ' ' + begin_at_time, '%Y-%m-%d %H:%M') begin_at = self.timezone.localize(begin_at).astimezone(pytz.utc).replace(tzinfo=None) except ValueError: raise error.ValidationError('begin_at_date', 'begin_at_time') try: penalty_since = datetime.datetime.strptime(penalty_since_date + ' ' + penalty_since_time, '%Y-%m-%d %H:%M') penalty_since = self.timezone.localize(penalty_since).astimezone(pytz.utc).replace(tzinfo=None) except ValueError: raise error.ValidationError('end_at_date', 'end_at_time') end_at = penalty_since + datetime.timedelta(days=extension_days) if begin_at >= penalty_since: raise error.ValidationError('end_at_date', 'end_at_time') if penalty_since > end_at: raise error.ValidationError('extension_days') pids = contest._parse_pids(pids) await self.verify_problems(pids) await contest.edit(self.domain_id, document.TYPE_HOMEWORK, tdoc['doc_id'], title=title, content=content, begin_at=begin_at, end_at=end_at, pids=pids, penalty_since=penalty_since, penalty_rules=penalty_rules) await self.hide_problems(pids) if tdoc['begin_at'] != begin_at \ or tdoc['end_at'] != end_at \ or tdoc['penalty_since'] != penalty_since \ or set(tdoc['pids']) != set(pids): await contest.recalc_status(self.domain_id, document.TYPE_HOMEWORK, tdoc['doc_id']) self.json_or_redirect(self.reverse_url('homework_detail', tid=tid))