Exemple #1
0
 async 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, tid),
                                     problem.get(self.domain_id, pid, uid))
   tsdoc = await contest.get_status(self.domain_id, tdoc['doc_id'], self.user['_id'])
   if not tsdoc or tsdoc.get('attend') != 1:
     raise error.ContestNotAttendedError(tdoc['doc_id'])
   if not self.is_live(tdoc):
     raise error.ContestNotLiveError(tdoc['doc_id'])
   if pid not in tdoc['pids']:
     raise error.ProblemNotFoundError(self.domain_id, pid, tdoc['doc_id'])
   tsdoc, udoc = await asyncio.gather(
       contest.get_status(self.domain_id, tdoc['doc_id'], self.user['_id']),
       user.get_by_uid(tdoc['owner_uid']))
   attended = tsdoc and tsdoc.get('attend') == 1
   if (contest.RULES[tdoc['rule']].show_func(tdoc, self.now)
       or self.has_perm(builtin.PERM_VIEW_CONTEST_HIDDEN_STATUS)):
     rdocs = await record.get_user_in_problem_multi(uid, self.domain_id, pdoc['doc_id']) \
                         .sort([('_id', -1)]) \
                         .limit(10) \
                         .to_list()
   else:
     rdocs = []
   if not self.prefer_json:
     path_components = self.build_path(
         (self.translate('contest_main'), self.reverse_url('contest_main')),
         (tdoc['title'], self.reverse_url('contest_detail', tid=tid)),
         (pdoc['title'], self.reverse_url('contest_detail_problem', tid=tid, pid=pid)),
         (self.translate('contest_detail_problem_submit'), None))
     self.render('problem_submit.html', tdoc=tdoc, pdoc=pdoc, rdocs=rdocs,
                 tsdoc=tsdoc, udoc=udoc, attended=attended,
                 page_title=pdoc['title'], path_components=path_components)
   else:
     self.json({'rdocs': rdocs})
Exemple #2
0
 async def post(self, *, tid: objectid.ObjectId,
                pid: document.convert_doc_id, lang: str, code: str):
     await opcount.inc(**opcount.OPS['run_code'],
                       ident=opcount.PREFIX_USER + str(self.user['_id']))
     tdoc, pdoc = await asyncio.gather(contest.get(self.domain_id, tid),
                                       problem.get(self.domain_id, pid))
     tsdoc = await contest.get_status(self.domain_id, tdoc['doc_id'],
                                      self.user['_id'])
     if not tsdoc or tsdoc.get('attend') != 1:
         raise error.ContestNotAttendedError(tdoc['doc_id'])
     if not self.is_live(tdoc):
         raise error.ContestNotLiveError(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,
                            tid=tdoc['doc_id'],
                            hidden=True)
     await contest.update_status(self.domain_id, 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('contest_detail', tid=tdoc['doc_id']))
     else:
         self.json_or_redirect(self.reverse_url('record_detail', rid=rid))
Exemple #3
0
 async 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 = 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']))
   attended = tsdoc and tsdoc.get('attend') == 1
   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'])
   if self.can_show_record(tdoc):
     rdocs = await record.get_user_in_problem_multi(uid, self.domain_id, pdoc['doc_id'], get_hidden=True) \
                         .sort([('_id', -1)]) \
                         .limit(10) \
                         .to_list()
   else:
     rdocs = []
   if not self.prefer_json:
     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'], self.reverse_url('homework_detail_problem', tid=tid, pid=pid)),
         (self.translate('homework_detail_problem_submit'), None))
     self.render('problem_submit.html', tdoc=tdoc, pdoc=pdoc, rdocs=rdocs,
                 tsdoc=tsdoc, udoc=udoc, attended=attended,
                 page_title=pdoc['title'], path_components=path_components)
   else:
     self.json({'rdocs': rdocs})
Exemple #4
0
 async 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)
Exemple #5
0
 async 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_CONTEST, tid),
                                     problem.get(self.domain_id, pid, uid))
   tsdoc, udoc = await asyncio.gather(
       contest.get_status(self.domain_id, document.TYPE_CONTEST, tdoc['doc_id'], self.user['_id']),
       user.get_by_uid(tdoc['owner_uid']))
   attended = tsdoc and tsdoc.get('attend') == 1
   if not attended:
     raise error.ContestNotAttendedError(tdoc['doc_id'])
   if not self.is_ongoing(tdoc):
     raise error.ContestNotLiveError(tdoc['doc_id'])
   if pid not in tdoc['pids']:
     raise error.ProblemNotFoundError(self.domain_id, pid, tdoc['doc_id'])
   if self.can_show_record(tdoc):
     rdocs = await record.get_user_in_problem_multi(uid, self.domain_id, pdoc['doc_id'], get_hidden=True) \
                         .sort([('_id', -1)]) \
                         .limit(10) \
                         .to_list()
   else:
     rdocs = []
   if not self.prefer_json:
     path_components = self.build_path(
         (self.translate('contest_main'), self.reverse_url('contest_main')),
         (tdoc['title'], self.reverse_url('contest_detail', tid=tid)),
         (pdoc['title'], self.reverse_url('contest_detail_problem', tid=tid, pid=pid)),
         (self.translate('contest_detail_problem_submit'), None))
     self.render('problem_submit.html', tdoc=tdoc, pdoc=pdoc, rdocs=rdocs,
                 tsdoc=tsdoc, udoc=udoc, attended=attended,
                 page_title=pdoc['title'], path_components=path_components)
   else:
     self.json({'rdocs': rdocs})
Exemple #6
0
 async def get(self, *, rid: objectid.ObjectId):
   rdoc = await record.get(rid)
   if not rdoc:
     raise error.RecordNotFoundError(rid)
   rdoc['udoc'], rdoc['pdoc'] = await asyncio.gather(
     user.get_by_uid(rdoc['uid']), problem.get(rdoc['domain_id'], rdoc['pid']))
   self.render('record_detail.html', rdoc=rdoc)
Exemple #7
0
 async 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))
Exemple #8
0
 async def on_record_change(self, e):
   rdoc = await record.get(objectid.ObjectId(e['value']))
   # TODO(iceboy): join from event to improve performance?
   # TODO(iceboy): projection.
   rdoc['udoc'], rdoc['pdoc'] = await asyncio.gather(
     user.get_by_uid(rdoc['uid']), problem.get(rdoc['domain_id'], rdoc['pid']))
   # TODO(iceboy): check permission for visibility. (e.g. test).
   self.send(html=self.render_html('record_tr.html', rdoc=rdoc), rdoc=rdoc)
Exemple #9
0
 async def get(self, *, rid: objectid.ObjectId):
     rdoc = await record.get(rid)
     if not rdoc:
         raise error.RecordNotFoundError(rid)
     rdoc['udoc'], rdoc['pdoc'] = await asyncio.gather(
         user.get_by_uid(rdoc['uid']),
         problem.get(rdoc['domain_id'], rdoc['pid']))
     self.render('record_detail.html', rdoc=rdoc)
Exemple #10
0
 async def on_record_change(self, e):
     rdoc = await record.get(objectid.ObjectId(e['value']))
     # TODO(iceboy): join from event to improve performance?
     # TODO(iceboy): projection.
     rdoc['udoc'], rdoc['pdoc'] = await asyncio.gather(
         user.get_by_uid(rdoc['uid']),
         problem.get(rdoc['domain_id'], rdoc['pid']))
     # TODO(iceboy): check permission for visibility. (e.g. test).
     self.send(html=self.render_html('record_tr.html', rdoc=rdoc),
               rdoc=rdoc)
Exemple #11
0
 async def post(self, *, ctype: str, tid: objectid.ObjectId,
                pid: document.convert_doc_id, lang: str,
                code: objectid.ObjectId):
     doc_type = constant.contest.CTYPE_TO_DOCTYPE[ctype]
     # TODO(iceboy): rate limit base on ip.
     tdoc, pdoc = await asyncio.gather(
         contest.get(self.domain_id, doc_type, tid),
         problem.get(self.domain_id, pid))
     tsdoc = await contest.get_status(self.domain_id, doc_type,
                                      tdoc['doc_id'], self.user['_id'])
     if not tsdoc or tsdoc.get('attend') != 1:
         if ctype == 'contest':
             raise error.ContestNotAttendedError(tdoc['doc_id'])
         elif ctype == 'homework':
             raise error.HomeworkNotAttendedError(tdoc['doc_id'])
         else:
             raise error.InvalidArgumentError('ctype')
     if not self.is_ongoing(tdoc):
         if ctype == 'contest':
             raise error.ContestNotLiveError(tdoc['doc_id'])
         elif ctype == 'homework':
             raise error.HomeworkNotLiveError(tdoc['doc_id'])
         else:
             raise error.InvalidArgumentError('ctype')
     if pid not in tdoc['pids']:
         raise error.ProblemNotFoundError(self.domain_id, pid,
                                          tdoc['doc_id'])
     # TODO(tc-imba): only constant.record.CODE_TYPE_TAR is supported now
     rid = await record.add(self.domain_id,
                            pdoc['doc_id'],
                            constant.record.TYPE_SUBMISSION,
                            self.user['_id'],
                            lang,
                            code,
                            tid=tdoc['doc_id'],
                            hidden=False,
                            code_type=constant.record.CODE_TYPE_TAR)
     await contest.update_status(self.domain_id, 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('contest_detail',
                              ctype=ctype,
                              tid=tdoc['doc_id']))
     else:
         self.json_or_redirect(self.reverse_url('record_detail', rid=rid))
Exemple #12
0
 async def get(self, *, rid: objectid.ObjectId):
     rdoc = await record.get(rid)
     if not rdoc:
         raise error.RecordNotFoundError(rid)
     # TODO(iceboy): Check domain permission, permission for visibility in place.
     if rdoc['domain_id'] != self.domain_id:
         self.redirect(
             self.reverse_url('record_detail',
                              rid=rid,
                              domain_id=rdoc['domain_id']))
         return
     # check permission for visibility: contest
     show_status = True
     if rdoc['tid']:
         now = datetime.datetime.utcnow()
         tdoc = await contest.get(rdoc['domain_id'], rdoc['tid'])
         show_status = contest.RULES[tdoc['rule']].show_func(tdoc, now) \
                       or self.has_perm(builtin.PERM_VIEW_CONTEST_HIDDEN_STATUS)
     # TODO(twd2): futher check permission for visibility.
     if (not self.own(rdoc, field='uid')
             and not self.has_perm(builtin.PERM_READ_RECORD_CODE)
             and not self.has_priv(builtin.PRIV_READ_RECORD_CODE)):
         del rdoc['code']
     if not show_status and 'code' not in rdoc:
         raise error.PermissionError(
             builtin.PERM_VIEW_CONTEST_HIDDEN_STATUS)
     udoc, dudoc, pdoc = await asyncio.gather(
         user.get_by_uid(rdoc['uid']),
         domain.get_user(self.domain_id, rdoc['uid']),
         problem.get(rdoc['domain_id'], rdoc['pid']))
     if show_status and 'judge_uid' in rdoc:
         judge_udoc = await user.get_by_uid(rdoc['judge_uid'])
     else:
         judge_udoc = None
     # check permission for visibility: hidden problem
     if pdoc.get(
             'hidden',
             False) and not self.has_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN):
         pdoc = None
     self.render('record_detail.html',
                 rdoc=rdoc,
                 udoc=udoc,
                 dudoc=dudoc,
                 pdoc=pdoc,
                 judge_udoc=judge_udoc,
                 show_status=show_status)
Exemple #13
0
 async def on_record_change(self, e):
   rdoc = e['value']
   for key, value in self.query.items():
     if rdoc[key] != value:
       return
   if rdoc['tid']:
     show_status, tdoc = await self.rdoc_contest_visible(rdoc)
     if not show_status:
       return
   # TODO(iceboy): projection.
   udoc, pdoc = await asyncio.gather(user.get_by_uid(rdoc['uid']),
                                     problem.get(rdoc['domain_id'], rdoc['pid']))
   # check permission for visibility: hidden problem
   if pdoc.get('hidden', False) and (pdoc['domain_id'] != self.domain_id
                                     or not self.has_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN)):
     pdoc = None
   self.send(html=self.render_html('record_main_tr.html', rdoc=rdoc, udoc=udoc, pdoc=pdoc))
Exemple #14
0
 async def get(self, *, ctype: str, tid: objectid.ObjectId,
               pid: document.convert_doc_id):
     doc_type = constant.contest.CTYPE_TO_DOCTYPE[ctype]
     uid = self.user['_id'] if self.has_priv(
         builtin.PRIV_USER_PROFILE) else None
     tdoc, pdoc = await asyncio.gather(
         contest.get(self.domain_id, doc_type, tid),
         problem.get(self.domain_id, pid, uid))
     tsdoc, udoc = await asyncio.gather(
         contest.get_status(self.domain_id, doc_type, tdoc['doc_id'],
                            self.user['_id']),
         user.get_by_uid(tdoc['owner_uid']))
     attended = tsdoc and tsdoc.get('attend') == 1
     if not self.is_finished(tdoc):
         if not attended:
             if ctype == 'contest':
                 raise error.ContestNotAttendedError(tdoc['doc_id'])
             elif ctype == 'homework':
                 raise error.HomeworkNotAttendedError(tdoc['doc_id'])
             else:
                 raise error.InvalidArgumentError('ctype')
         if not self.is_ongoing(tdoc):
             if ctype == 'contest':
                 raise error.ContestNotLiveError(tdoc['doc_id'])
             elif ctype == 'homework':
                 raise error.HomeworkNotLiveError(tdoc['doc_id'])
             else:
                 raise error.InvalidArgumentError('ctype')
     if pid not in tdoc['pids']:
         raise error.ProblemNotFoundError(self.domain_id, pid,
                                          tdoc['doc_id'])
     path_components = self.build_path(
         (self.translate('page.contest_main.{0}.title'.format(ctype)),
          self.reverse_url('contest_main', ctype=ctype)),
         (tdoc['title'],
          self.reverse_url('contest_detail', ctype=ctype, tid=tid)),
         (pdoc['title'], None))
     self.render('problem_detail.html',
                 tdoc=tdoc,
                 pdoc=pdoc,
                 tsdoc=tsdoc,
                 udoc=udoc,
                 attended=attended,
                 page_title=pdoc['title'],
                 path_components=path_components)
Exemple #15
0
 async def on_record_change(self, e):
   rdoc = e['value']
   for key, value in self.query.items():
     if rdoc[key] != value:
       return
   if rdoc['tid']:
     show_status, tdoc = await self.rdoc_contest_visible(rdoc)
     if not show_status:
       return
   # TODO(iceboy): projection.
   udoc, dudoc, pdoc = await asyncio.gather(user.get_by_uid(rdoc['uid']),
                                            domain.get_user(self.domain_id, rdoc['uid']),
                                            problem.get(rdoc['domain_id'], rdoc['pid']))
   # check permission for visibility: hidden problem
   if pdoc.get('hidden', False) and (pdoc['domain_id'] != self.domain_id
                                     or not self.has_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN)):
     pdoc = None
   self.send(html=self.render_html('record_main_tr.html', rdoc=rdoc, udoc=udoc, dudoc=dudoc, pdoc=pdoc))
Exemple #16
0
 async 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))
Exemple #17
0
 async 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_CONTEST, tid),
                                     problem.get(self.domain_id, pid, uid))
   tsdoc, udoc, dudoc = await asyncio.gather(
       contest.get_status(self.domain_id, document.TYPE_CONTEST, 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.ContestNotAttendedError(tdoc['doc_id'])
     if not self.is_ongoing(tdoc):
       raise error.ContestNotLiveError(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('contest_main'), self.reverse_url('contest_main')),
       (tdoc['title'], self.reverse_url('contest_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)
Exemple #18
0
 async def on_record_change(self, e):
     rdoc = await record.get(objectid.ObjectId(e['value']),
                             record.PROJECTION_PUBLIC)
     # check permission for visibility: contest
     if rdoc['tid']:
         now = datetime.datetime.utcnow()
         tdoc = await contest.get(rdoc['domain_id'], rdoc['tid'])
         if (not contest.RULES[tdoc['rule']].show_func(tdoc, now) and
             (self.domain_id != tdoc['domain_id'] or
              not self.has_perm(builtin.PERM_VIEW_CONTEST_HIDDEN_STATUS))):
             return
     # TODO(iceboy): join from event to improve performance?
     # TODO(iceboy): projection.
     udoc, pdoc = await asyncio.gather(
         user.get_by_uid(rdoc['uid']),
         problem.get(rdoc['domain_id'], rdoc['pid']))
     # check permission for visibility: hidden problem
     if pdoc.get('hidden', False) and (
             pdoc['domain_id'] != self.domain_id
             or not self.has_perm(builtin.PERM_VIEW_PROBLEM_HIDDEN)):
         pdoc = None
     self.send(html=self.render_html(
         'record_main_tr.html', rdoc=rdoc, udoc=udoc, pdoc=pdoc))
Exemple #19
0
 async def get(self, *, ctype: str, tid: objectid.ObjectId,
               pid: document.convert_doc_id):
     doc_type = constant.contest.CTYPE_TO_DOCTYPE[ctype]
     uid = self.user['_id'] if self.has_priv(
         builtin.PRIV_USER_PROFILE) else None
     tdoc, pdoc = await asyncio.gather(
         contest.get(self.domain_id, doc_type, tid),
         problem.get(self.domain_id, pid, uid))
     tsdoc, udoc = await asyncio.gather(
         contest.get_status(self.domain_id, doc_type, tdoc['doc_id'],
                            self.user['_id']),
         user.get_by_uid(tdoc['owner_uid']))
     attended = tsdoc and tsdoc.get('attend') == 1
     if not attended:
         if ctype == 'contest':
             raise error.ContestNotAttendedError(tdoc['doc_id'])
         elif ctype == 'homework':
             raise error.HomeworkNotAttendedError(tdoc['doc_id'])
         else:
             raise error.InvalidArgumentError('ctype')
     if not self.is_ongoing(tdoc):
         if ctype == 'contest':
             raise error.ContestNotLiveError(tdoc['doc_id'])
         elif ctype == 'homework':
             raise error.HomeworkNotLiveError(tdoc['doc_id'])
         else:
             raise error.InvalidArgumentError('ctype')
     if pid not in tdoc['pids']:
         raise error.ProblemNotFoundError(self.domain_id, pid,
                                          tdoc['doc_id'])
     if self.can_show_record(tdoc):
         rdocs = await record.get_user_in_problem_multi(uid, self.domain_id, pdoc['doc_id'], get_hidden=True) \
           .sort([('_id', -1)]) \
           .limit(10) \
           .to_list()
     else:
         rdocs = []
     if not self.prefer_json:
         path_components = self.build_path(
             (self.translate('page.contest_main.{0}.title'.format(ctype)),
              self.reverse_url('contest_main', ctype=ctype)),
             (tdoc['title'],
              self.reverse_url('contest_detail', ctype=ctype, tid=tid)),
             (pdoc['title'],
              self.reverse_url(
                  'contest_detail_problem', ctype=ctype, tid=tid, pid=pid)),
             (self.translate('page.contest_detail_problem_submit.{0}.title'.
                             format(ctype)), None))
         languages = filter_language(pdoc.get('languages') or [])
         default_lang = len(languages) and list(languages.keys())[0] or ''
         self.render('problem_submit.html',
                     tdoc=tdoc,
                     pdoc=pdoc,
                     rdocs=rdocs,
                     tsdoc=tsdoc,
                     udoc=udoc,
                     attended=attended,
                     page_title=pdoc['title'],
                     path_components=path_components,
                     languages=languages,
                     default_lang=default_lang)
     else:
         self.json({'rdocs': rdocs})