Ejemplo n.º 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, 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)
Ejemplo n.º 2
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))
Ejemplo n.º 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, 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})
Ejemplo n.º 4
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))
Ejemplo n.º 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_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})
Ejemplo n.º 6
0
Archivo: contest.py Proyecto: vijos/vj4
 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})
Ejemplo n.º 7
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))
Ejemplo n.º 8
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)
Ejemplo n.º 9
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))
Ejemplo n.º 10
0
Archivo: contest.py Proyecto: vijos/vj4
 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)
Ejemplo n.º 11
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})