Example #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 = 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})
Example #2
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)
Example #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})
Example #4
0
File: contest.py Project: 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})
Example #5
0
 async def get(self, *, tid: objectid.ObjectId, page: int = 1):
     # contest
     tdoc = await contest.get(self.domain_id, tid)
     tsdoc, pdict = await asyncio.gather(
         contest.get_status(self.domain_id, 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 #6
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)
Example #7
0
File: contest.py Project: 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)
Example #8
0
File: contest.py Project: vijos/vj4
 async 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 #9
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})