当前位置: 首页>>代码示例>>Python>>正文


Python objectid.ObjectId方法代码示例

本文整理汇总了Python中bson.objectid.ObjectId方法的典型用法代码示例。如果您正苦于以下问题:Python objectid.ObjectId方法的具体用法?Python objectid.ObjectId怎么用?Python objectid.ObjectId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bson.objectid的用法示例。


在下文中一共展示了objectid.ObjectId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validate_metadata_file

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
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) 
开发者ID:broadinstitute,项目名称:single_cell_portal,代码行数:27,代码来源:manage_study.py

示例2: add

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
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'] 
开发者ID:vijos,项目名称:vj4,代码行数:20,代码来源:document.py

示例3: rejudge

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
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']) 
开发者ID:vijos,项目名称:vj4,代码行数:20,代码来源:record.py

示例4: edit

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
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) 
开发者ID:vijos,项目名称:vj4,代码行数:25,代码来源:contest.py

示例5: update_status

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
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 
开发者ID:vijos,项目名称:vj4,代码行数:25,代码来源:contest.py

示例6: get_scoreboard

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
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 
开发者ID:vijos,项目名称:vj4,代码行数:19,代码来源:contest.py

示例7: get

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
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'])) 
开发者ID:vijos,项目名称:vj4,代码行数:20,代码来源:homework.py

示例8: post

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
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)) 
开发者ID:vijos,项目名称:vj4,代码行数:22,代码来源:homework.py

示例9: find_one

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
def find_one(self,id):
        '''获取指定数据'''
        article = self.articles.find_one({"_id": ObjectId(id)})
        return article 
开发者ID:iHealth-ecnu,项目名称:iHealth_site,代码行数:6,代码来源:models.py

示例10: updateRead

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
def updateRead(self,id=None,cnt=1):
        '''阅读量+1'''
        if id == None:
            raise Exception,'请提供 id 参数!'
        self.articles.update_one({'_id':ObjectId(id)},{'$inc':{'read':cnt}}) 
开发者ID:iHealth-ecnu,项目名称:iHealth_site,代码行数:7,代码来源:models.py

示例11: updateUpvote

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
def updateUpvote(self,id=None):
        '''点赞接口'''
        if id == None:
            raise Exception,'请提供 id 参数!'
        self.articles.update_one({'_id':ObjectId(id)},{'$inc':{'upvote':1}}) 
开发者ID:iHealth-ecnu,项目名称:iHealth_site,代码行数:7,代码来源:models.py

示例12: find_label

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
def find_label(self, id):
        '''获取用户对应的labels'''
        user = self.users.find_one({"_id": ObjectId(id)})
        if user.has_key('labels'):
            return user['labels']
        else: #用户没有label
            return None 
开发者ID:iHealth-ecnu,项目名称:iHealth_site,代码行数:9,代码来源:models.py

示例13: update_label

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
def update_label(self, id, label, value):
        '''更新labels中label的值'''
        #没有labels的用户首先设置label
        self.insert_label(id)
        #首先找到对应用户的labels
        user = self.users.find_one({"_id": ObjectId(id)})
        cur_labels = user['labels']
        if cur_labels.has_key(label):
            cur_labels[label] = cur_labels[label] + value
        else: #新增对应label
            cur_labels[label] = value
        self.users.update_one({"_id": ObjectId(id)}, {'$set': {'labels':cur_labels}})

    #修改昵称 
开发者ID:iHealth-ecnu,项目名称:iHealth_site,代码行数:16,代码来源:models.py

示例14: changeNickname

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
def changeNickname(self,id=None,newName=None):
        if id == None or newName == None:
            raise Exception,'请提供 id 和昵称完整参数!'
        self.users.update_one({'_id':ObjectId(id)},{'$set':{'nickname':newName}})

    #修改手机号 
开发者ID:iHealth-ecnu,项目名称:iHealth_site,代码行数:8,代码来源:models.py

示例15: changePhone

# 需要导入模块: from bson import objectid [as 别名]
# 或者: from bson.objectid import ObjectId [as 别名]
def changePhone(self,id=None,newPhone=None):
        if id == None or newPhone == None:
            raise Exception,'请提供 id 和手机号完整参数!'
        self.users.update_one({'_id':ObjectId(id)},{'$set':{'phone':newPhone}})

    #修改用户姓名 
开发者ID:iHealth-ecnu,项目名称:iHealth_site,代码行数:8,代码来源:models.py


注:本文中的bson.objectid.ObjectId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。