async def edit(domain_id: str, doc_type: int, tid: objectid.ObjectId, **kwargs): if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]: raise error.InvalidArgumentError('doc_type') if 'title' in kwargs: validator.check_title(kwargs['title']) if 'content' in kwargs: validator.check_content(kwargs['content']) if 'rule' in kwargs: if doc_type == document.TYPE_CONTEST: if kwargs['rule'] not in constant.contest.CONTEST_RULES: raise error.ValidationError('rule') elif doc_type == document.TYPE_HOMEWORK: if kwargs['rule'] not in constant.contest.HOMEWORK_RULES: raise error.ValidationError('rule') if 'begin_at' in kwargs and 'end_at' in kwargs: if kwargs['begin_at'] >= kwargs['end_at']: raise error.ValidationError('begin_at', 'end_at') if 'penalty_since' in kwargs: if 'begin_at' in kwargs and kwargs['penalty_since'] < kwargs[ 'begin_at']: raise error.ValidationError('penalty_since', 'begin_at') if 'end_at' in kwargs and kwargs['penalty_since'] > kwargs['end_at']: raise error.ValidationError('penalty_since', 'end_at') return await document.set(domain_id, doc_type, tid, **kwargs)
async def edit(domain_id: str, pid: document.convert_doc_id, pname: str = None, **kwargs): pid = await document.get_pid(domain_id, pid) if 'title' in kwargs: validator.check_title(kwargs['title']) if 'content' in kwargs: validator.check_content(kwargs['content']) if pname == "": pname = None if pname: validator.check_string_pname(pname) pdoc = await document.set(domain_id, document.TYPE_PROBLEM, pid, pname=pname, **kwargs) else: pdoc = await document.set(domain_id, document.TYPE_PROBLEM, pid, **kwargs) if not pdoc: raise error.DocumentNotFoundError(domain_id, document.TYPE_PROBLEM, pid) return pdoc
async def add(domain_id: str, title: str, content: str, owner_uid: int, pid: document.convert_doc_id = None, data: objectid.ObjectId = None, category: list = [], tag: list = [], hidden: bool = False, ac_msg=''): validator.check_title(title) validator.check_content(content) pid = await document.add(domain_id, content, owner_uid, document.TYPE_PROBLEM, pid, title=title, data=data, category=category, tag=tag, hidden=hidden, num_submit=0, num_accept=0, ac_msg=ac_msg) await domain.inc_user(domain_id, owner_uid, num_problems=1) return pid
async def add(domain_id: str, doc_type: int, title: str, content: str, owner_uid: int, rule: int, begin_at: lambda i: datetime.datetime.utcfromtimestamp(int(i)), end_at: lambda i: datetime.datetime.utcfromtimestamp(int(i)), pids=[], **kwargs): if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]: raise error.InvalidArgumentError('doc_type') validator.check_title(title) validator.check_content(content) if doc_type == document.TYPE_CONTEST: if rule not in constant.contest.CONTEST_RULES: raise error.ValidationError('rule') elif doc_type == document.TYPE_HOMEWORK: if rule not in constant.contest.HOMEWORK_RULES: raise error.ValidationError('rule') if begin_at >= end_at: raise error.ValidationError('begin_at', 'end_at') if doc_type == document.TYPE_HOMEWORK: if 'penalty_since' not in kwargs: raise error.ValidationError('penalty_since') if kwargs['penalty_since'] < begin_at: raise error.ValidationError('penalty_since', 'begin_at') if kwargs['penalty_since'] > end_at: raise error.ValidationError('penalty_since', 'end_at') # TODO(twd2): should we check problem existance here? return await document.add(domain_id, content, owner_uid, doc_type, title=title, rule=rule, begin_at=begin_at, end_at=end_at, pids=pids, attend=0, **kwargs)
async def edit(domain_id: str, did: document.convert_doc_id, **kwargs): if 'title' in kwargs: validator.check_title(kwargs['title']) if 'content' in kwargs: validator.check_content(kwargs['content']) return await document.set(domain_id, document.TYPE_DISCUSSION, did, **kwargs)
async def add(domain_id: str, title: str, content: str, owner_uid: int, rule: int, begin_at: lambda i: datetime.datetime.utcfromtimestamp(int(i)), end_at: lambda i: datetime.datetime.utcfromtimestamp(int(i)), pids=[]): validator.check_title(title) validator.check_content(content) if rule not in RULES: raise error.ValidationError('rule') if begin_at >= end_at: raise error.ValidationError('begin_at', 'end_at') # TODO(twd2): should we check problem existance here? return await document.add(domain_id, content, owner_uid, document.TYPE_CONTEST, title=title, rule=rule, begin_at=begin_at, end_at=end_at, pids=pids, attend=0)
async def set(domain_id: str, lid: document.convert_doc_id, **kwargs): # TODO(twd2): check if deleted? if 'title' in kwargs: validator.check_title(kwargs['title']) if 'content' in kwargs: validator.check_content(kwargs['content']) return await document.set(domain_id, document.TYPE_PROBLEM_LIST, lid, **kwargs)
async def add(desc: str, file_id: objectid.ObjectId, owner_uid: int, length: int): validator.check_title(desc) return await document.add(STORE_DOMAIN_ID, desc, owner_uid, document.TYPE_USERFILE, file_id=file_id, length=length)
async def edit(domain_id: str, pid: document.convert_doc_id, **kwargs): if 'title' in kwargs: validator.check_title(kwargs['title']) if 'content' in kwargs: validator.check_content(kwargs['content']) pdoc = await document.set(domain_id, document.TYPE_PROBLEM, pid, **kwargs) if not pdoc: raise error.DocumentNotFoundError(domain_id, document.TYPE_PROBLEM, pid) return pdoc
async def add(domain_id: str, title: str, content: str, owner_uid: int, pid: document.convert_doc_id=None, data: objectid.ObjectId=None, category: list=[], tag: list=[], hidden: bool=False): validator.check_title(title) validator.check_content(content) pid = await document.add(domain_id, content, owner_uid, document.TYPE_PROBLEM, pid, title=title, data=data, category=category, tag=tag, hidden=hidden, num_submit=0, num_accept=0) await domain.inc_user(domain_id, owner_uid, num_problems=1) return pid
async def add(domain_id: str, title: str, content: str, owner_uid: int, dag=[]): validator.check_title(title) validator.check_content(content) dag = list(dag) for node in dag: for nid in node['require_nids']: if nid >= node['_id']: raise error.ValidationError('dag') return await document.add(domain_id, content, owner_uid, document.TYPE_TRAINING, title=title, dag=dag, enroll=0)
async def add(domain_id: str, title: str, content: str, owner_uid: int, dag=[], desc=''): validator.check_title(title) validator.check_intro(content) validator.check_description(desc) dag = list(dag) for node in dag: for nid in node['require_nids']: if nid >= node['_id']: raise error.ValidationError('dag') return await document.add(domain_id, content, owner_uid, document.TYPE_TRAINING, title=title, dag=dag, desc=desc, enroll=0)
async def add(domain_id: str, node_or_dtuple: str, owner_uid: int, title: str, content: str, ip: str=None, **flags): validator.check_title(title) validator.check_content(content) vnode = await get_vnode(domain_id, node_or_dtuple) if not vnode: raise error.DiscussionNodeNotFoundError(domain_id, node_or_dtuple) return await document.add(domain_id, content, owner_uid, document.TYPE_DISCUSSION, title=title, num_replies=0, views=0, ip=ip, **flags, update_at=datetime.datetime.utcnow(), parent_doc_type=vnode['doc_type'], parent_doc_id=vnode['doc_id'])
async def add(domain_id: str, title: str, content: str, owner_uid: int, pid: document.convert_doc_id=None, data: objectid.ObjectId=None, category: list=[], hidden: bool=False): validator.check_title(title) validator.check_content(content) # tc-imba: use cc as the default language pid = await document.add(domain_id, content, owner_uid, document.TYPE_PROBLEM, pid, title=title, data=data, category=category, hidden=hidden, num_submit=0, num_accept=0, languages=['cc']) await domain.inc_user(domain_id, owner_uid, num_problems=1) return pid
async def add(domain_id: str, node_or_dtuple: str, owner_uid: int, title: str, content: str, **flags): validator.check_title(title) validator.check_content(content) vnode = await get_vnode(domain_id, node_or_dtuple) if not vnode: raise error.DiscussionNodeNotFoundError(domain_id, node_or_dtuple) return await document.add(domain_id, content, owner_uid, document.TYPE_DISCUSSION, title=title, num_replies=0, views=0, **flags, update_at=datetime.datetime.utcnow(), parent_doc_type=vnode['doc_type'], parent_doc_id=vnode['doc_id'])
async def edit(domain_id: str, tid: objectid.ObjectId, **kwargs): if 'title' in kwargs: validator.check_title(kwargs['title']) if 'content' in kwargs: validator.check_content(kwargs['content']) if 'rule' in kwargs: if kwargs['rule'] not in RULES: raise error.ValidationError('rule') if 'begin_at' in kwargs and 'end_at' in kwargs: if kwargs['begin_at'] >= kwargs['end_at']: raise error.ValidationError('begin_at', 'end_at') return await document.set(domain_id, document.TYPE_CONTEST, tid, **kwargs)
async def edit(domain_id: str, tid: objectid.ObjectId, **kwargs): if 'title' in kwargs: validator.check_title(kwargs['title']) if 'content' in kwargs: validator.check_content(kwargs['content']) if 'dag' in kwargs: kwargs['dag'] = list(kwargs['dag']) for node in kwargs['dag']: for nid in node['require_nids']: if nid >= node['_id']: raise error.ValidationError('dag') return await document.set(domain_id, document.TYPE_TRAINING, tid, **kwargs)
async def add(domain_id: str, title: str, content: str, owner_uid: int, pid: document.convert_doc_id = None, pname: str = None, data: objectid.ObjectId = None, category: list = [], tag: list = [], hidden: bool = False): validator.check_title(title) validator.check_content(content) if not pid: pid = await domain.inc_pid_counter(domain_id) try: pid = int(pid) except ValueError: pass if pname == "": pname = None if pname: validator.check_string_pname(pname) pid = await document.add(domain_id, content, owner_uid, document.TYPE_PROBLEM, pid, pname=pname, title=title, data=data, category=category, tag=tag, hidden=hidden, num_submit=0, num_accept=0) else: pid = await document.add(domain_id, content, owner_uid, document.TYPE_PROBLEM, pid, title=title, data=data, category=category, tag=tag, hidden=hidden, num_submit=0, num_accept=0) await domain.inc_user(domain_id, owner_uid, num_problems=1) return pid
async def add(domain_id: str, title: str, content: str, owner_uid: int, lid: document.convert_doc_id = None): validator.check_title(title) validator.check_content(content) return await document.add(domain_id, content, owner_uid, document.TYPE_PROBLEM_LIST, lid, title=title, problem=[])
async def edit(domain_id: str, tid: objectid.ObjectId, **kwargs): if 'title' in kwargs: validator.check_title(kwargs['title']) if 'content' in kwargs: validator.check_intro(kwargs['content']) if 'desc' in kwargs: validator.check_description(kwargs['desc']) if 'dag' in kwargs: kwargs['dag'] = list(kwargs['dag']) for node in kwargs['dag']: for nid in node['require_nids']: if nid >= node['_id']: raise error.ValidationError('dag') return await document.set(domain_id, document.TYPE_TRAINING, tid, **kwargs)
async def edit(domain_id: str, doc_type: int, tid: objectid.ObjectId, **kwargs): if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]: raise error.InvalidArgumentError('doc_type') if 'title' in kwargs: validator.check_title(kwargs['title']) if 'content' in kwargs: validator.check_content(kwargs['content']) if 'rule' in kwargs: if doc_type == document.TYPE_CONTEST: if kwargs['rule'] not in constant.contest.CONTEST_RULES: raise error.ValidationError('rule') elif doc_type == document.TYPE_HOMEWORK: if kwargs['rule'] not in constant.contest.HOMEWORK_RULES: raise error.ValidationError('rule') if 'begin_at' in kwargs and 'end_at' in kwargs: if kwargs['begin_at'] >= kwargs['end_at']: raise error.ValidationError('begin_at', 'end_at') if 'penalty_since' in kwargs: if 'begin_at' in kwargs and kwargs['penalty_since'] < kwargs['begin_at']: raise error.ValidationError('penalty_since', 'begin_at') if 'end_at' in kwargs and kwargs['penalty_since'] > kwargs['end_at']: raise error.ValidationError('penalty_since', 'end_at') return await document.set(domain_id, doc_type, tid, **kwargs)