Python bson.objectid.ObjectId() Examples

The following are 30 code examples of bson.objectid.ObjectId(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bson.objectid , or try the search function .
Example #1
Source File: contest.py    From vj4 with GNU Affero General Public License v3.0 6 votes vote down vote up
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) 
Example #2
Source File: record.py    From vj4 with GNU Affero General Public License v3.0 6 votes vote down vote up
def rejudge(record_id: objectid.ObjectId, enqueue: bool=True):
  coll = db.coll('record')
  doc = await coll.find_one_and_update(filter={'_id': record_id},
                                       update={'$unset': {'judge_uid': '',
                                                          'judge_token': '',
                                                          'judge_at': '',
                                                          'compiler_texts': '',
                                                          'judge_texts': '',
                                                          'cases': ''},
                                               '$set': {'status': constant.record.STATUS_WAITING,
                                                        'score': 0,
                                                        'time_ms': 0,
                                                        'memory_kb': 0,
                                                        'rejudged': True}},
                                       return_document=ReturnDocument.AFTER)
  bus.publish_throttle('record_change', doc, doc['_id'])
  if enqueue:
    await queue.publish('judge', rid=doc['_id']) 
Example #3
Source File: homework.py    From vj4 with GNU Affero General Public License v3.0 6 votes vote down vote up
def get(self, *, tid: objectid.ObjectId):
    tdoc, tsdocs = await contest.get_and_list_status(self.domain_id, document.TYPE_HOMEWORK, tid)
    rnames = {}
    for tsdoc in tsdocs:
      for pdetail in tsdoc.get('detail', []):
        rnames[pdetail['rid']] = 'U{}_P{}_R{}'.format(tsdoc['uid'], pdetail['pid'], pdetail['rid'])
    output_buffer = io.BytesIO()
    zip_file = zipfile.ZipFile(output_buffer, 'a', zipfile.ZIP_DEFLATED)
    rdocs = record.get_multi(get_hidden=True, _id={'$in': list(rnames.keys())})
    async for rdoc in rdocs:
      zip_file.writestr(rnames[rdoc['_id']] + '.' + rdoc['lang'], rdoc['code'])
    # mark all files as created in Windows :p
    for zfile in zip_file.filelist:
      zfile.create_system = 0
    zip_file.close()

    await self.binary(output_buffer.getvalue(), 'application/zip',
                      file_name='{}.zip'.format(tdoc['title'])) 
Example #4
Source File: contest.py    From vj4 with GNU Affero General Public License v3.0 6 votes vote down vote up
def update_status(domain_id: str, doc_type: int, tid: objectid.ObjectId, uid: int,
                        rid: objectid.ObjectId, pid: document.convert_doc_id,
                        accept: bool, score: int):
  """This method returns None when the modification has been superseded by a parallel operation."""
  if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]:
    raise error.InvalidArgumentError('doc_type')
  tdoc = await document.get(domain_id, doc_type, tid)
  tsdoc = await document.rev_push_status(
    domain_id, tdoc['doc_type'], tdoc['doc_id'], uid,
    'journal', {'rid': rid, 'pid': pid, 'accept': accept, 'score': score})
  if 'attend' not in tsdoc or not tsdoc['attend']:
    if tdoc['doc_type'] == document.TYPE_CONTEST:
      raise error.ContestNotAttendedError(domain_id, tid, uid)
    elif tdoc['doc_type'] == document.TYPE_HOMEWORK:
      raise error.HomeworkNotAttendedError(domain_id, tid, uid)
    else:
      raise error.InvalidArgumentError('doc_type')

  journal = _get_status_journal(tsdoc)
  stats = RULES[tdoc['rule']].stat_func(tdoc, journal)
  tsdoc = await document.rev_set_status(domain_id, tdoc['doc_type'], tid, uid, tsdoc['rev'],
                                        journal=journal, **stats)
  return tsdoc 
Example #5
Source File: homework.py    From vj4 with GNU Affero General Public License v3.0 6 votes vote down vote up
def get(self, *, tid: objectid.ObjectId, pid: document.convert_doc_id):
    uid = self.user['_id'] if self.has_priv(builtin.PRIV_USER_PROFILE) else None
    tdoc, pdoc = await asyncio.gather(contest.get(self.domain_id, document.TYPE_HOMEWORK, tid),
                                      problem.get(self.domain_id, pid, uid))
    tsdoc, udoc, dudoc = await asyncio.gather(
        contest.get_status(self.domain_id, document.TYPE_HOMEWORK, tdoc['doc_id'], self.user['_id']),
        user.get_by_uid(tdoc['owner_uid']),
        domain.get_user(domain_id=self.domain_id, uid=tdoc['owner_uid']))
    attended = tsdoc and tsdoc.get('attend') == 1
    if not self.is_done(tdoc):
      if not attended:
        raise error.HomeworkNotAttendedError(tdoc['doc_id'])
      if not self.is_ongoing(tdoc):
        raise error.HomeworkNotLiveError(tdoc['doc_id'])
    if pid not in tdoc['pids']:
      raise error.ProblemNotFoundError(self.domain_id, pid, tdoc['doc_id'])
    path_components = self.build_path(
        (self.translate('homework_main'), self.reverse_url('homework_main')),
        (tdoc['title'], self.reverse_url('homework_detail', tid=tid)),
        (pdoc['title'], None))
    self.render('problem_detail.html', tdoc=tdoc, pdoc=pdoc, tsdoc=tsdoc, udoc=udoc,
                attended=attended, dudoc=dudoc,
                page_title=pdoc['title'], path_components=path_components) 
Example #6
Source File: contest.py    From vj4 with GNU Affero General Public License v3.0 6 votes vote down vote up
def get_scoreboard(self, doc_type: int, tid: objectid.ObjectId, is_export: bool=False):
    if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]:
      raise error.InvalidArgumentError('doc_type')
    tdoc, tsdocs = await get_and_list_status(self.domain_id, doc_type, tid)
    if not self.can_show_scoreboard(tdoc):
      if doc_type == document.TYPE_CONTEST:
        raise error.ContestScoreboardHiddenError(self.domain_id, tid)
      elif doc_type == document.TYPE_HOMEWORK:
        raise error.HomeworkScoreboardHiddenError(self.domain_id, tid)
    udict, dudict, pdict = await asyncio.gather(
        user.get_dict([tsdoc['uid'] for tsdoc in tsdocs]),
        domain.get_dict_user_by_uid(self.domain_id, [tsdoc['uid'] for tsdoc in tsdocs]),
        problem.get_dict(self.domain_id, tdoc['pids']))
    ranked_tsdocs = RULES[tdoc['rule']].rank_func(tsdocs)
    rows = RULES[tdoc['rule']].scoreboard_func(is_export, self.translate, tdoc,
                                                       ranked_tsdocs, udict, dudict, pdict)
    return tdoc, rows, udict 
Example #7
Source File: homework.py    From vj4 with GNU Affero General Public License v3.0 6 votes vote down vote up
def get(self, *, tid: objectid.ObjectId):
    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)
    begin_at = pytz.utc.localize(tdoc['begin_at']).astimezone(self.timezone)
    penalty_since = pytz.utc.localize(tdoc['penalty_since']).astimezone(self.timezone)
    end_at = pytz.utc.localize(tdoc['end_at']).astimezone(self.timezone)
    extension_days = round((end_at - penalty_since).total_seconds() / 60 / 60 / 24, ndigits=2)
    page_title = self.translate('homework_edit')
    path_components = self.build_path(
        (self.translate('homework_main'), self.reverse_url('homework_main')),
        (tdoc['title'], self.reverse_url('homework_detail', tid=tdoc['doc_id'])),
        (page_title, None))
    self.render('homework_edit.html', tdoc=tdoc,
                date_begin_text=begin_at.strftime('%Y-%m-%d'),
                time_begin_text=begin_at.strftime('%H:%M'),
                date_penalty_text=penalty_since.strftime('%Y-%m-%d'),
                time_penalty_text=penalty_since.strftime('%H:%M'),
                extension_days=extension_days,
                penalty_rules=_format_penalty_rules_yaml(tdoc['penalty_rules']),
                pids=contest._format_pids(tdoc['pids']),
                page_title=page_title, path_components=path_components) 
Example #8
Source File: homework.py    From vj4 with GNU Affero General Public License v3.0 6 votes vote down vote up
def post(self, *, tid: objectid.ObjectId, pid: document.convert_doc_id,
                 lang: str, code: str):
    tdoc, pdoc = await asyncio.gather(contest.get(self.domain_id, document.TYPE_HOMEWORK, tid),
                                      problem.get(self.domain_id, pid))
    tsdoc = await contest.get_status(self.domain_id, document.TYPE_HOMEWORK, tdoc['doc_id'], self.user['_id'])
    if not tsdoc or tsdoc.get('attend') != 1:
      raise error.HomeworkNotAttendedError(tdoc['doc_id'])
    if not self.is_ongoing(tdoc):
      raise error.HomeworkNotLiveError(tdoc['doc_id'])
    if pid not in tdoc['pids']:
      raise error.ProblemNotFoundError(self.domain_id, pid, tdoc['doc_id'])
    rid = await record.add(self.domain_id, pdoc['doc_id'], constant.record.TYPE_SUBMISSION,
                           self.user['_id'], lang, code,
                           ttype=document.TYPE_HOMEWORK, tid=tdoc['doc_id'], hidden=True)
    await contest.update_status(self.domain_id, document.TYPE_HOMEWORK, tdoc['doc_id'], self.user['_id'],
                                rid, pdoc['doc_id'], False, 0)
    if not self.can_show_record(tdoc):
      self.json_or_redirect(self.reverse_url('homework_detail', tid=tdoc['doc_id']))
    else:
      self.json_or_redirect(self.reverse_url('record_detail', rid=rid)) 
Example #9
Source File: document.py    From vj4 with GNU Affero General Public License v3.0 6 votes vote down vote up
def add(domain_id: str, content: str, owner_uid: int,
              doc_type: int, doc_id: convert_doc_id = None,
              parent_doc_type: int = None, parent_doc_id: convert_doc_id = None, **kwargs):
  """Add a document. Returns the document id."""
  obj_id = objectid.ObjectId()
  coll = db.coll('document')
  doc = {'_id': obj_id,
         'content': content,
         'owner_uid': owner_uid,
         'domain_id': domain_id,
         'doc_type': doc_type,
         'doc_id': doc_id or obj_id,
         **kwargs}
  if parent_doc_type or parent_doc_id:
    assert parent_doc_type and parent_doc_id
    doc['parent_doc_type'], doc['parent_doc_id'] = parent_doc_type, parent_doc_id
  await coll.insert_one(doc)
  return doc['doc_id'] 
Example #10
Source File: manage_study.py    From single_cell_portal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def validate_metadata_file(metadata_path):
    study_name = get_parsed_args().study_name
    dry_run = get_parsed_args().dry_run
    verbose = get_parsed_args().verbose
    study_accession_res =get_connection().get_study_attribute(
        study_name=study_name,
        attribute='accession',
        dry_run=dry_run)
    # Needed dummy values for CellMetadata
    study_file = ObjectId('addedfeed000000000000000')
    study_file_id = ObjectId('addedfeed000000000000001')
    if succeeded(study_accession_res):
        if verbose:
            print(f'Study accession {study_accession_res} retrieved for {study_name}')
        study_accession = study_accession_res.get('study_attribute')
        metadata = CellMetadata(metadata_path, study_file, study_file_id, study_accession=str(study_accession))
        convention_res = get_connection().do_get(command=get_api_base() + 'metadata_schemas/alexandria_convention/latest/json',dry_run=dry_run)
        if succeeded(convention_res ):
            if verbose:
                print(f'Retreieved file for latest metdata convention')
            convention = convention_res["response"].json()
            validate_input_metadata(metadata, convention)
            serialize_issues(metadata)
            report_issues(metadata)
            exit_if_errors(metadata) 
Example #11
Source File: userfile.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #12
Source File: contest.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def get(self, *, tid: objectid.ObjectId, page: int=1):
    tdoc = await contest.get(self.domain_id, document.TYPE_CONTEST, tid)
    tsdoc, pdict = await asyncio.gather(
        contest.get_status(self.domain_id, document.TYPE_CONTEST, tdoc['doc_id'], self.user['_id']),
        problem.get_dict(self.domain_id, tdoc['pids']))
    psdict = dict()
    rdict = dict()
    if tsdoc:
      attended = tsdoc.get('attend') == 1
      for pdetail in tsdoc.get('detail', []):
        psdict[pdetail['pid']] = pdetail
      if self.can_show_record(tdoc):
        rdict = await record.get_dict((psdoc['rid'] for psdoc in psdict.values()),
                                      get_hidden=True)
      else:
        rdict = dict((psdoc['rid'], {'_id': psdoc['rid']}) for psdoc in psdict.values())
    else:
      attended = False
    # discussion
    ddocs, dpcount, dcount = await pagination.paginate(
        discussion.get_multi(self.domain_id,
                             parent_doc_type=tdoc['doc_type'],
                             parent_doc_id=tdoc['doc_id']),
        page, self.DISCUSSIONS_PER_PAGE)
    uids = set(ddoc['owner_uid'] for ddoc in ddocs)
    uids.add(tdoc['owner_uid'])
    udict = await user.get_dict(uids)
    dudict = await domain.get_dict_user_by_uid(domain_id=self.domain_id, uids=uids)
    path_components = self.build_path(
      (self.translate('contest_main'), self.reverse_url('contest_main')),
      (tdoc['title'], None))
    self.render('contest_detail.html', tdoc=tdoc, tsdoc=tsdoc, attended=attended, udict=udict,
                dudict=dudict, pdict=pdict, psdict=psdict, rdict=rdict,
                ddocs=ddocs, page=page, dpcount=dpcount, dcount=dcount,
                datetime_stamp=self.datetime_stamp,
                page_title=tdoc['title'], path_components=path_components) 
Example #13
Source File: userfile.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def delete(fid: objectid.ObjectId):
  doc = await get(fid)
  result = await document.delete(STORE_DOMAIN_ID, document.TYPE_USERFILE, fid)
  result = bool(result.deleted_count)
  if result:
    await fs.unlink(doc['file_id'])
  return result 
Example #14
Source File: record.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def on_open(self):
    await super(RecordDetailConnection, self).on_open()
    self.rid = objectid.ObjectId(self.request.match_info['rid'])
    rdoc = await record.get(self.rid, record.PROJECTION_PUBLIC)
    if rdoc['tid']:
      show_status, tdoc = await self.rdoc_contest_visible(rdoc)
      if not show_status:
        self.close()
        return
    bus.subscribe(self.on_record_change, ['record_change'])
    self.send_record(rdoc) 
Example #15
Source File: discussion.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def post_delete_tail_reply(self, *, did: document.convert_doc_id,
                                   drid: document.convert_doc_id, drrid: objectid.ObjectId):
    ddoc = await discussion.get(self.domain_id, did)
    drdoc, drrdoc = await discussion.get_tail_reply(self.domain_id, drid, drrid)
    if not drdoc or drdoc['parent_doc_id'] != ddoc['doc_id']:
      raise error.DocumentNotFoundError(domain_id, document.TYPE_DISCUSSION_REPLY, drid)
    if (not self.own(ddoc, builtin.PERM_DELETE_DISCUSSION_REPLY_SELF_DISCUSSION)
        and not self.own(drrdoc, builtin.PERM_DELETE_DISCUSSION_REPLY_SELF)):
      self.check_perm(builtin.PERM_DELETE_DISCUSSION_REPLY)
    await oplog.add(self.user['_id'], oplog.TYPE_DELETE_SUB_DOCUMENT, sub_doc=drrdoc,
                    doc_type=drdoc['doc_type'], doc_id=drdoc['doc_id'])
    await discussion.delete_tail_reply(self.domain_id, drid, drrid)
    self.json_or_redirect(self.url) 
Example #16
Source File: discussion.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def get(self, *, did: document.convert_doc_id, drid: document.convert_doc_id,
                drrid: objectid.ObjectId):
    ddoc = await discussion.get(self.domain_id, did)
    drdoc, drrdoc = await discussion.get_tail_reply(self.domain_id, drid, drrid)
    self.response.content_type = 'text/markdown'
    self.response.text = drrdoc['content'] 
Example #17
Source File: home.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def post_reply_message(self, *, message_id: objectid.ObjectId, content: str):
    mdoc, reply = await message.add_reply(message_id, self.user['_id'], content)
    if not mdoc:
      return error.MessageNotFoundError(message_id)
    if mdoc['sender_uid'] != mdoc['sendee_uid']:
      if mdoc['sender_uid'] == self.user['_id']:
        other_uid = mdoc['sendee_uid']
      else:
        other_uid = mdoc['sender_uid']
      mdoc['reply'] = [reply]
      await bus.publish('message_received-' + str(other_uid), {'type': 'reply', 'data': mdoc})
    self.json_or_redirect(self.url, reply=reply) 
Example #18
Source File: home.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def post_delete_message(self, *, message_id: objectid.ObjectId):
    await message.delete(message_id, self.user['_id'])
    self.json_or_redirect(self.url) 
Example #19
Source File: record.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def get(self, *, rid: objectid.ObjectId):
    rdoc = await record.get(rid)
    if not rdoc or rdoc['type'] != constant.record.TYPE_PRETEST:
      raise error.RecordNotFoundError(rid)
    if not self.own(rdoc, builtin.PRIV_READ_PRETEST_DATA_SELF, 'uid'):
      self.check_priv(builtin.PRIV_READ_PRETEST_DATA)
    if not rdoc.get('data_id'):
      raise error.RecordDataNotFoundError(rdoc['_id'])
    secret = await fs.get_secret(rdoc['data_id'])
    if not secret:
      raise error.RecordDataNotFoundError(rdoc['_id'])
    self.redirect(options.cdn_prefix.rstrip('/') + \
                  self.reverse_url('fs_get', domain_id=builtin.DOMAIN_ID_SYSTEM,
                                   secret=secret)) 
Example #20
Source File: training.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def set_status(domain_id: str, tid: objectid.ObjectId, uid: int, **kwargs):
  return await document.set_status(domain_id, document.TYPE_TRAINING, tid, uid, **kwargs) 
Example #21
Source File: problem.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def update_status(domain_id: str, pid: document.convert_doc_id, uid: int,
                        rid: objectid.ObjectId, status: int):
  try:
    return await document.set_if_not_status(domain_id, document.TYPE_PROBLEM, pid, uid,
                                            'status', status, constant.record.STATUS_ACCEPTED,
                                            rid=rid)
  except errors.DuplicateKeyError:
    return None 
Example #22
Source File: problem.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def set_data(domain_id: str, pid: document.convert_doc_id, data: objectid.ObjectId):
  pdoc = await document.set(domain_id, document.TYPE_PROBLEM, pid, data=data)
  if not pdoc:
    raise error.DocumentNotFoundError(domain_id, document.TYPE_PROBLEM, pid)
  await bus.publish('problem_data_change', {'domain_id': domain_id, 'pid': pid})
  return pdoc 
Example #23
Source File: problem.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def delete_solution_reply(domain_id: str, psid: document.convert_doc_id, psrid: objectid.ObjectId):
  return document.delete_sub(domain_id, document.TYPE_PROBLEM_SOLUTION, psid, 'reply', psrid) 
Example #24
Source File: problem.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def edit_solution_reply(domain_id: str, psid: document.convert_doc_id, psrid: objectid.ObjectId,
                        content: str):
  return document.set_sub(domain_id, document.TYPE_PROBLEM_SOLUTION, psid, 'reply', psrid,
                          content=content) 
Example #25
Source File: problem.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example #26
Source File: contest.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def recalc_status(domain_id: str, doc_type: int, tid: objectid.ObjectId):
  if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]:
    raise error.InvalidArgumentError('doc_type')
  tdoc = await document.get(domain_id, doc_type, tid)
  async with document.get_multi_status(domain_id=domain_id,
                                       doc_type=doc_type,
                                       doc_id=tdoc['doc_id']) as tsdocs:
    async for tsdoc in tsdocs:
      if 'journal' not in tsdoc or not tsdoc['journal']:
        continue
      journal = _get_status_journal(tsdoc)
      stats = RULES[tdoc['rule']].stat_func(tdoc, journal)
      await document.rev_set_status(domain_id, doc_type, tid, tsdoc['uid'], tsdoc['rev'],
                                    return_doc=False, journal=journal, **stats) 
Example #27
Source File: contest.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_and_list_status(domain_id: str, doc_type: int, tid: objectid.ObjectId, fields=None):
  # TODO(iceboy): projection, pagination.
  if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]:
    raise error.InvalidArgumentError('doc_type')
  tdoc = await get(domain_id, doc_type, tid)
  tsdocs = await document.get_multi_status(domain_id=domain_id,
                                           doc_type=doc_type,
                                           doc_id=tdoc['doc_id'],
                                           fields=fields) \
                         .sort(RULES[tdoc['rule']].status_sort) \
                         .to_list()
  return tdoc, tsdocs 
Example #28
Source File: contest.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def attend(domain_id: str, doc_type: int, tid: objectid.ObjectId, uid: int):
  # TODO(iceboy): check time.
  if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]:
    raise error.InvalidArgumentError('doc_type')
  try:
    await document.capped_inc_status(domain_id, doc_type, tid,
                                     uid, 'attend', 1, 0, 1)
  except errors.DuplicateKeyError:
    if doc_type == document.TYPE_CONTEST:
      raise error.ContestAlreadyAttendedError(domain_id, tid, uid) from None
    elif doc_type == document.TYPE_HOMEWORK:
      raise error.HomeworkAlreadyAttendedError(domain_id, tid, uid) from None
  return await document.inc(domain_id, doc_type, tid, 'attend', 1) 
Example #29
Source File: contest.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def get(domain_id: str, doc_type: int, tid: objectid.ObjectId):
  if doc_type not in [document.TYPE_CONTEST, document.TYPE_HOMEWORK]:
    raise error.InvalidArgumentError('doc_type')
  tdoc = await document.get(domain_id, doc_type, tid)
  if not tdoc:
    raise error.DocumentNotFoundError(domain_id, doc_type, tid)
  return tdoc 
Example #30
Source File: discussion.py    From vj4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def delete_tail_reply(domain_id: str, drid: document.convert_doc_id, drrid: objectid.ObjectId):
  return document.delete_sub(domain_id, document.TYPE_DISCUSSION_REPLY, drid, 'reply', drrid)