예제 #1
0
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)
예제 #2
0
파일: contest.py 프로젝트: vijos/vj4
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)
예제 #3
0
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
예제 #4
0
파일: contest.py 프로젝트: zhiwehu/vj4
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)
예제 #5
0
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)
예제 #6
0
파일: problem.py 프로젝트: pyjnqd/ds-judge
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
예제 #7
0
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)
예제 #8
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)
예제 #9
0
파일: discussion.py 프로젝트: zryoung/vj4
async def add_reply(domain_id: str, did: document.convert_doc_id, owner_uid: int, content: str):
  validator.check_content(content)
  drdoc, _ = await asyncio.gather(
    document.add(domain_id, content, owner_uid, document.TYPE_DISCUSSION_REPLY,
                 parent_doc_type=document.TYPE_DISCUSSION, parent_doc_id=did),
    document.inc_and_set(domain_id, document.TYPE_DISCUSSION, did,
                         'num_replies', 1, 'update_at', datetime.datetime.utcnow()))
  return drdoc
예제 #10
0
파일: discussion.py 프로젝트: wtjiang98/vj4
async def edit_reply(domain_id: str, drid: document.convert_doc_id,
                     content: str):
    validator.check_content(content)
    drdoc = await document.set(domain_id,
                               document.TYPE_DISCUSSION_REPLY,
                               drid,
                               content=content)
    return drdoc
예제 #11
0
파일: discussion.py 프로젝트: zryoung/vj4
async def add_tail_reply(domain_id: str, drid: document.convert_doc_id,
                         owner_uid: int, content: str):
  validator.check_content(content)
  drdoc, sid = await document.push(domain_id, document.TYPE_DISCUSSION_REPLY, drid,
                                   'reply', content, owner_uid)
  await document.set(domain_id, document.TYPE_DISCUSSION, drdoc['parent_doc_id'],
                     update_at=datetime.datetime.utcnow())
  return drdoc, sid
예제 #12
0
파일: discussion.py 프로젝트: vijos/vj4
async def add_tail_reply(domain_id: str, drid: document.convert_doc_id,
                         owner_uid: int, content: str, ip: str=None):
  validator.check_content(content)
  drdoc, sid = await document.push(domain_id, document.TYPE_DISCUSSION_REPLY, drid,
                                   'reply', content, owner_uid, ip=ip)
  await document.set(domain_id, document.TYPE_DISCUSSION, drdoc['parent_doc_id'],
                     update_at=datetime.datetime.utcnow())
  return drdoc, sid
예제 #13
0
파일: problem.py 프로젝트: vijos/vj4
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
예제 #14
0
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
예제 #15
0
파일: discussion.py 프로젝트: vijos/vj4
async def add_reply(domain_id: str, did: document.convert_doc_id, owner_uid: int, content: str,
                    ip: str=None):
  validator.check_content(content)
  drdoc, _ = await asyncio.gather(
    document.add(domain_id, content, owner_uid, document.TYPE_DISCUSSION_REPLY, ip=ip,
                 parent_doc_type=document.TYPE_DISCUSSION, parent_doc_id=did),
    document.inc_and_set(domain_id, document.TYPE_DISCUSSION, did,
                         'num_replies', 1, 'update_at', datetime.datetime.utcnow()))
  return drdoc
예제 #16
0
파일: problem.py 프로젝트: vijos/vj4
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
예제 #17
0
파일: training.py 프로젝트: wtjiang98/vj4
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)
예제 #18
0
파일: discussion.py 프로젝트: zryoung/vj4
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'])
예제 #19
0
파일: problem.py 프로젝트: whitefirer/vj4
async def set_solution(domain_id: str, psid: document.convert_doc_id,
                       content: str):
    validator.check_content(content)
    psdoc = await document.set(domain_id,
                               document.TYPE_PROBLEM_SOLUTION,
                               psid,
                               content=content)
    if not psdoc:
        raise error.DocumentNotFoundError(domain_id,
                                          document.TYPE_PROBLEM_SOLUTION, psid)
    return psdoc
예제 #20
0
파일: problem.py 프로젝트: tc-imba/cb4
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
예제 #21
0
파일: discussion.py 프로젝트: vijos/vj4
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'])
예제 #22
0
파일: training.py 프로젝트: wtjiang98/vj4
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)
예제 #23
0
파일: message.py 프로젝트: vijos/vj4
async def add_reply(message_id: objectid.ObjectId, sender_uid: int, content: str):
  """Reply a message with specified content."""
  validator.check_content(content)
  coll = db.coll('message')
  reply = {'sender_uid': sender_uid,
           'content': content,
           'status': STATUS_UNREAD,
           'at': datetime.datetime.utcnow()}
  mdoc = await coll.find_one_and_update(filter={'_id': message_id},
                                        update={'$push': {'reply': reply}},
                                        return_document=ReturnDocument.AFTER)
  return (mdoc, reply)
예제 #24
0
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)
예제 #25
0
파일: problem.py 프로젝트: whitefirer/vj4
async def add_solution(domain_id: str, pid: document.convert_doc_id, uid: int,
                       content: str):
    validator.check_content(content)
    return await document.add(domain_id,
                              content,
                              uid,
                              document.TYPE_PROBLEM_SOLUTION,
                              None,
                              document.TYPE_PROBLEM,
                              pid,
                              vote=0,
                              reply=[])
예제 #26
0
파일: message.py 프로젝트: vijos/vj4
async def add(sender_uid: int, sendee_uid: int, content: str):
  """Send a message from sender to sendee with specified content."""
  validator.check_content(content)
  coll = db.coll('message')
  mdoc = {'sender_uid': sender_uid,
          'sendee_uid': sendee_uid,
          'status': STATUS_UNREAD,
          'reply': [{'sender_uid': sender_uid,
                     'content': content,
                     'status': STATUS_UNREAD,
                     'at': datetime.datetime.utcnow()}]}
  await coll.insert_one(mdoc)
  return mdoc
예제 #27
0
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
예제 #28
0
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=[])
예제 #29
0
async def add_reply(message_id: objectid.ObjectId, sender_uid: int,
                    content: str):
    """Reply a message with specified content."""
    validator.check_content(content)
    coll = db.coll('message')
    reply = {
        'sender_uid': sender_uid,
        'content': content,
        'status': STATUS_UNREAD,
        'at': datetime.datetime.utcnow()
    }
    mdoc = await coll.find_one_and_update(filter={'_id': message_id},
                                          update={'$push': {
                                              'reply': reply
                                          }},
                                          return_document=ReturnDocument.AFTER)
    return (mdoc, reply)
예제 #30
0
async def add(sender_uid: int, sendee_uid: int, content: str):
    """Send a message from sender to sendee with specified content."""
    validator.check_content(content)
    coll = db.coll('message')
    mdoc = {
        'sender_uid':
        sender_uid,
        'sendee_uid':
        sendee_uid,
        'status':
        STATUS_UNREAD,
        'reply': [{
            'sender_uid': sender_uid,
            'content': content,
            'status': STATUS_UNREAD,
            'at': datetime.datetime.utcnow()
        }]
    }
    await coll.insert_one(mdoc)
    return mdoc
예제 #31
0
파일: contest.py 프로젝트: vijos/vj4
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)
예제 #32
0
파일: problem.py 프로젝트: vijos/vj4
async def set_solution(domain_id: str, psid: document.convert_doc_id, content: str):
  validator.check_content(content)
  psdoc = await document.set(domain_id, document.TYPE_PROBLEM_SOLUTION, psid, content=content)
  if not psdoc:
    raise error.DocumentNotFoundError(domain_id, document.TYPE_PROBLEM_SOLUTION, psid)
  return psdoc
예제 #33
0
파일: discussion.py 프로젝트: vijos/vj4
async def edit_reply(domain_id: str, drid: document.convert_doc_id, content: str):
  validator.check_content(content)
  drdoc = await document.set(domain_id, document.TYPE_DISCUSSION_REPLY, drid, content=content)
  return drdoc
예제 #34
0
파일: discussion.py 프로젝트: vijos/vj4
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)
예제 #35
0
파일: problem.py 프로젝트: vijos/vj4
async def add_solution(domain_id: str, pid: document.convert_doc_id, uid: int, content: str):
  validator.check_content(content)
  return await document.add(domain_id, content, uid, document.TYPE_PROBLEM_SOLUTION, None,
                            document.TYPE_PROBLEM, pid, vote=0, reply=[])
예제 #36
0
파일: problem.py 프로젝트: whitefirer/vj4
async def reply_solution(domain_id: str, psid: document.convert_doc_id,
                         uid: int, content: str):
    validator.check_content(content)
    return await document.push(domain_id, document.TYPE_PROBLEM_SOLUTION, psid,
                               'reply', content, uid)
예제 #37
0
파일: problem.py 프로젝트: vijos/vj4
async def reply_solution(domain_id: str, psid: document.convert_doc_id, uid: int, content: str):
  validator.check_content(content)
  return await document.push(domain_id, document.TYPE_PROBLEM_SOLUTION, psid,
                             'reply', content, uid)